项目中的程序集资源FileNotFoundException已升级到VS 2010 framework 4.0
我已经将C#WinForms应用程序从Visual C#2008(框架3.5)升级到2010(框架4.0),并且我遇到了运行时错误。
应用程序使用Assembly.Load(filename)在运行时动态加载程序集。 它是这样设计的,因为根据用户配置,它应该加载位于不同文件夹中的程序集的不同实现。
一切正常,除非加载的dll有嵌入资源(位图或xsd数据集),然后我得到FileNotFoundException:
{“无法找到文件’FF.Fi_Stat.SKA.resources’。”:null}
该程序集称为FF.Fi_Stat.SKA.dll。 我不理解这条消息,因为没有外部资源(只有嵌入式资源),并且VS在输出目录中没有生成具有该名称的文件。 有任何想法吗?
–
更多细节:
这是我加载程序集的方式:
Assembly a = Assembly.LoadFile(assemblyFileName);
组件的实际加载工作,当我尝试在程序集内创建exception发生的类的实例时:
Type t = a.GetType("nameofclass"); Activator.CreateInstance(t); //fails here
这是堆栈跟踪:
Exception has been thrown by the target of an invocation. at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) ...
内部exception堆栈跟踪:
at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark) at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark) at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark) at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark) at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) at System.Resources.ResourceManager.GetString(String name, CultureInfo culture) at System.Resources.ResourceManager.GetString(String name) at FF.Fi_Stat.SKA.RegForm.InitializeComponent() at FF.Fi_Stat.SKA.RegForm..ctor()
我现在意识到不起作用的dll在InitializeComponent中有这个共同点:
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RegForm));
但是正如我提到的那样,框架3.5没有问题。
–
找到解决方案
我发现问题与dotnet框架如何尝试查找本地化资源有关,在我将以下行添加到程序集中的AssemblyInfo.cs后,它又开始工作了。
[assembly: NeutralResourcesLanguageAttribute("sv-SE", UltimateResourceFallbackLocation.MainAssembly)]
找到解决方案
我发现问题与dotnet框架如何尝试查找本地化资源有关,在我将以下行添加到程序集中的AssemblyInfo.cs后,它又开始工作了。
[assembly: NeutralResourcesLanguageAttribute("sv-SE", UltimateResourceFallbackLocation.MainAssembly)]
您可以尝试在Fusion加载程序中启用日志记录 。 我在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion
中将DWORD
值EnableLog
创建为1非常成功。 然后,您将在事件日志中获得详细的加载错误消息。
- 是否可以将数组绑定到DataGridView控件?
- 编译器说我没有实现我的界面,但我是?
- 内存消耗.Net应用程序(Azure网站)
- 通过reflectionC#获取嵌套属性值
- MVC 5 Code First脚手架,关系简单
- aspnet核心entity framework7自引用“作业”1到多表
- 使用Unity3D的IPointerDownHandler方法,但使用“整个屏幕”
- 如何在处理使用Facebook API调用的服务方法时透明地更新Facebook访问令牌?
- TransactionScope中的Membership.GetUser()抛出TransactionPromotionException