System.IO.FileNotFoundException when trying to remove UserControl on form in constructor

I created a custom UserControl in Managed C ++ that wraps some native controls with code. I confirmed that the control works at runtime, and tried to get the control to work with the Visual Studio designer by letting drag and drop the control from the designer toolbar.

As long as I have successfully added the UserControl to the toolbar, nothing happens when I drag the control onto the Windows Form. To investigate the problem, I opened a second instance of Visual Studio 2008 and attached its debugger to the devenv.exe instance where I am trying to use UserControl. After removing the UserControl on Windows Forms, the Visual Studio debugger throws a FileNotFoundException in the mscorlib.dll file when it tries to load the module that contains the UserControl.

I noticed that the designer does not load the dll from the project's output path, but creates a copy of the assembly in the% UserData% \ VisualStudio \ 9.0 \ ProjectAssemblies \ RandomFolderName folder. However, none of the module dependencies are copied, and I believe this is the source of the FileNotFoundException.

Any ideas how to fix this problem? Ideally Vistual Studio copies all assembly dependencies when copying the dlls to the ProjectAssemblies folder, but I can't figure out how to do this.

+1


source to share


3 answers


Visual studio is unaware of an unmanaged dependency. You will have to copy the dlls yourself or copy them to the windows \ system32 directory.

Two other strategies for dealing with this.



  • Wrap this assembly in another assembly and manually load the mixed DLL using assembly.loadfrom. this function will configure the correct load directory for the mixed mode DLL.

  • In your mixed build, use loadlibrary to load native dependencies DLLs this way you can specify their paths.

+1


source


Old thread, but subordinating my solution to a similar problem, since I just ran into an issue and found this question during the process. Since you are wrapping the control this might not be as easy as a fix, since I only had access to types.



Basically, I just started loading native DLLs into my C ++ / CLI wrapper library. Since the C ++ / CLI part of the wrapper contains the interface specifications used by Visual Studio and the framework, the native DLL is never needed or loaded. I've answered this in more detail in this question: fooobar.com/questions/1030430 / ...

+1


source


Try not to put anything in the constructor of the control that will access the files. If you need to, sometimes the DesignTime property helps to skip the offending lines.

0


source







All Articles