探测privatePath和资源字典

时间:2017-07-01 07:33:02

标签: wpf xaml resourcedictionary

我有两个症状明显不同的问题,我认为这可能是同样的问题。这两个问题都发生在一台机器上,但不发生在其他机器上。

在一种情况下,.NET库在旧的C ++ / MFC应用程序中加载。该库打开一个WPF窗口,该窗口生成以下错误:

Set property 'System.Windows.ResourceDictionary.Source' threw an exception.
Cannot locate resource 'resourcedictionaries/images/bitmaps_32_32.xaml'.

启动WPF应用程序时出现第二个错误。程序在加载时崩溃,并将以下错误写入Windows事件日志:

Anwendung: Cs3SystemManager.exe
Frameworkversion: v4.0.30319
Beschreibung: Der Prozess wurde aufgrund einer unbehandelten Ausnahme beendet.
Ausnahmeinformationen: System.IO.IOException
   bei MS.Internal.AppModel.ResourcePart.GetStreamCore(System.IO.FileMode, System.IO.FileAccess)
   bei System.IO.Packaging.PackagePart.GetStream(System.IO.FileMode, System.IO.FileAccess)
   bei System.IO.Packaging.PackWebResponse+CachedResponse.GetResponseStream()
   bei System.IO.Packaging.PackWebResponse.GetResponseStream()
   bei System.IO.Packaging.PackWebResponse.get_ContentType()
   bei MS.Internal.WpfWebRequestHelper.GetContentType(System.Net.WebResponse)
   bei MS.Internal.WpfWebRequestHelper.GetResponseStream(System.Net.WebRequest, MS.Internal.ContentType ByRef)
   bei System.Windows.ResourceDictionary.set_Source(System.Uri)
   bei System.Windows.Baml2006.WpfSharedBamlSchemaContext+<>c.<Create_BamlProperty_ResourceDictionary_Source>b__342_0(System.Object, System.Object)
   bei System.Windows.Baml2006.WpfKnownMemberInvoker.SetValue(System.Object, System.Object)
   bei MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(System.Xaml.XamlMember, System.Object, System.Object)
   bei MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(System.Object, System.Xaml.XamlMember, System.Object)

Ausnahmeinformationen: System.Windows.Markup.XamlParseException
   bei System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
   bei System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
   bei System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
   bei System.Windows.Application.LoadComponent(System.Object, System.Uri)
   bei Cs3SystemManager.App.InitializeComponent()
   bei Cs3SystemManager.App.Main()

此应用程序引用第一条错误消息中引用的相同资源字典。我强烈怀疑它是同样的基本错误。

使用以下语法引用资源字典:

<ResourceDictionary Source="/McWpfResources;component/ResourceDictionaries/Images/Bitmaps_32_32.xaml" />

我也尝试了以下语法,但它没有任何区别。

<ResourceDictionary Source="pack://application:,,,/McWpfResources;component/ResourceDictionaries/Images/Bitmaps_32_32.xaml" />

我们的安装将可执行文件(.exe)存储到名为 bin 的目录中,并将DLL存储到名为 bin \ interop 的子目录中(其中一些是interop包装器) COM组件)。

对于每个.exe文件,都有一个匹配的.exe.Config文件,用于表示privatePath,例如:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="interop"/>
    </assemblyBinding>
  </runtime>
</configuration>

如果我将exe文件复制到interop目录中,则不会出现任何问题。

显然,privatePath参数在这种特定情况下不起作用(至少不能按照我的预期工作),但它确实可以在其他机器和其他应用程序中运行。

显然,我可以通过将所有内容放在一个目录中来修复错误,但除此之外,我该如何修复错误?

1 个答案:

答案 0 :(得分:0)

算了。这是我的错误。

从以前的安装中,bin目录包含旧版本的DLL,现在已安装到interop子目录中。这个旧的DLL正在加载,而不是子目录中的DLL。

我可能会删除这个问题(或者我可能会将其留作警示故事)。