Windows 8: WinRT Error – The given System.Uri cannot be converted into a Windows.Foundation.Uri

I was trying to directly set the source of an image to the path within the assembly. Previously you built up the Uri to include the assembly name and the path to the asset. Just like below but this now throws an error.

            // ;Component/ must all ways be present in the Uri below
            Uri uri = new Uri("VJComponent;Component/Assets/joystick.png", UriKind.Relative);
            BitmapImage bi = new BitmapImage();
            bi.UriSource = uri;

The given System.Uri cannot be converted into a Windows.Foundation.Uri

Replace the assembly name and ‘;Component/’ with ‘ms-appx:/’ and build the Uri as before.

            Uri uri = new Uri("ms-appx:/Assets/joystick.png");
            BitmapImage bi = new BitmapImage();
            bi.UriSource = uri;

To do the same but directly in the XAML instead of doing it programmatically you previously did this


Again replace the assembly name and ‘;Component/’ with ‘ms-appx:/’ and build the Uri as before.


Windows 8 Developer Camp Slides

Here are the slides from the Windows 8 Developer Camp I recently attended

[gview file=”http://allanmuller.co.uk/wp-content/uploads/2012/05/Agenda.pdf” authonly=”1″]

[gview file=”http://allanmuller.co.uk/wp-content/uploads/2012/05/Overview_MikeT.pdf” authonly=”1″]

[gview file=”http://allanmuller.co.uk/wp-content/uploads/2012/05/Views_MikeT.pdf” authonly=”1″]

[gview file=”http://allanmuller.co.uk/wp-content/uploads/2012/05/ControlsBinding_MikeT.pdf” authonly=”1″]

[gview file=”http://allanmuller.co.uk/wp-content/uploads/2012/05/Media_MikeT.pdf” authonly=”1″]

[gview file=”http://allanmuller.co.uk/wp-content/uploads/2012/05/PLM_MikeT.pdf” authonly=”1″]

 

Create WinRT Component DLL in C#

There are loads of tutorials on how to create a WinRT Component DLL in C++ but there aren’t many on how to do this with C#. In fact it is pretty simple:

Step 1: Add a C# Class library project to your solution

Step 2: Right click on the new project you have just added and go to properties.

Step 3: Change the output type from ‘Class Library’ to ‘WinMD File’.

Change from Class Library

Change to WinMD File

Step 4: Ensure your class inside the newly created Class Library is sealed. The Windows Runtime classes you create must be sealed.

Make sure you set your class to sealed