visual studio .net ide:
I am trying to create a C++ Windows Form Application that contains managed and unmanaged code. My problem is not with the mixed code, but with my User Controls and the Visual Studio 2005 IDE. After I change the Common Language Runtime support compiler option from /clr:pure to /clr (necessary for mixed code), I can not open any Windows Form that contains a User Control in the Visual Studio 2005 IDE. To create the test project: • Create a C++ Windows Form Application project named ‘Mixed’. • Add a User Control to the project named ‘UserCtrl’. • Add a button to the new User Control. • Save and build the project. • Open Form1.h [Design]. From the Toolbox, add the ‘UserCtrl’ User Control to Form1. • Add #include "UserCtrl.h" to Form1.h. • Save and build the project. • Close all open code windows in Visual Studio. • Open the Form1.h [Design] file, it will open and display the Form with the User Control. To create the problem: • Close all open code windows in Visual Studio. • Change the compiler option from /clr:pure to /clr. • Clean the solution, and then build it. • Open the Form1.h [Design] file, Visual Studio will display an error. When I try to open the Form in design mode I get the error: Could not find type 'Mixed.UserCtrl'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built. The variable 'userCtrl1' is either undeclared or was never assigned. at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement) If I change the compiler option back to /clr:pure and rebuild the project, I can successfully open the Form1 Form in the IDE. With either compiler option, I can always successfully build and run the code. However, once I change to /clr, I can not open my Windows Forms that contain User Controls in the IDE. I have tried recompiles, deleting my ncb file, adding various directories to my PATH, recreating the controls, check variables exist with namespace, restarting VS, nothing seems to help. Any ideas on how to fix this problem?
Hello Gallan, Thanks for your detailed information. I have reproduced the issue on my side with (VS 2005 sp1). The User Control doesn't work fine in VS IDE when compiling with /clr. It seems like the issue is related to the CLR compiler. However, I cannot figure it out so far. We need to perform research on this issue. We will reply here as soon as possible. If you also have any more concerns on it, please feel free to post here. I'm glad to assist you. Sincerely, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Hello Gallan Thanks for your waiting. This is an expected behavior given a known CLR limitation. The same problem happens for user controls and inherited forms. The workaround is to compile the mixed-mode code as a DLL not as an EXE. If you'd like more detail, here it goes :) The Windows Forms designer uses reflection on user controls (and on inherited forms) to show them in the designer view. The CLR has a limitation where it cannot reflect on mixed-mode (/clr) EXEs from outside the EXE. It can, however, reflect on pure IL (/clr:pure) EXEs as well as pure IL (/clr:pure) and mixed-mode (/clr) DLLs. Consequently, to get user controls to work, we'll have to make the CLR happy by either compiling our code using /clr:pure (which the VC++ wizards do by default) or compiling your code into a DLL. In sort, what you need to do is to put the user control in a separate DLL and compile that using /clr. Alternatively, they could package both the form and the control in the DLL. Hope this helps. If you still have anything unclear, please feel free to let me know. I'm glad to assist you. Have a great day, Sincerely, Wen Yuan Microsoft Online Community Support ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Don't see what you're looking for? Try a search.
|