I'm experimenting with tampering of the assemblies in order to be able to mock the code which cannot easily be mocked, such as SharePoint assemblies.
As a prototype, I have a solution where the tested code is tampered through a custom build action with ILRepack and Mono.Cecil, so that the actual code is not the one which was originally written.
When the assembly containing the tested code is not signed, everything works well. When the assembly is signed, I see the well expected error:
The located assembly's manifest definition does not match the assembly reference.
Since the assembly is tampered, obviously, the key is either not the same (if signed after tampering) or doesn't exist.
I thought that passing by AppDomain.CurrentDomain.AssemblyResolve
event could allow forcing the tampered assembly to be accepted, but it's not.
How do I ask .NET Framework to ignore the checking of assembly matching during unit tests running in full trust, and accept unsigned assemblies when it expects them to be signed?
As I understand it, the problem is not strong name validation. Not only the error would be different, but also running the corresponding sn –Vr
has no effect: the error is still there.
The actual problem seems to be at the assembly binding level. This is also why I'm surprised to see that AppDomain.CurrentDomain.AssemblyResolve
event is raised, but its result is still ignored; probably, it doesn't do what I always thought it did.