开发者

How to get name of type contained within missing assembly

I have loaded assembly A in ReflectionOnly context in order to get information on types and their methods. At least one of methods has return type that is part of dependency assembly B.

The problem is that assembly B is not available and cannot be resolved so following FileNotFoundException is thrown:

Could not load file or assembly 'B' or one of its dependencies. The system cannot find the file specified.

That exception is kind of expected. 开发者_如何学PythonHowever, I have seen that Reflector CAN load type name (which is what I need) even when it cannot resolve dependency assembly.

Does someone know how to get name of type contained within missing assembly without getting FileNotFoundException?

EDIT:

Exception is thrown when trying to access ReturnType property:

Type returnType = methodInfo.ReturnType;


You can try to use a different library to load this assembly, like Mono.Cecil.


Ok... there is a "weird" possible solution, I say, it's "weird".

Each time you try to load a class that cannot be found in an AppDomain, AppDomain.TypeResolve event is raised.

See the MSDN page

Now... we leave multithreading and multiple app domain issues apart for now, for the sake of keeping things simple, but if you add an handler to AppDomain.Current.TypeResolve you can find the name of the missing class.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜