Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to generate a temporary class - Cryptographic failure while signing assembly

I have a signed class library that I want to create assemblies for via the sgen tool. However, I get an error when I try to run the following command:

$ sgen.exe /a:testsign.dll /force /compiler:/keyfile:..\..\testsign.pfx /verbose /n
Error: Unable to generate a temporary class (result=1).
error CS1548: Cryptographic failure while signing assembly '[...path...]\TestSign.XmlSerializers.dll' -- 'Error signing assembly - - The parameter is incorrect. '

If you would like more help, please type "sgen /?".

I checked the error on MSDN which states that

CS1548 occurs when assembly signing fails. This is usually due to an invalid key file name, an invalid key file path, or a corrupt key file.

However, I just created the key, the path is correct and to my knowledge Visual Studio 2010 does not create corrupt keys.

This issue is fairly simple to reproduce.

  1. Using the code pasted here create a new class library.
  2. Create two classes, one class TestSigning and one class Model
  3. go to Project properties > Signing and check the "Sign this assembly"
  4. create a new Strong name key file
  5. open up Visual Studio Command Prompt (2010)
  6. locate the dll and run sgen /a:<dllname> [... as above ...]

My guess is something with the public key for the keyfile.. But I cannot find any sources as to how I inform sgen of what password I have used to protect my key file.

I am not sure how to proceed. the other threads I have looked at here on SO have the same error "header" unable to generate temporary class but different error details, for which none has the Cryptographic failure (that I have found).

like image 973
default Avatar asked Oct 08 '22 01:10

default


1 Answers

Following the instructions in this thread solved this issue. Although it wasn't done manually with the sgen tool, it was done via Visual Studio.

That is, the above example is changed to:

  1. as before
  2. as before
  3. as before
  4. as before
  5. Go to the Build tab
  6. Set the Generate serialization assembly to On
  7. Right click the project and select Unload project
  8. Right click the project and select *edit nnn.csproj**
  9. Paste the following snippet somewhere

    <PropertyGroup>
        <SGenUseProxyTypes>false</SGenUseProxyTypes>
        <SGenPlatformTarget>$(Platform)</SGenPlatformTarget>
    </PropertyGroup>
    
  10. Reload and build the project.

like image 125
default Avatar answered Nov 10 '22 15:11

default