Custom Controls having problems with persisting Enums

M

malcolm

I've now spent countless hours trying to solve this to no avail. I
have searched through and through many different newsgroups and
postings and cannot seem to find any solution to this. The error I get
is:

The variable 'ListID' is either undeclared or was never assigned.

On top of this, my custom control instance will lose that property
that I have set in the designer.

Where ListID is actually an enum type. In fact, we have about 70
projects, 30 of which are custom controls. We're using c# in Visual
Studio 2003 (.net 1.1). This error shows up over and over again in
many of our controls that have a custom enumeration inside of the
control (or so it seams). If the property is a value type, then it
works fine. As a fix, we basically set the property in the constroctor
of the containor form (what a hack!). Anyway, this is what I've
learned so far (so if you have the same problem let's share notes):

1) Out of the countless newsgroups threads I found on this, the most
popular solution (out of the ones that posted a solution) is to place
the declaration of the enum outside the custom control class. Well,
I've done that to all the enums that apply and it didn't fix the
problem.

2) On top of this, the problem only shows up in our master .exe
project. If I try and reproduce the problem with the same control in a
new project (with the intent to post a sample online) with a blank
form, then it is not a problem and it works fine. To me, this is the
single factor that has caused alot of confusion for this issue. It's
simply not very reproducable. But, we get it every single time in our
mast application that refernces all 70 projects...

3) This error only reveals itself under the following conditions:
a) If I open a form for the first time with that that user control on
it, there will be no errors. The property will be set correctly in the
designer.
b) one of two things can cause the error to occur. Simply compiling,
or closing and opening the form again. At this point, the designer
loses the property and selects the default enum (first one) and throws
this error. As a result of this, I've even tried to debug the control
in a seperate IDE and it does not throw an error at this point.

4) The error makes no sense! It simply should not be an error.

5) For the above example, I have an internal variable of type ListID
that is initialized to the default value. I also use the
DefaultValue() Attribute and default it to that same value:
NOTE: It's set to Browsable(true) on purpose, kind of the point of
this control...

public class AttributeListBox : ListBox
{

private Attributes.ListID m_attributeID = Attributes.ListID.Null;

[DefaultValue(Attributes.ListID.Null)]
public Attributes.ListID AttributeID
{
get {return m_attributeID;}
set
{
m_attributeID = value;
RefreshView();
}
}

private void RefreshView()
{
.. Populate the dropdown depending on AttributeID selected
}

}

6) A funny thing is that, this problem nearly goes away (if not
entirely) when we change to release mode.

7) Now I have a hunch as to what the actual cause is, but it's merely
an educated guess. I think Visual Studio is causing this problem
because dlls are not copying themselves correctly. Before I explain, I
think it's also important to show exactly how we develop to see if
anyone else having the same problems can relate to this.

Like I said earlier, we have some 70 projects. We've come to learn
that the best way to develop is to leave all the defaults (CopyLocal =
true, build paths, etc...) and to develop with all your projects open
in 1 solution. The reason why this is good, I think, is that if you
make a change to a core library, then Visual Studio re-compiles
everything in order. We've learned this the hard way, but are very
happy with this way.

Now as a result, there may be a fair amount of copying of dlls which
may be why this happens only in our big solution and I can't reproduce
this in a smaller form. Also, the fact that Release mode generally
doesn't have this problem is a clue to make me think this. I've even
read some newsgroup threads that have said similar things. This also
could explain why placing the enum outside of the control works for
some people (probably with smaller scale projects), since the order in
which the assemblies copy themselves may fail for me and not other
people. Microsoft has publicly stated that the size of the dll can
cause issues (in particular if it's over 64k)

http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q313512

We have several dlls over 64k, but we're following all of Microsofts
recommendations as to avoiding locking issues from that KB.

8) Here's another post where a guy says inherited forms cuase this
too. Which is something we relay on heavily
http://groups.google.com/groups?hl=...2x.143444%40rwcrnsc52.ops.asp.att.net&rnum=13

Any help would be greatly appreciated! I hope that this thread could
be the one where we all put our heads together and solve this
rediculous bug in Visual Studio (and/or .NET). Maybe the solution is
to use the command prompt!

-Dave

p.s. When is Microsoft going to release a service pack for Visual
Studio 2003!
 
M

Michael Bray

I've now spent countless hours trying to solve this to no avail. I
have searched through and through many different newsgroups and
postings and cannot seem to find any solution to this. The error I get
is:

The variable 'ListID' is either undeclared or was never assigned.

Yeah I've dealt with this before, and I think I found the solution was to
***NOT*** place the enum inside a class. Put it inside the namespace, but
outside of any classes.

-mdb
 
M

malcolm

Yes, this was in my first part of my message. I think this works
because you probably have a smaller project. We have roughly 70
projects in 1 solution. As I said above, I have a hunch that Visual
Studio is causing this by not being able to copy the dll's properly.
This would explain to things:

1) Why some people still have this problem and others don't.
2) The exact error that is raised can be explained by the fact that
the dll is not being copied over. The actual error may even be coming
from the Attribute DefaultValue...

These are only guesses though. Anyone else having these issues?

if my hunch is right, how do we solve this? Do we use less, but
larger, dlls? One thing we do is we have very specific dlls. I notice
Microsoft doesn't quite do this. Example, System.Windows.Forms.dll
holds virtually all their controls, System.dll holds several core
classes. We, on the other hand, have 1 control per dll. They seem to
have 20 or 30 entire dlls for the entire .NET framework. I've never
heard any recommendations toward this (nor should I, this should not
be a factor) but could this be a factor?

-dave
 
M

malcolm

Another thing that happens which may be related:

Sometimes I lose intellisense on Enums. Yet, when I type out the Enum
type and then select it and hit F12, it finds it every time.

This re-enforces my theory. I think Visual Studio is raising an
internal error that causes all of these things.

WHEN IS A SERVICE PACK FOR VISUAL STUDIO 2003 COMING!!!!!!!!!
 

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