0

I have a WPF .Net 4.0 application that has been running just fine under WinPE 4.0, until recently. I added the code shown below, and it broke the app when running it under WinPE 4.0. Note, the app still runs fine under Windows 7 x64 and Windows 2012.

[ValueConversion(typeof(string), typeof(bool))]
public class HeaderToImageConverter : IValueConverter
{
    public static HeaderToImageConverter Instance =
        new HeaderToImageConverter();

    public object Convert(object value, Type targetType,
        object parameter, CultureInfo culture)
    {
        if ((value as string).Contains("corp.com"))
        {
            Uri uri = new Uri
            ("pack://application:,,,/Images/DeployWiz_Network.png");
            BitmapImage source = new BitmapImage();
            source.BeginInit();
            source.UriSource = uri;
            source.DecodePixelHeight = 40;
            source.EndInit();
            return source;
        }
        else
        {
            Uri uri = new Uri
            ("pack://application:,,,/Images/ou2.png");
            BitmapImage source = new BitmapImage();
            source.BeginInit();
            source.UriSource = uri;
            source.DecodePixelHeight = 20;
            source.EndInit();
            return source;
        }
    }

    public object ConvertBack(object value, Type targetType,
        object parameter, CultureInfo culture)
    {
        throw new NotSupportedException("Cannot convert back");
    }
}

This code allows me to use a different image in my Treeview control based on the contents of the treeview item.

When running this under WinPE, I get the following exception:

enter image description here

So, I put the missing .DLL in the same folder as my .exe, and then I get this exception:

enter image description here

Is there something funky about the .dll that doesn't cause it to work in WinPE? Is there any other class I can use besides BitmapImage in WPF to accomplish my goals and avoid this .dll? Is BitmapImage even the class that needs this .dll? I assume it is because it's the only new code I've added that breaks my app.

Dbloom
  • 1,302
  • 3
  • 18
  • 45

2 Answers2

2

Are you making a 32bit or 64bit WinPE environment?

By the looks of it your WPF application is using "Any CPU" as the platform, and so when the app runs it will expect a 32bit version of mscms.dll to be available when run on a 32bit platform and a 64bit mscms.dll when run on a 64bit platform.

You need to make sure you copy the mscms.dll across that matches the "bitness" WinPE environment you decided to use.

WinPE x64 doesn't support WOW64 (Windows 32-bit on Windows 64-bit)... so compiling your application as "x86" (i.e. 32bit) and supplying a 32bit mscms.dll isn't an option.

Thus, make sure you copy the right 32bit or 64bit mscms.dll...depending on your PE bitness.

You "might" be able to add WOW64 (Windows 32-bit on Windows 64-bit) to WinPE x64 by creating your own custom PE build/image by following some of the suggestions here:

Community
  • 1
  • 1
Colin Smith
  • 12,375
  • 4
  • 39
  • 47
  • I copied mscms.dll from my own c:\windows\system32 folder into the same folder as my .exe, and it did not work. So then I copied mscms.dll from my own c:\windows\syswow64 folder into the same folder as my .exe, and it still did not work. What else can I try? I am using 64-bit WinPE. – Dbloom Jun 21 '13 at 00:46
  • 1
    You need to check which directories are being probed when it tries to load mscms.dll, it may not necessarily be looking in your applications directory first. You can use Fusion Log Viewer to see any failure, and why: http://msdn.microsoft.com/en-us/library/e74a18c4(v=VS.100).aspx ... http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57120.aspx – Colin Smith Jun 21 '13 at 00:54
0

Well, after more detective work the problem is that the BitmapImage class in C# eventually boils down to a 32-bit native .DLL, which will NOT work in 64-bit WinPE.

I confirmed this by running my app in 32-bit WinPE just fine. So, does anyone know of any other way to render images in WPF other than the BitmapImage class?

:-)

Dbloom
  • 1,302
  • 3
  • 18
  • 45