views:

664

answers:

2

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.

+1  A: 

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.

  1. 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.

  2. In your mixed assembly use loadlibrary to load your native dependencies dll's this way you can provide their paths.

Aaron Fischer
I was afraid that was the case. Copying the files to the system directory is not an ideal solution for me, and since the Visual Studio designer creates the assembly copy in a random folder each time an instance is dropped on a form, copying the modules myself is not a viable solution either.
Joe Waller
windows\system2 ? Do you mean c:\Windows\System32 or c:\Windows\System ?
bitbonk
Anyway it doesn't work for either location.
bitbonk
A: 

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.

Tomer Pintel