问题
I've used ILMerge to merge a secondary assembly that is itself merged with Castle.DynamicProxy, having set most if not all of the normally-public Castle types to internal. When I use the code from the secondary assembly that is dependent on the Castle types, I get a TypeLoadException saying that access is denied.
The first step to check is that my merged assembly has the InternalsVisibleTo attribute still set for the DynamicProxy2 assembly. Any way to check this?
回答1:
DotPeek shows this by double-clicking the assembly. [assembly: InternalsVisibleTo(...)]
should be visible zero or more times.
Also, Ildasm should be able to tell you this by double-clicking the MANIFEST
of the assembly. A yellow popup shows lines that start with .custom instance void [mscorlib]System.Runtime.CompilerServices.InternalsVisibleToAttribute
.
回答2:
Assuming you can load the assembly itself, you can use Assembly.GetCustomAttributes
:
var asm = ...;
var internals = asm.GetCustomAttributes(typeof(InternalsVisibleToAttribute),
false);
var foundDynamicProxy2 = internals.Cast<InternalsVisibleToAttribute>()
.Any(x => x.AssemblyName == "DynamicProxy2");
来源:https://stackoverflow.com/questions/28700047/how-can-i-check-for-an-internalsvisibleto-attribute-on-an-assembly