开发者

Assembly ordering in .net c#

A similar question has been asked in Ordering of reflection requests in dotnet But I'm hoping for a different answer... I'm writing a plugin for a program that uses reflection to interrogate plugins to find the entry point. Unfortunately it has a bug which means if it encounters an interface declaration during this process it crashes with an unhandled exception. I have spoken to the development team and this is unlikely to be fixed. This is extremely limiting for me for obvious reasons. One workaround I have already thought of is to have my 开发者_如何学Cassembly load another assembly with the interfaces in it, but for reasons I won't go into this is not a great solution. It was a while before I encountered this problem because for some reason my entry class always preceded my interfaces in the reflection enumeration order.

My question is, is there any way to influence the ordering of classes and interfaces in the assembly?

Note: I have already tried setting different accessibility levels on my interfaces but that doesn't work for me. Cheers, J


I'd bet the code using AppDomain.GetAssemblies() which are then inspected. The implementation of AppDomain.GetAssemblies() leads to an external method, so Reflector is of mostly no help here.

However, without actually trying it and inspecting the result, there are two logical options for the ordering of assemblies in the result:

  1. Load order
  2. Alphabetical order

In the first case you'd probably have to organize references among your assemblies and the load order in such a way that the foreign code finds the right assembly with the entrypoint class and stops. In the second case it would be a pure matter of naming the assemblies in a 'right' way but I doubt it's this case.

(However, the order may be completely different from the two above, e.g. 'mostly' random as well.)

In either case I think sooner or later the buggy code will encounter the problematic assembly and crash anyway. Thus the strong recommendation is: insist on having the bug fixed.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜