为什么我在WinPE 4.0中获得此异常但不在Windows 7 / Windows 2012中获得此异常?

时间:2013-06-20 23:20:43

标签: c# wpf winpe

我有一个WPF .Net 4.0应用程序,直到最近才在WinPE 4.0下运行得很好。我添加了下面显示的代码,它在WinPE 4.0下运行时破坏了应用程序。请注意,该应用程序在Windows 7 x64和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");
    }
}

此代码允许我根据树视图项的内容在Treeview控件中使用不同的图像。

在WinPE下运行时,我得到以下异常:

enter image description here

所以,我把丢失的.DLL放在与我的.exe相同的文件夹中,然后我得到了这个例外:

enter image description here

.dll是否存在一些无法使其在WinPE中工作的内容? 除了WPF中的BitmapImage之外,还有其他类可以用来实现我的目标并避免使用.dll吗? BitmapImage甚至是需要这个.dll的类吗?我认为这是因为它是我添加的唯一一个破坏我的应用程序的新代码。

2 个答案:

答案 0 :(得分:2)

您是在制作32位或64位WinPE环境吗?

从外观来看,你的WPF应用程序正在使用“任何CPU”作为平台,因此当应用程序运行时,它将在32位平台和64位mscms上运行时可以使用32位版本的mscms.dll .dll在64位平台上运行时。

您需要确保将mscms.dll复制到与您决定使用的“bitness”WinPE环境匹配的位置。

WinPE x64不支持WOW64(Windows 64位Windows 32位)...因此将应用程序编译为“x86”(即32位)并提供32位mscms.dll不是一种选择。 / p>

因此,请确保复制正确的32位或64位mscms.dll ...取决于您的PE位数。

您可以通过以下一些建议创建自己的自定义PE构建/映像,从而“可能”能够将WOW64(Windows 64位上的Windows 32位)添加到WinPE x64中:

答案 1 :(得分:0)

好吧,经过更多的侦探工作后,问题是C#中的BitmapImage类最终归结为32位原生.DLL,这在64位WinPE中不起作用。

我通过在32位WinPE中运行我的应用程序确认了这一点。那么,有没有人知道在除BitmapImage类之外的WPF中渲染图像的任何其他方法?

: - )