Reputation: 1765
I am trying to create and use a C# library (dll) with C++ (C++/Cli) project. However my C# library doesn't come (or produces) with .lib file. I have been told that I need a lib file but I'm not sure how to produce it.
You can view the code here
I have included the .dll file in my C++ project but it fails to run.
I get the following error:
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module.Additional information: Could not load file or assembly 'ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
I am fairly new to playing with .dll and .lib file. This problem is related to my other problem found here
Upvotes: 0
Views: 671
Reputation: 725
.NET assemblies (in your case the C# library) are not normal dlls, in other words they don't expose their APIs like other standard (native) windows dlls. Instead they expose their APIs in a way only other .NET can understand.
There are two possible ways to expose a .NET API for a C++ project.
1- Convert the C++ native project into a managed C++ project (i.e. a .NET C++ assembly) and then you can add the C# library as a .NET reference to the C++ project and call it as a managed library.
2- You can turn your .NET library into a COM+ library and then consume it from C++ as a COM+ dependency.
In short, directly consuming .NET APIs as through a .lib file is not a feature of .NET
Upvotes: 3