Unfortunately, you are faced with a “design error” in VS (or, in other words, a “feature”).
Your suspicion that the problem is with the Visual Studio designer, who needs to know where the local DLL is located, is partially right. This is not a matter of not knowing the location, but rather the fact that the designer cannot reflect mixed-mode assemblies (those that contain both managed and native code) to create an instance of the control. This causes the toolbar to display the error you specified.
The workaround is to compile the C ++ source files using /clr:pure to create a purely managed EXE.
Another possibility (also a “design error” in VS) is that the control you are trying to add was compiled as a 64-bit component. Since Visual Studio is a 32-bit process, it can only run 32-bit modules. Although it allows you to add a link to a 64-bit assembly, it cannot actually JIT compile this 64-bit assembly and execute it in the process.
The workaround here is to compile your custom control assembly using the “AnyCPU” parameter, which will lead to its execution as a 32-bit process in a 32-bit environment, and a 64-bit process in a 64-bit Environment. In fact, this is the best of both worlds, assuming you wrote your code correctly.
Finally, if none of them work, there is always the opportunity to bypass the constructor. You can still write the code needed to instantiate your user control and set its properties in the form initializer. All you lose is the ability to use the control inside the constructor inside Visual Studio. Everything will work as expected at runtime.
Cody gray
source share