views:

98

answers:

1

I have a C# project with a UserControl in it.

This user control depends on a particular C++ Mixed mode dll which in turns, acts as a facade to an unmanaged C++ DLL

                     C#           C++ Mixed            C++ Umnanaged
  [ main app ] ---> [ myUC ] ---> [ OCShell.dll ] ---> [ OCC.dll ]

In the Design View, I cannot add the UserControl. It says that there is a FileNotFoundException on OCShell (or one of its dependency). However, via code, everything works fine. In main app (windows form) I can

myUC uc = new myUC();
this.Controls.Add(uc);

and this works fine. The right code gets executed properly.

I checked with Dependency Walker and everything is ok. Everything gets properly copied to the Bin\Debug\ directory and each of those DLL sees each other.

My guess is that the Design View Editor does not check the proper paths for those DLL and thus returns an error.

I also tried copying every dll to every possible directory in my solution but that didn't help either

+1  A: 

Yes, that's a problem. At issue is that the code is executing in Visual Studio, not your app. The probing path that's used to find dependent assemblies will only include private directories of VS (Common7\IDE\PrivateAssemblies and PublicAssemblies), not the build directory of your project. You can make it find OCShell.dll by copying it into one of those directories, but the unmanaged DLL is going to have to be put in a directory that Window will search when looking for DLLs. Which, other than the Windows side-by-side cache which requires a manifest, is limited to a directory on the system PATH environment variable.

These are not pleasant options. The best thing to do is to ensure that the code in these DLLs cannot execute at design time. You do so by using the DesignMode property, bypass calls if it is True. That needs to be done in at least the constructor and the Load event. Other events can run as well. Also greatly minimizes the odds that you'll crash Visual Studio because of a bug in the unmanaged code. If this impacts the design-time view of the control then you may need to write a designer to make up for that.

Hans Passant
DesignMode totaly did the trick, thanks a LOT
Eric
Ok it did not "totaly did the trick" =(
Eric