0

I followed the method described by the user Smoke in the post, How to call a C# library from Native C++ (using C++\CLI and IJW)

But, I am getting an error during runtime.

A first chance exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module.

I have copied my C# dll file into the Debug folder of the my c++ project as suggested by a comment in the question mentioned above. But, I am still getting the same error.

Here is the line of code which uses the C# library.

QLNet::Date^ nowDate = gcnew QLNet::Date(15,2,2002);

More info:

If I only declare the variable( QLNet::Date^ nowDate; ) and don't allocate the memory using gcnew, I don't have any errors. I am unable to debug this issue.

The C# library I am using is Quantlib C# library

https://github.com/amaggiulli/qlnet

Community
  • 1
  • 1
user98180
  • 149
  • 1
  • 4
  • 12
  • You can try to [enabling fusion logging](http://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net). If that doesn't help you identify the missing file, you can also try [Process Monitor](https://technet.microsoft.com/en-us/library/bb896645.aspx). – jmc Aug 06 '15 at 16:57
  • It is a *very* brittle way to call managed code. It likes throwing exceptions, there's nobody there to tell you what they look like. Project > Properties > Debugging > Debugger Type = Mixed. Then Debug > Exceptions > tick the Thrown box for CLR exceptions. Lets you find out what went wrong on your machine. Still not good enough to diagnose mishaps on your user's machine, adding logging code is not really optional. Using COM is the better mousetrap, at least you can get an error code and the Exception.Message property. – Hans Passant Aug 06 '15 at 17:31
  • @HansPassant Thank you for the suggestion. I tried this to get the error message. Here is the error message Additional information: Could not load file or assembly 'QLNet, Version=1.4.0.4, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. QLNet is the C# dll file. It appears that the C# library is not loaded even though I have enabled /clr and have added the C# dll path in the "Framework and References". Do you have any thoughts on why the C# dll is unable to load. Thanks again. – user98180 Aug 10 '15 at 13:43
  • It is a simple file-not-found error. We can't find it for you, but the odds that you got qlnet.dll in the same directory as your C++ executable are not great, you'll have to copy it yourself. Use a post-build event to automate it. – Hans Passant Aug 10 '15 at 13:56

0 Answers0