Vil*_*nde 9 c# visual-studio-2010
我已经将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);
Run Code Online (Sandbox Code Playgroud)
组件的实际加载工作,当我尝试在程序集内创建异常发生的类的实例时:
Type t = a.GetType("nameofclass");
Activator.CreateInstance(t); //fails here
Run Code Online (Sandbox Code Playgroud)
这是堆栈跟踪:
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)
...
Run Code Online (Sandbox Code Playgroud)
内部异常堆栈跟踪:
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()
Run Code Online (Sandbox Code Playgroud)
我现在意识到不起作用的dll在InitializeComponent中有这个共同点:
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RegForm));
Run Code Online (Sandbox Code Playgroud)
但是正如我提到的那样,框架3.5没有问题.
-
找到解决方案
我发现问题与dotnet框架如何尝试查找本地化资源有关,在我将以下行添加到程序集中的AssemblyInfo.cs后,它又开始工作了.
[assembly: NeutralResourcesLanguageAttribute("sv-SE", UltimateResourceFallbackLocation.MainAssembly)]
Run Code Online (Sandbox Code Playgroud)
找到解决方案
我发现问题与dotnet框架如何尝试查找本地化资源有关,在我将以下行添加到程序集中的AssemblyInfo.cs后,它又开始工作了.
[assembly: NeutralResourcesLanguageAttribute("sv-SE", UltimateResourceFallbackLocation.MainAssembly)]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5878 次 |
| 最近记录: |