I am working on a Windows Store app, of which more soon. I am writing the app in XAML and C#. I was tweaking the page design when I hit a problem. Everything was fine in the designer in Visual Studio, but running the app raised an exception:
WinRT information: Failed to create a ‘Windows.Foundation.Int32’ from the text ‘ 2’.
along with the ever-helpful:
Additional information: The text associated with this error code could not be found.
The annoying this about this error is that debugging is not that easy. The exception is in Framework code, not your own code, and Microsoft does not supply the source. Once again, everything is fine in the designer and there are no compiler errors.
Puzzling. I resorted to undoing bits of my changes until I found what triggered the problem.
This was it. In the XAML, I had somehow typed a leading space before a number:
The designer parses this OK (it would be better if it did not) but the runtime does not like it.
Actually, I know why this happens. If you are typing in the XAML code editor (which I find myself doing a lot), then auto completion inserts the blank space for you:
I wish all bugs were this easy to solve, though I regard it as a bug in the Visual Studio editor. Posted here mainly in case others hit this problem; but I also observe that Windows Store development still seems less solid in Visual Studio than the tools for desktop or web apps.
Other problems I have hit include the visual designer changing to read-only of its own accord; and a highly irritating issue where the editor for a XAML code-behind class sometimes forgets the existence of all the controls you have declared in XAML, covering your valid code with red squiggly lines and reporting numerous errors, which disappear as soon as you compile. Once this starts happening, the problem persists for the rest of the editing session.
It is not all bad. I am pleased with the way I have been able to put together a touch-friendly game UI relatively easily. Now comes the fun part: writing the logic for the AI (Artificial Intelligence).
- XAML and C#, or HTML and WinJS for Windows Store, Universal and cross platform apps?
- Microsoft Build Sessions published: Windows Phone XAML and HTML/JS apps, new Azure APIs and more
- Mac App Store, Windows Store, and the decline of the open platform
- Notes on styling a Windows Store app ListView to vary item appearance according to the data
- 10 things you might not have known about XAML