简体   繁体   中英

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. Don't wont to load them since I know that is impossible with Assembly.Load or LoadFrom. Only thing I need is Type. Is this possible and how to do it? For example this is dll ADONETSrc that I am trying get Type is:

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.

Chicked-and-egg question. Anything you could possibly do with the type requires the program to run with the v4 version of the CLR. Simple to do with a .config file, <supportedRuntime> element. 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. The v2 CLR simply doesn't know how read it and will refuse to do so, throwing a BadImageFormatException. Type info is stored in the assembly metadata so you can never get to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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