.NET 2.0 VS .NET 4.0加载错误 [英] .NET 2.0 vs .NET 4.0 loading error

查看:105
本文介绍了.NET 2.0 VS .NET 4.0加载错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的类库编译的.NET 2.0,每当我尝试加载它在2.0运行时插件工作得很好。但是,如果主应用程序运行在.NET 4.0中运行时,我只要资源需要访问得到一个异常:

My class library is compiled against .NET 2.0 and works just fine whenever I try to load it as a plugin under the 2.0 runtime. If however the master application is running the .NET 4.0 runtime, I get an exception as soon as the resources need to be accessed:

Exception occurred during processing of command: Grasshopper
Plug-in = Grasshopper
Could not find file 'Grasshopper.resources'.

CALL STACK
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, Dictionary2 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.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream)
at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture)
at Grasshopper.My.Resources.Resources.get_GrasshopperBannerImage_Palette() in D:\dev\grasshopper\1.0\root\src\My Project\Resources.Designer.vb:line 1159
at Grasshopper.GUI.GH_Banner.ExplicitBanner_Load(Object sender, EventArgs e) in D:\dev\grasshopper\1.0\root\src\GH_Banner.vb:line 14
....

这是怎么回事?我如何使所有的.NET运行时我的项目负荷?

What's going on and how do I make my project load on all .NET Runtimes?

编辑: 这个问题是一个AssemblyResolver我写道,有迷茫的时候询问是否载入Grasshopper.resources。看来,.NET 4.0处理资源加载不同的方式从早期的运行时间???

The problem was an AssemblyResolver I wrote that got confused when asked to load "Grasshopper.resources". It seems that .NET 4.0 handles resource loading differently from earlier runtimes???

推荐答案

添加一个测试资源的程序集的AssemblyResolver解决了问题,让我跑在两个.NET 2.0和4.0这个类库:

Adding a test for resource assemblies to an AssemblyResolver fixes the issue and allows me to run this class library under both .NET 2.0 and 4.0:

private Assembly ResolveGrasshopper(object sender, ResolveEventArgs e)
{
  if (e.Name.Contains(".resources,")) { return null; }
  ....
}

这篇关于.NET 2.0 VS .NET 4.0加载错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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