Search code examples
.netserializationversionsignaturestrongname

.net: When i update the assembly version, it said: Could not load file or assembly. A strongly-named assembly is required


I have a assembly with C# code. And the version of this assembly is 1.0.0.0. This Assembly's information is serialized when i serialize the data of this assembly into binary. And then i update this assembly version into 4.0.0.0, **

and i remove the signature

**. When i de-serialize the data of assembly, an exception occur, which is "Could not load file or assembly '[AssemblyName], Version=1.0.0.0, Culture=neutral, PublicKeyToken=[TokenKey]' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)".

How can i redirect my old version assembly to a new version assembly? Does configuration assembly binding work?


Solution

  • In your config, add the following block ,

        <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="yourAssembly" publicKeyToken="PKTokenOfYourAssembly"/>
        <bindingRedirect oldVersion="1.0.0.0" newVersion="4.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>