Forms designer deleting usercontrols

C

Christian

I have a really frustrating problem, and some googling has revealed that I'm
not the only one. Its quite easy to reproduce:

1. Create a .Net C# project with a usercontrol and a forms application
2. Build the solution (debug) and add the usercontrol to the form's toolbox
3. Drag a usercontrol from the toolbox into the form
4. Close the form
5. Select the "Release" configuration
6. Open the form

Now the user control is gone with all its related code!

I know this is happening because the usercontrol .dll does not exist in the
release configuration, but is deleting sourcecode really expected behaviour?
Am I doing something wrong?

Regards,
Christian
 
G

Guest

The way the code is created behind the form is by the CodeDomSerializer associated with each control who outputs the correct code. At deserialization the same process is done in reverse. When a control is being deserialized it is also instantiated (so it can be displayed in the designer) but if the dll cannot be found, the deserialization fails. On the next serialization process the object is NOT in memory because it's deserialization failed. Therefore all the code previously created is "unnecesary" as per what is in memory and therefore removed. To protect from this behavior you may move the InitializeComponent code into a different function and call it in the constructor..

regards
iulia
 
C

Christian

Yes, but then I will loose the opportunity to use the forms designer :-(

I was hoping that the people making the forms designer would have thought it
through, so that it would mimic the behaviour of the dialog designer in VS6,
where ActiveX controls was displayed as a grey rectangle in case the object
was not available. The code was never touched.

-Christian


Iulian Ionescu said:
The way the code is created behind the form is by the CodeDomSerializer
associated with each control who outputs the correct code. At
deserialization the same process is done in reverse. When a control is being
deserialized it is also instantiated (so it can be displayed in the
designer) but if the dll cannot be found, the deserialization fails. On the
next serialization process the object is NOT in memory because it's
deserialization failed. Therefore all the code previously created is
"unnecesary" as per what is in memory and therefore removed. To protect from
this behavior you may move the InitializeComponent code into a different
function and call it in the constructor...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top