【发布时间】:2016-11-11 19:51:06
【问题描述】:
从 C# 3.5 迁移到 4 后,我们开始遇到 InitializeComponent 上找不到 .resources 文件的异常:
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in PresentationCore.dll
Additional information: Could not load file or assembly 'MYASSEMBLY.resources, Version=1.0.0.0, Culture=en-US, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
这是一个 WPF 程序集,按需加载,并且没有本地化 - .resources 不存在也不应该存在。该问题在迁移之前并未发生,仅在应用程序中执行一组特定操作时才会发生。在另一个操作中,程序集已正确加载,Fusion Logs 显示尝试加载 .resources 失败,但未引发异常。
另外,一篇关于调试程序集加载的旧博客文章特别提到:
注意:除非您明确调试资源加载失败,否则您可能希望忽略查找具有“.resources”扩展名且文化设置为“中性”以外的程序集的失败。当 ResourceManager 探测附属程序集时,这些是预期的失败。 https://blogs.msdn.microsoft.com/suzcook/2003/05/29/debugging-assembly-loading-failures/
我已尝试在 AssemblyInfo.cs 中应用 NeutralResourcesLanguage 属性,但这只会使异常引用另一个第三方程序集。
这个问题的原因可能是什么?
【问题讨论】:
标签: c# .net wpf .net-assembly