开发者

Why do I get different results in .NET4 compared to .NET 3.5

When I have my project's target framework set to Framework 4.0 and run the following code:

 Assembly pAsm = Assembly.LoadFrom(aMagPath);
 foreach (Module m in pAsm.GetModules())
 {
    Type t = m.GetType("typeName"));
 }

typeName is a user defined ty开发者_Go百科pe from a 3rd party dll.

t is null.

If I change the target type to Framework 3.5 t is not null.

I don't change anything else. I just change the target framework and rerun the application.

Can anyone explain why this it happening? is there some tool that will let me look into this more?

UPDATE: I changed my code to the following.

Assembly pAsm = Assembly.LoadFrom(aMagPath);
Type t = pAsm.GetType(String.Format("GM.FCAT.{0}.{0}+FBlock+{1}Function+{2}CaseStream+{2}RepeatableParameterStream", FBlockName, pName, aParam.Name), false);

I still have the same problem. t = null in version 4.0 and doesn't in version 3.5

I can't find the type when I load it into .net reflector. so I guess it is not really there.


Some framework types have moved across assemblies between versions, with an assembly binding redirection to make it usually invisible to clients. That may explain what's going on, but it's hard to say without knowing which assembly and type you're trying to find.

EDIT: Okay, now that we've got a bit more context...

That suggests the type really isn't in that module... It's possible that there was a bug in .NET 3.5 which looked in the parent assembly for the type name instead of just within the module.

Is there any reason why you have to look on a module-by-module basis, instead of just asking the assembly itself for the type?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜