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?
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
.
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");