Search code examples
windows-8windows-runtime

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


I'm trying to programmatically load a BitmapImage in a XAML Metro app. Here's my code:

var uri = new Uri("/Images/800x600/BackgroundTile.bmp", UriKind.RelativeOrAbsolute);
var imageSource = new BitmapImage(uri);

The second line crashes with a System.ArgumentException:

The given System.Uri cannot be converted into a Windows.Foundation.Uri. Please see http://go.microsoft.com/fwlink/?LinkID=215849 for details.

The link just goes to the MSDN home page, so it's no use.

I've also tried removing the leading /, in case WinRT has different expectations about relative URIs, but I still get the same exception.

Why am I getting this exception for what seems to be a perfectly valid URI?


Solution

  • In the Consumer Preview, the correct URL format has apparently changed to ms-appx:/Images/800x600/BackgroundTile.bmp