Order assembly in .net C #

A similar question was asked in Ordering reflection requests in dotnet. But I hope for a different answer ... I am writing a plug-in for a program that uses reflection to poll plug-ins to find an entry point. Unfortunately, it has an error, which means that if it encounters an interface declaration during this process, it crashes with an unhandled exception. I spoke with the development team, and this is unlikely to be fixed. This is limiting me for obvious reasons. One of the workarounds I mentioned earlier is for my assembly to load another assembly with interfaces in it, but for reasons that I will not go into it, this is not a great solution. It was some time before I ran into this problem, because for some reason my input class always preceded my interfaces in the order in which the reflections were enumerated.

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

Note. I have already tried setting different access levels on my interfaces, but this does not work for me. Hooray, J

+4
source share
1 answer

I would put the code using AppDomain.GetAssemblies() , which are then checked. The implementation of AppDomain.GetAssemblies() leads to an external method, so Reflector basically doesn't help here.

However, without trying and not checking the result, there are two logical options for ordering the assembly as a result:

  • Boot order
  • alphabet order

In the first case, you may have to arrange the links between your assemblies and the boot order so that the external code finds the desired assembly with the entry point class and stops. In the second case, it would be pure business to call assemblies β€œright”, but I doubt it.

(However, the order may be completely different from the two above, for example, β€œmostly” randomly.)

In any case, I think that sooner or later the error code will encounter a problematic assembly and failure in any case. Thus, a strong recommendation: insist on fixing the error.

+2
source

Source: https://habr.com/ru/post/1337733/


All Articles