.NET 2.0 VS .NET 4.0加载错误

编程入门 行业动态 更新时间:2024-10-26 17:21:27
本文介绍了.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加载错误

本文发布于:2023-11-12 00:56:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580042.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   错误   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!