Search code examples
c#.netclr.net-assembly

Can't skip .net strong name verification on windows


I have tried to skip .net strong name verification on both Win10 & Win7, following How to disable strong name validation and this, type the following comamnds on both x86 and amd64 environment.

vcvarsall.bat amd64
sn /Vr *
vcvarsall.bat x86
sn /Vr *

but still receive the complains:

=== Pre-bind state information ===
LOG: User = US\Hauck
LOG: DisplayName = TestDll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b1cf2005f5cbe0bd (Fully-specified)
LOG: Appbase = file:///D:/myprojects/bin/
LOG: Initial PrivatePath = NULL
Calling assembly : TestDriver, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b1cf2005f5cbe0bd.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using machine configuration file from c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: TestDll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b1cf2005f5cbe0bd
LOG: Attempting download of new URL file:///D:/myprojects/bin/TestDll.DLL.
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN 
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

After googling a lot I still have no idea how to skip the verification.

References:

  1. How to: Enable a 64-Bit Visual C++ Toolset on the Command Line
  2. Bypassing strong-name verification for a .Net assembly
  3. How to: Disable the Strong-Name Bypass Feature

Solution

  • The public key token is part of an assembly identity. That means that if you have two assemblies:

    TestDriver, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b1cf2005f5cbe0bd

    and

    TestDriver, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

    They are seen as completely different by the assembly loader. It looks to me like the problem you have here is that you referenced the strong named version of the assembly, but only have the unsigned version available.

    If you are building TestDriver yourself, you need to make sure you have the public half of the key pair with which it will ultimately be signed available, and then check the "Delay sign only" box on the Signing page of the assembly properties in Visual Studio. This will build a version of TestDriver that has a public key token, but which is not in fact signed. At that point, disabling signature verification will be necessary, but once disabling, the assembly should load.