3 Answers

  1. Run ildasm.exe /out=first.il first.dll (or first.exe )
  2. Edit first.il and find the .assembly extern block for the reference to second.dll.
  3. Change the public key token in that block.
  4. Run ilasm.exe first.il to produce first.dll (or first.exe )

What is the PublicKeyToken?

The public key token is a unique 16-character key that is given to the assembly when it is built and signed in Microsoft Visual Studio. To determine the public token key, you can run the Strong Name tool (sn.exe) on the assembly.

What is PublicKeyToken in app config for?

The public key token is a 64-bit hash of the public key which corresponds to the private key used to sign the assembly. It’s used to make an assembly name unique, so two strongly named assemblies can have the same filename, but . NET will treat them as different assemblies.

How do I use Ildasm?

To use the GUI, type ildasm at the command line without supplying the PEfilename argument or any options. From the File menu, you can navigate to the PE file that you want to load into Ildasm.exe. To save the metadata and disassembled code displayed for the selected PE, select the Dump command from the File menu.

How do I get PublicKeyToken in Visual Studio?

Visual Studio Add-in to get an assembly PublicKeyToken

  1. In Visual Studio, select External Tools from the Tools menu.
  2. In the External Tools dialog, click Add and enter Get Assembly Public Key for the Title.
  3. Fill the Command textbox by browsing to sn.exe.

What is a BindingRedirect?

Specify assembly binding in configuration files. To redirect one assembly version to another, use the element. The oldVersion attribute can specify a single assembly version or a range of versions. The newVersion attribute should specify a single version. For example, <bindingRedirect oldVersion=”1.1.</p>

Could not load file or assembly PublicKeyToken null or one of its dependencies?

This error usually means that the assembly was not found. Try verifying that the file exists in the directory where your application is running.

What is the public key token?

The .Net framework documentation states that the Public Key Token is the ‘last 8 bytes of the SHA-1 hash of the public key’. .Net provides the strong name tool (sn.exe) for generation and verification of the public key and public key token in addition to other options.

Is PublicKeyToken field optional?

As specified in Microsoft’s documentation, publicKeyToken field is optional. However, it is recommended to use it for a strong mapping of your assemblies. Before going further; What is the public key token?

How to see the public key token of an assembly file?

If you only want to see the public key token, you can only use -T parameter. Even if you configure everything correctly, you may run into “Could not load file or assembly” issue. Read about Assembly Binding Logging to troubleshoot these kind of issues.

How to generate public key token using SN Exe?

The sn.exe can generate the Public Key Token only from the Public Key file. Hence you have to first generate a Key Pair and then extract the Public Key. This Public Key is then passed to the sn.exe. Here are the steps for generation of Public Key and verification of its Token using sn.exe.