Mysterious bug in VS2005 which occasionally causes crash

S

scarleton

A coworker and I have spent the last day and a half trying to track
down this bug in our code. We found the solution and thought we might
post it to help others out...

The setup: Class FinalForm derives from Class BaseForm that derives
from System.Windows.Forms.

public class BaseForm : Forms {}
public class FinalForm : BaseForm {}

When trying to open class FinalForm in the designer one of a number of
error happens which are listed at the bottom, they are a bit long so
here is what was causing the problem, and the fix:

The problem:

A recursive call within the base class BaseForm:

public class BaseForm : Forms
{
int count =0;
public int Count
{
get { return Count; }
}
}

The Count's getter should be returning count, but is calling itself!
Once it returns the right thing, all is well.

I hope this helps out others!

Sam

The differen errors we saw, there might be more:

1: VS2005 crashes and either simply goes away or gives the dialog to
report the error to Microsoft.

2: One or more errors encountered while loading the designer. The
errors are listed below. Some errors can be fixed by rebuilding your
project, while others may require code changes.

Unable to load one or more of the requested types. Retrieve the
LoaderExceptions property for more information.
Hide

at System.Reflection.Module.GetTypesInternal(StackCrawlMark& stackMark)
at System.Reflection.Assembly.GetTypes()
at
Microsoft.VisualStudio.Shell.Design.AssemblyObsoleteEventArgs..ctor(Assembly
assembly)
at
Microsoft.VisualStudio.Design.VSDynamicTypeService.ReloadAssemblyIfChanged(String
codeBase)
at
Microsoft.VisualStudio.Design.VSDynamicTypeService.CreateDynamicAssembly(String
codeBase)
at
Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_Assembly()
at
Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.Search(String
fullName, String typeName, Boolean ignoreTypeCase, Assembly& assembly,
String description)
at
Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchProjectEntries(AssemblyName
assemblyName, String typeName, Boolean ignoreTypeCase, Assembly&
assembly)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.GetType(String
typeName, Boolean throwOnError, Boolean ignoreCase, ReferenceType
refType)
at
Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String
name, Boolean throwOnError, Boolean ignoreCase)
at
Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String
name)
at
System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.GetType(String
typeName)
at
System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager
manager)
at
System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager
manager)
at
Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager
serializationManager)
at
System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost
host)
3: One or more errors encountered while loading the designer. The
errors are listed below. Some errors can be fixed by rebuilding your
project, while others may require code changes.

Could not load file or assembly '<my assembly>, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=12e8b3ea4074fce4' or one of its
dependencies. The system cannot find the file specified.
Hide

at System.Signature._GetSignature(SignatureStruct& signature, Void*
pCorSig, Int32 cCorSig, IntPtr fieldHandle, IntPtr methodHandle, IntPtr
declaringTypeHandle)
at System.Signature.GetSignature(SignatureStruct& signature, Void*
pCorSig, Int32 cCorSig, RuntimeFieldHandle fieldHandle,
RuntimeMethodHandle methodHandle, RuntimeTypeHandle
declaringTypeHandle)
at System.Signature..ctor(RuntimeMethodHandle methodHandle,
RuntimeTypeHandle declaringTypeHandle)
at System.Reflection.RuntimeMethodInfo.get_Signature()
at System.Reflection.RuntimeMethodInfo.GetParametersNoCopy()
at System.Reflection.RuntimePropertyInfo.GetIndexParameters()
at
System.ComponentModel.ReflectTypeDescriptionProvider.ReflectGetProperties(Type
type)
at
System.ComponentModel.ReflectTypeDescriptionProvider.ReflectedTypeData.GetProperties()
at
System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetProperties()
at
System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetProperties()
at System.ComponentModel.TypeDescriptor.GetProperties(Type
componentType)
at
System.Windows.Forms.Design.FormDocumentDesigner.Initialize(IComponent
component)
at
System.ComponentModel.Design.DesignerHost.AddToContainerPostProcess(IComponent
component, String name, IContainer containerToAddTo)
at System.ComponentModel.Design.DesignerHost.Add(IComponent component,
String name)
at
System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.CreateComponent(Type
componentType, String name)
at
System.ComponentModel.Design.Serialization.DesignerSerializationManager.CreateInstance(Type
type, ICollection arguments, String name, Boolean addToContainer)
at
System.ComponentModel.Design.Serialization.DesignerSerializationManager.System.ComponentModel.Design.Serialization.IDesignerSerializationManager.CreateInstance(Type
type, ICollection arguments, String name, Boolean addToContainer)
at
System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager
manager, CodeTypeDeclaration declaration)
at
System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager
manager)
at
Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager
serializationManager)
at
System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost
host)
 
S

Stephany Young

I can't really see where you're driving at with this.

You have written a class (BaseForm) with a typo in it that is liable to
cause a stack overflow and yet you are you appear to be claiming that VS2005
has a bug in it.

Firstly System.Windows.Forms is a namespace and therfore I can't really
accept that you are deriving a class from it.

Secondly, neither of the stack traces indicate a call to the Count property
of your BaseForm.

If the Count property in your BasForm were to be called I would expect an
explicit stack overflow to be encountered with a few milliseconds.

When it comes to classes derived from System.Windows.Forms.Form, you have to
remember that code in the inherited class(es) may run when you load the
derived class in the designer. You have to implement code in the base
class(es) to cater for for this.
 
S

scarleton

I guess I did not state things clearly. It first appeared to be a bug
in VS2005, but it turned out to be a recursive call in our code.

What I am driving at, or more accurately, why I made the posting is to
help out others that run into the same problem in their code. I am
hoping that someone else will search the news groups, find my posting
and say: Ah, let me look for a recursive call in my code!

It took two developers a day and a half to find this, I am hoping
others can benefit from what we learned.

As far as a explicit stack overflow, there isn't one. I believe the
reason is because VS2005 is using reflection to call into our code
right before it displays the designer and crashes not expecting a stack
overflow. I have a feeling this is not something Microsoft can help,
thus it is what it is.

Sam
 

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