【问题标题】:probing privatePath and resource dictionary探测 privatePath 和资源字典
【发布时间】:2017-07-01 07:33:02
【问题描述】:

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

在一种情况下,.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 的子目录中(其中一些是互操作包装器) 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 文件复制到互操作目录中,则不会出现任何问题。

显然,privatePath 参数在这种特定情况下不起作用(至少不像我预期的那样起作用),但它似乎在其他机器和其他应用程序中起作用。

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

【问题讨论】:

    标签: wpf xaml resourcedictionary


    【解决方案1】:

    算了。这是我的错误。

    在以前的安装中,bin 目录包含旧版本的 DLL,现在安装到 interop 子目录中。这个旧的 DLL 优先于子目录中的 DLL 被加载。

    我可能会删除这个问题(或者我可能会把它作为一个警示故事)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-07
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多