大会资源FileNotFoundException异常项目升级到VS 2010的框架4.0 [英] Assembly resources FileNotFoundException in project upgraded to VS 2010 framework 4.0

查看:146
本文介绍了大会资源FileNotFoundException异常项目升级到VS 2010的框架4.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经升级从Visual C#2008(框架3.5)一个C#WinForms应用程序到2010(4.0框架)和我得到运行时错误。



应用程序加载在运行时动态组件使用的Assembly.Load(文件名)。它的目的是通过这种方式,因为这取决于用户的配置应该加载位于不同的文件夹中的组件的不同实现。



一切工作正常,除了当加载的DLL已得到嵌入的资源(位图或XSD的数据集),然后我得到FileNotFoundException异常:



{找不到文件FF.Fi_Stat.SKA.resources'。:空}



的组件被称为FF.Fi_Stat.SKA.dll。因为没有外部资源(仅适用于嵌入式的),并与该名称的文件是由VS输出目录中生成我不明白这条消息。 ?任何想法



-



更多细节:



这是我如何加载程序集:

 大会提出= Assembly.LoadFile(assemblyFileName); 



该组件的实际负荷工作,它是当我尝试中创建一个类的实例该异常发生总成:

 类型T = a.GetType(nameofclass); 
Activator.CreateInstance(T); //这里失败

下面是堆栈跟踪:

 异常已被调用的目标引发异常。 
在System.RuntimeTypeHandle.CreateInstance(RuntimeType型,布尔publicOnly,布尔NOCHECK,布尔和放大器; canBeCached,RuntimeMethodHandleInternal&安培;构造函数,布尔和放大器; bNeedSecurityCheck)
在System.RuntimeType.CreateInstanceSlow(布尔publicOnly,布尔skipCheckThis,布尔fillCache)
在System.RuntimeType.CreateInstanceDefaultCtor(布尔publicOnly,布尔skipVisibilityChecks,布尔skipCheckThis,布尔fillCache)
在System.Activator.CreateInstance(类型类型,布尔非公开)
在System.Activator .CreateInstance(类型类型)
...

的内部异常堆栈跟踪:

 在System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(字符串名称,CultureInfo的文化,版本版本,布尔throwOnFileNotFound,StackCrawlMark&安培; stackMark)
。在System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo的lookForCulture,StackCrawlMark&安培; stackMark)
在System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo的文化,Dictionary`2 localResourceSets,布尔tryParents,布尔createIfNotExists,StackCrawlMark&安培; stackMark)
在System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo的requestedCulture,布尔createIfNotExists,布尔tryParents,StackCrawlMark&安培; stackMark)
在System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo的文化,布尔createIfNotExists,布尔tryParents)
在System.Resources.ResourceManager.GetString(字符串名称,CultureInfo的文化)在System.Resources.ResourceManager.GetString(字符串名称)
在FF.Fi_Stat.SKA.RegForm.InitializeComponent()
。在FF.Fi_Stat.SKA.RegForm..ctor(

我现在认识到DLL的不工作在的InitializeComponent共同这一行:

  System.ComponentModel.ComponentResourceManager资源=新System.ComponentModel.ComponentResourceManager(typeof运算(RegForm)); 



但正如我所说,这是与框架3.5没有问题。



-



溶液中发现的



我发现这个问题是涉及到DOTNET框架如何试图找到本地化的资源后,我添加了下面一行在我的程序集的AssemblyInfo.cs它开始再次合作。

  [汇编:NeutralResourcesLanguageAttribute(SV-SE,UltimateResourceFallbackLocation.MainAssembly)] 


解决方案

溶液中发现的



我发现,这个问题是涉及到DOTNET框架如何试图找到本地化的资源后,我添加了以下行到我的程序集的AssemblyInfo.cs它开始再次合作。

  [汇编:NeutralResourcesLanguageAttribute(SV-SE,UltimateResourceFallbackLocation.MainAssembly)] 


I have upgraded a C# WinForms application from Visual C# 2008 (framework 3.5) to 2010 (framework 4.0) and I'm getting runtime errors.

The application loads assemblies dynamically at runtime using Assembly.Load(filename). It is designed this way because depending on the users configuration it should load different implementations of the assembly located in different folders.

Everything works fine, except when the loaded dll has got embedded resources (bitmaps or xsd-datasets) then I get FileNotFoundException:

{"Could not find file 'FF.Fi_Stat.SKA.resources'.":null}

The assembly is called FF.Fi_Stat.SKA.dll. I do not understand this message because there are no external resources (only embedded ones) and no file with that name is generated by VS in the output directory. Any ideas?

--

More details:

This is how I load the assembly:

Assembly a = Assembly.LoadFile(assemblyFileName);

The actual loading of the assembly works, it is when I try to create an instance of a class inside the assembly that the exception occurs:

Type t = a.GetType("nameofclass");
Activator.CreateInstance(t);  //fails here

Here is the stack trace:

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)
   ...

The inner exception stack trace:

   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()

I now realize that the dll's that don't work has this line in InitializeComponent in common:

System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RegForm));

However as I mentioned this was no problem with framework 3.5.

--

SOLUTION FOUND

I found out that the problem was related to how the dotnet framework tried to find localized resources and after I added the following line to AssemblyInfo.cs in my assemblies it started working again.

[assembly: NeutralResourcesLanguageAttribute("sv-SE", UltimateResourceFallbackLocation.MainAssembly)]

解决方案

SOLUTION FOUND

I found out that the problem was related to how the dotnet framework tried to find localized resources and after I added the following line to AssemblyInfo.cs in my assemblies it started working again.

[assembly: NeutralResourcesLanguageAttribute("sv-SE", UltimateResourceFallbackLocation.MainAssembly)]

这篇关于大会资源FileNotFoundException异常项目升级到VS 2010的框架4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆