We use strong named assemblies and internal interfaces/classes in our solutions. Unfortunately it is not possible to use Unity Interception in that case. It creates a dynamic assembly which is not signed and therefore not loaded. We figured out how easily that could be implemented. We did the change locally and rebuild Unity Interception by ourselves. It works great in our particular case.
Important hint: This is only an issue, if you work with internal interfaces/classes. You have to add the following line to your AssemblyInfo.cs
[SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline",
Justification = "Need to use constructor so we can place attribute on it.")]
static InterfaceInterceptorClassGenerator()
{
var assemblyName = new AssemblyName("Unity_ILEmit_InterfaceProxies")
{
KeyPair = new StrongNameKeyPair(Resources.unity)
};
AssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(
assemblyName,
#if DEBUG_SAVE_GENERATED_ASSEMBLY
AssemblyBuilderAccess.RunAndSave);
#else
AssemblyBuilderAccess.Run);
#endif
}
The key file itself could be found on the top level within the build folder. Its name is “unity.snk”. We imported that file as resource file in Visual Studio and named it unity. Therefore it’s possible to access the content with the command Resources.unity.
It would be great to have that functionality in the official builds too.
Thanks for all your efforts.
@mizasie wrote:
Hello,
We use strong named assemblies and internal interfaces/classes in our solutions. Unfortunately it is not possible to use Unity Interception in that case. It creates a dynamic assembly which is not signed and therefore not loaded. We figured out how easily that could be implemented. We did the change locally and rebuild Unity Interception by ourselves. It works great in our particular case.
Important hint: This is only an issue, if you work with internal interfaces/classes. You have to add the following line to your
AssemblyInfo.cs
Have a look into the constructor without parameters: https://github.com/unitycontainer/unity/blob/master/source/Unity.Interception/Src/Interceptors/InstanceInterceptors/InterfaceInterception/InterfaceInterceptorClassGenerator.cs
We changed it into that:
The key file itself could be found on the top level within the
build
folder. Its name is “unity.snk”. We imported that file as resource file in Visual Studio and named itunity
. Therefore it’s possible to access the content with the commandResources.unity
.It would be great to have that functionality in the official builds too. Thanks for all your efforts.
Cheers Micha