cheesetarmac

Hi

I'm at a loss regarding the issue that I'll explain below and am hoping that someone can point to a sensible reason / resolution

A customer is attempting to run my application on a PC running Vista 32 Business IBM/Lenovo version (note that Lenovo version may turn out to be a key clue). When the application tries to load an png image, I end up getting the following exception.

[Exception=System.UriFormatException: Invalid URI: The hostname could not be parsed.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString)
at System.Windows.Media.ColorContext..ctor(PixelFormat pixelFormat)
at System.Windows.Media.Imaging.BitmapImage.FinalizeCreation()
at System.Windows.Media.Imaging.BitmapImage.EndInit()
at System.Windows.Media.Imaging.BitmapImage..ctor(Uri uriSource)
at DebugPackSyntax.Window1.ClickMe_Click(Object sender, routedEventArgs e)

I've created a test application and had them run that to make sure there wasn't any other interaction effect. The code that throws this exception is as follows. Note that the DiMlogo.png has a build action of Resource and a Copy to Output Directory of Do Not Copy.

Code Block

try

{

image1.Source = new BitmapImage(new Uri("pack://application:,,,/Images/DiMlogo.png"));

MessageBox.Show("Pack syntax success");

}

catch (Exception ex)

{

string error = string.Format("Pack syntax {0} - {1}\n{2}", ex.GetType(), ex.Message, ex.StackTrace);

Clipboard.SetText(error);

MessageBox.Show(error);

}

What really has me stumped is that this works on our Vista Business and Vista Ultimate PC's as well as our XP pc's.

Can anyone throw any light on this please.

regards


Steve




Re: Windows Presentation Foundation (WPF) Help with System.UriFormatException and loading an image with pack syntax

Andre N. - MSFT

On the machine that's failing, open a CMD prompt and type:

set windir

If the result is:

windir=%systemroot%

That's the problem. It should be something like:

windir=c:\windows

(depending on which drive windows is actually installed on, of course).

If this is the problem, just set windir=c:\windows and hopefully the problem will be fixed.

Andre





Re: Windows Presentation Foundation (WPF) Help with System.UriFormatException and loading an image with pack syntax

cheesetarmac

Hi Andre

Thanks for the tip and I'll check it out.

Out of interest, why does winDir have an impact on the pack syntax for application

Secondly, if the windir is different from C:\Windows on the problematic PC presumably it's been set to something different for a reason If I'm unable to change it because it breaks something else, what other options are available

regards

Steve




Re: Windows Presentation Foundation (WPF) Help with System.UriFormatException and loading an image with pack syntax

cheesetarmac

Hi

The reported path from the customer is C:\windows so it looks like that isn't the problem.

regards

Steve




Re: Windows Presentation Foundation (WPF) Help with System.UriFormatException and loading an image with pack syntax

Andre N. - MSFT

This sounded similar to another issue that involved the windir variable but apparently it isn't. Hopefully someone else will have an idea here





Re: Windows Presentation Foundation (WPF) Help with System.UriFormatException and loading an image with pack syntax

Jordan Parker - MSFT

What's happening is that particular PNG file has a color profile embedded in it and it's not the same as the system's color profile so we try to do a conversion. There was a bug with this in Vista that we fixed in .NET 3.5 (Orcas) and it sounds like you're hitting it Smile

That particular PNG fails on only one machine, right My guess is that machine's color profile is different than the others. Go to Color Management's Advanced tab in the Control Panel and make sure the Device Profile is set to the system default. If it is and things are still crashing, I think your only options are to either strip the color profile from the PNG file or upgrade to 3.5 when it comes out shortly.