简体   繁体   English

是否可以从.net 3.5项目获取程序集.net 4.0的类型?

[英]Is it possible to get type of an assembly .net 4.0 from .net 3.5 project?

I am trying to get a type of some Microsoft .net 4.0 dll from .net 3.5 project. 我正在尝试从.net 3.5项目中获取某种Microsoft .net 4.0 dll的类型。 Don't wont to load them since I know that is impossible with Assembly.Load or LoadFrom. 不要加载它们,因为我知道用Assembly.Load或LoadFrom是不可能的。 Only thing I need is Type. 我唯一需要的就是Type。 Is this possible and how to do it? 这可能吗,怎么办? For example this is dll ADONETSrc that I am trying get Type is: 例如,这是我尝试获取的dll ADONETSrc类型:

Microsoft.SqlServer.ADONETSrc, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91.

Thanks, 谢谢,

Unfortunately this isn't possible. 不幸的是,这是不可能的。 Loading a .net 4.0 type requires loading CLR engine v4.0, which can't be loaded by the .NET 2.0 CLR engine. 加载.net 4.0类型需要加载CLR引擎v4.0,.NET 2.0 CLR引擎无法加载。

Chicked-and-egg question. 鸡和蛋的问题。 Anything you could possibly do with the type requires the program to run with the v4 version of the CLR. 您可能要使用该类型执行的任何操作都要求该程序与CLR的v4版本一起运行。 Simple to do with a .config file, <supportedRuntime> element. 使用.config文件<supportedRuntime>元素很容易做到。 At which point loading the assembly isn't a problem anymore either. 在那个时候加载程序集也不再是问题。

As originally stated: no, the metadata format was changed in .NET 4.0. 如最初所述:不,.NET 4.0中的元数据格式已更改。 The v2 CLR simply doesn't know how read it and will refuse to do so, throwing a BadImageFormatException. v2 CLR根本不知道如何读取它,并且会拒绝这样做,并抛出BadImageFormatException。 Type info is stored in the assembly metadata so you can never get to it. 类型信息存储在程序集元数据中,因此您永远无法获取它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM