Reputation: 1989
I have created a custom UserControl in Managed C++ that wraps some native code controls. I have confirmed the control works at runtime, and have been trying to make the control work with the Visual Studio designer by allowing drag and drop of the control from the designer toolbox.
While I have successfully added the UserControl to the toolbox, nothing happens when I drag the control onto a windows form. To investigate the problem, I opened a second Visual Studio 2008 instance and attached its debugger to the devenv.exe instance where I am attempting to use the UserControl. After dropping the UserControl onto the windows forms, the Visual Studio debugger outputs a FileNotFoundException in mscorlib.dll when trying to load the module containing the UserControl.
I noticed that the designer does not load the dll from the project's output path, but rather creates a copy of the assembly in the %UserData%\VisualStudio\9.0\ProjectAssemblies\RandomFolderName folder. However, none of the module's dependencies are copied, which I believe is the source of the FileNotFoundException.
Any ideas how to resolve this issue? Ideally Vistual Studio would copy all the assembly's dependencies when copying the dll to the ProjectAssemblies folder, but I can't figure out any way to make this happen.
Upvotes: 1
Views: 3271
Reputation: 1698
Old thread, but submitting my solution to a similar issue since I just encountered the issue and found this question during the process. Since you are wrapping a control, it may not be as easy a fix as mine with just accessing types was.
Basically I just made the native DLLs to be delay loaded in my wrapper C++/CLI library. Since the C++/CLI part of the wrapper contains the interface specs used by Visual Studio and the framework, the native DLL is never needed or loaded. I answered it with more details in this question too: https://stackoverflow.com/a/15481687/34440
Upvotes: 1
Reputation: 21231
Visual studio is unaware of any unmanaged dependency. You will have to copy the dll's your self or copy them into your windows\system32 directory.
Two other strategies for dealing with this.
Wrap this assembly with another assembly and manually load your mixed dll with assembly.loadfrom. this function will setup the correct load directory for your mixed mode dll.
In your mixed assembly use loadlibrary to load your native dependencies dll's this way you can provide their paths.
Upvotes: 1
Reputation: 1587
Try not to put anything in the constructor of the control that will access files. If you have to, sometimes the DesignTime property helps in skipping the offending lines.
Upvotes: 0