Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / IDE / June 2007

Tip: Looking for answers? Try searching our database.

User Control error in IDE when compiling with /clr

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gallan - 14 Jun 2007 09:34 GMT
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?
WenYuan Wang [MSFT] - 14 Jun 2007 14:35 GMT
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.
WenYuan Wang [MSFT] - 18 Jun 2007 04:35 GMT
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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.