0

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in LoggerLibrary.dll

Additional information: Could not load file or assembly 'log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a' or one of its dependencies. The system cannot find the file specified.

The log4Net called from a c++ wrapper cause this excption I added a call to the log4Net in the beginning of the test and it's stable, why? Is the DLL didn't load yet?

Amir Touitou
  • 3,141
  • 1
  • 35
  • 31

1 Answers1

1

Good news is you can build the .net dll from Visual Studio source code provide at log4Net site https://logging.apache.org/log4net/download_log4net.cgi and choose the right target framework that suits your needs.

Then you can exposed the classes you want as COM classes so C++ can consume them. You'll have to add some interfaces to the code.

This article gives a great explanation "How to call a managed DLL from native Visual C++ code in Visual Studio.NET or in Visual Studio 2005" https://support.microsoft.com/en-ca/kb/828736

Then sign your dll.

sn.exe -k MyKeyFile.SNK

Replace the following lines of code in the AssemblyInfo.cs file

[assembly: ComVisible(false)]
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]

with the following.

[assembly: ComVisible(true)] 
[assembly: AssemblyDelaySign(false)] 
[assembly: AssemblyKeyFile("..\\..\\MyKeyFile.SNK")]

Press CTRL+SHIFT+B to generate the managed DLL to use in your C++ project.

Markus
  • 420
  • 3
  • 7
  • The problem with the Log4Net is that in the beginning of the test i am capable to write to the log file using the log4Net but after a few step in the test it's suddenly raise an exception that "Could not load file or assembly". The Test is .Net and this called to a wrapper layer that connected to a unmanage code (C++). The Unmanage code raise the exception and not the .Net (MS test) – Amir Touitou Jul 31 '16 at 14:46
  • You may have to write a wrapper around the offending unmanged code call interface to the managed code as in this example. // Interface implementation. public class ManagedClass:ICalculator { public int Add(int Number1,int Number2) { return Number1+Number2; } } – Markus Aug 02 '16 at 04:19
  • I have a wrapper! BTW this is my answer for wrappers in unmanage code http://stackoverflow.com/questions/315051/using-a-class-defined-in-a-c-dll-in-c-sharp-code/36574077#36574077 – Amir Touitou Aug 02 '16 at 10:27