2

I'm writing a C++/CLI RCW around a set of proprietary COM-objects for use from a C#-application, when I deploy the RCW and the C#-application I get a FileNotFound error.

After this I did the simplest thing possible:

A .NET Class Library written with C++/CLI (VS2012), no code added to the default implementation.

A C# Windows Forms Application, Solution and project set to target x86. A reference added to the C++/CLI class library But a button the form in the C# appilcation and crete an instance of Class1 i the C++/CLI library.

The error is still the same; in detail:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IO.FileNotFoundException: Could not load file or assembly 'ClassLibraryTest.dll' or one of its dependencies. The specified module could not be found.
File name: 'ClassLibraryTest.dll'
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at WindowsFormsApplicationTest.Form1.button1_Click(Object sender, EventArgs e) in c:\Users\Sten\Documents\Visual Studio 2012\Projects\C#\WindowsFormsApplicationTest\WindowsFormsApplicationTest\Form1.cs:line 23
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)




************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34209 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
WindowsFormsApplicationTest
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/SmokeTest/WindowsFormsApplicationTest.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34209 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34209 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34238 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

I have used the Fusion Log Viewer to try to find the error, but according to the log my ClassLibraryTest.dll is loaded successfully.

What am I missing here?

BePPe
  • 29
  • 1
  • 2
    Why are you writing a c++/CLI wrapper around COM in the first place? c# can directly access COM regardless of what language the COM objects are written in. _[Best way to access COM objects from C#.](http://stackoverflow.com/questions/635839/best-way-to-access-com-objects-from-c-sharp?lq=1)_ –  May 15 '15 at 09:44
  • I agree with @MickyDuncan. Also, one of the ways you can trouble shoot this error is to look and see what files ClassLibraryTest.dll depend on. There is a tool called depends that does a great job of that. You can also use this link to enable Fusion logging to possibly get more details: http://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net. Finally you can also use System Internals ProcMon to see what files it can't find and where it is looking for them. – mageos May 15 '15 at 10:21
  • 1
    You have a dependency on another DLL, a native one, and you forgot to copy it. A very common one that's overlooked is the C runtime library. If you have no idea then use SysInternals' Process Monitor. You'll see your program searching for the DLL and not finding it towards the end of the trace. – Hans Passant May 15 '15 at 10:23

1 Answers1

0

Try compiling in x86 if you are compiling in x64. It worked for me.

Subhash Makkena
  • 1,909
  • 2
  • 13
  • 15