2

I have a some managed C++ assembly with simple code.

This assembly has mixed (managed/unmanaged) code. If I put unmanaged code to the separate unmanaged static library and link it with managed code then I get registration error like this: "Failed to load 'xxxxxx.dll' because it is not a valid .NET assembly".

If I put all code to one project and build it together then all works finely. I have tried it on VS2008 + .NET3.5 + RegAsm .Net2.0. My assembly is signed.

I would like to save my code separation for unmanaged static library and managed assembly.

What I need to do?

Thanks in advance.

AMadmanTriumphs
  • 4,888
  • 3
  • 28
  • 44
yuriv
  • 21
  • 2
  • How possibly can it contain "mixed code"?.. Are you talking about "unsafe code" instead? it's still managed then.. – vines May 23 '11 at 14:41
  • no he is talking about a mixed mode assembly see http://msdn.microsoft.com/en-us/library/x0w2664k.aspx – Yaur May 23 '11 at 15:00
  • deleted my answer because it was wrong. take a look this related SO question which I think will help you. http://stackoverflow.com/questions/2691325/c-cli-mixed-mode-dll-creation – Yaur May 23 '11 at 15:08
  • It's auto-answer ;-). I have done some experiments and here some my issues: 1. If you want to use static libraries with unmanaged code into managed C++ project then you need to compile it with /clr option. 2. Be carefull with optimization of unmanaged library's code (sometimes I have got the message like "...damaged library image" during release compilation of the managed project). 3. If you want to work with pure unmanaged code (without /clr compilation) and small time and space overhead then try to include unmanaged code like unmanaged dll library (I am using boost library like dll). IMHO – yuriv May 25 '11 at 11:16

1 Answers1

1

Your lib must be built to use the C++ runtime dynamically (as of .NET 2.0).

In project properties, open C/C++, and go to Code Generation. Look for Runtime Library, and set to Multi-threaded DLL for release, and Multi-threaded Debug DLL for debug.

Lou Franco
  • 87,846
  • 14
  • 132
  • 192