Getting a reference to System.String from System.Runtime.dll instead of mscorlib

I have a link to System.Runtime.dllwhat I used Assembly.ReflectionOnlyLoad. When I call .GetType("System.String")on it, I get type System.Stringin mscorlib, not one in System.Runtime, which will cause me problems because I will generate the wrong IL. Is there any other way to do this?

+4
source share
1 answer

What you see is the result of assembling the assembly. When you emit assemblies using the System.Reflection API, there is no easy way to avoid leaking metadata references (such as type) from your environment to the final assembly. This is because SR Api was intended to generate a run-time code, and not to generate some result to save.

You can try using something like Mono.Cecil, which is much more suitable for this purpose.

+1
source

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


All Articles