3

I am using VS2012. I have a C++ Native Library and a C++/CLI project that I built to wrap the C++ Native library. I am bulding the projects for x64 bits.

I don't have much experience with C++ or C++/CLI, this is the first project I am trying to sign.

How I signed my C++/CLI project:

  • I placed my strong name in the same folder where the C++/CLI is located and then I went to: Right Click on the project -> Configuration Properties -> Linker -> Advanced -> Key File.
  • I wrote the name of my file in the Key File attribute: StrongNameKey.snk.

It builds without errors and I can run the tests. I also have another Solution that uses the resulting dll, and it builds fine and the test pass. But that solution it is not using signed assemblies.

The Errors I am getting:

I have a C# Solution with all its assemblies signed.

At first I was using my C++/CLI dll in this solution without signing it, and it was mostly working. But I was getting an error similar to this when trying to use one of the Wrapper classes in a ComboBox in WPF.

That post made me realize I had forgotten to sign the C++/CLI assembly.

So then I signed them as I described above, but when I tried to use the dll in my C# Solution I was getting a lot of errors. None of them seemed related to my dll, except 2 warnings.

First Warning

Warning 18 There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "MyNamespace.MyCppCLI", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. MyTestApp

I don't have anything set as AMD, I just have it configured to x64. My C# Project is configured for AnyCPU.

Second Warning: The error said like there was 2 different locations of the signature.

I was using the same "name" both for the C# and the C++/CLI signature (the files were copies). I changed the name of the C++/CLI signature, and built the project again. And now the C# project builds, but I am still not able to use the class in the ComboBox and the designer throws the error of the other post, except that the public token is not null.

I don't know what I am doing wrong.

What are the correct steps to sign a C++/CLI Project? Where should I place the signature file?

Community
  • 1
  • 1
Dzyann
  • 5,062
  • 11
  • 63
  • 95
  • There are a lot of moving parts here. The most significant problems are you trying to run 64-bit code in a 32-bit process. And that this DLL needs to be found at design time. This is not going to work. You'll need to use the DesignMode property to ensure that none of this C++ code is going to run at design time. – Hans Passant Feb 25 '14 at 13:15
  • @HansPassant you can't use C++/CLI dlls at design time? – Dzyann Feb 25 '14 at 13:19
  • Sure you can, just not your DLL. – Hans Passant Feb 25 '14 at 13:26
  • @HansPassant I am struggling a bit with this. You said that I am trying to run 64 bit code in 32 bit process, I assume you refer to the Designer process. Am I correct? So I either don't use the x64 dll in the Designer OR build it as x32. And it has nothing to do with the signing? – Dzyann Feb 25 '14 at 13:30
  • Right. Visual Studio is a 32-bit process. – Hans Passant Feb 25 '14 at 13:36
  • @HansPassant now I understand you. When I saw the warning I thought it was referring to my App, which I was building to AnyCPU so the it was rather confusing. Regarding signing the assembly is it ok the way I did it? – Dzyann Feb 25 '14 at 15:02

0 Answers0