472,780 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

possible bug "<undefined value>" debugging a custom editor

Hi everyone,

(I already posted this to the VS.NET IDE news group without any responses, so I'm attempting one more time in this group)

The issue I'm having is occuring in the IDE of VS.NET 2003, although I'm not sure what is actually causing the problem. I can't
summarize the issue, so please read on to find out more.

I've created a BaseDialogEditor class that allows a developer (namely me) to create Modal editors for controls at design time
without having to rewrite the same "EditValue" logic and "Form" logic again. The class derives directly from UITypeEditor.

The BaseDialogEditor has an abstract property called "BaseDialogType" that defines the Type of Form that will be displayed. The
form must derive from BaseDialogEditorForm, which is also abstract. The base form has an OK and Cancel button, complimentary
events, and the Form properties set up appropriately so the Form will appear as a Modal Dialog. (Derived implementations may change
this when necessary)

Here is a snippet from the EditValue override of the BaseDialogEditor class (I've added comments to guide you through the steps):

// type is a local variable, assigned to the abstract "Type" property, which returns a Type instance.
// I've already insured that type is a BaseDialogEditorForm, using reflection, before this code is reached.
gui = Activator.CreateInstance(type) as BaseDialogEditorForm;
catch (Exception ex)
throw new SynthesoftException("Cannot create instance of DialogFormType Type. There may be no default constructor.",
"BaseDialogEditor.EditValue", ex);


// This allows derived BaseDialogEditor classes to modify "value" before it's passed to the form
OnBeforeEdit(context, provider, value);

// The BaseDialogEditorForm has a virtual method called, "Initialize" where it can store the information it needs to display:
gui.Initialize(context, provider, value);

Here is the entire "BaseDialogEditorForm.Initialize" code block:

public virtual void Initialize(System.ComponentModel.ITypeDescriptorCo ntext context, IServiceProvider provider, object component)
// Assign the local variables to the parameters passed in by the BaseDialogEditor class.
// Each variable has a public property that allows derived implementations to access them at runtime.
this.component = component;
this.provider = provider;
this.context = context;
I've created an editor deriving from BaseDialogEditor and a Form deriving from BaseDialogEditorForm and setup everything
I'm able to successfully use the editor at design time, and it works as expected, except for one important thing; Derived classes
cannot access the three local variables mentioned above.

To see why I was getting an InvalidCastException thrown when accessing the variables, I ran a new instance of VS.NET and attached to
it using the first instance of VS.NET (both 2003).

In the debugger, I set a break point on:

this.component = component;

When I clicked the elipses on my property in the VS.NET PropertyGrid, the debugger stopped at that line, as I expected.
The Type of component that appeared in the tooltip and Watch windows was correct. It was the Type that I was trying to edit.

I stepped to the next line:

this.provider = provider;

I moused over "this.component" to ensure that the variable took the parameter's value, but to my suprise it was "<undefined value>"
I've never seen this happen before.

I opened the command window in immediate mode:

<undefined value>
this.component == null
error: 'this.component.GetType' does not exist
(object) this.component
<undefined value>

Can anyone explain how a variable is not "null", yet cannot be cast to System.Object?

To make things even stranger, I queried the public property that has "this.component" as a backing field:

<error: an exception of type: {System.ArgumentException} occurred>

The public property is called "Value". It has one line of code in the get accessor:

return component;

So, where is the ArgumentException coming from?

Furthermore, as soon as I entered "Value" into the immediate window, I saw the watch on "this.component" change from "<undefined
to the appropriate Type with a "+" sign to drop it down. It seems that querying the "Value" property forced the "component" field
to show it's real value. How is that possible?

Now, in the immediate window and watch window everything seemed fine. The same was true for the other two variables I mentioned
above in the "Initialize" method as long as I queried their public properties first.

Obviously, this won't do since I can't attach a debugger everytime I need the editor to work correctly!

The first attempt to use my editing framework worked without a problem since I didn't have a need to query those variables. The
issue went unnoticed until I actually needed those values in a different property editor and got InvalidCastException when
attempting to cast the public properties of those variables at runtime to the Type I expected to be returned.

As for assembly references, both instances of VS.NET (the debugger and the testing instance) reference the exact same assembly that
contains the code mentioned above. The assembly built successfully before starting the project in debug mode.

Can anyone shed a little light on the issue at hand?

Thanks in advance,

Dave Sexton
Jul 22 '05 #1
0 1794

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Eric A. Forgy | last post by:
Hello, I am just learning Java and am trying to write a method that does something like //=========================================== public Static List find(double array,double val,String...
by: H. S. | last post by:
Hi, I am trying to compile these set of C++ files and trying out class inheritence and function pointers. Can anybody shed some light why my compiler is not compiling them and where I am going...
by: ahaque38 | last post by:
Hello. Using A2K SP3, I am having the following problem with a report using "Sorting and Grouping". I have recently added a grouping in the reports for "Category2<>'CONTRACTS'". I have...
by: Tom | last post by:
Hi I have an aspx page which has javascript to configure xmldata. I added breakpoint to the button method. When I click submit button, it did not go to those breakpoint and show the following...
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or < tag. Since I have sub xml data in a parent xml node...
by: Dave | last post by:
Hi everyone, (I already posted this to the VS.NET IDE news group without any responses, so I'm attempting one more time in this group) The issue I'm having is occuring in the IDE of VS.NET...
by: mkaushik | last post by:
Hi everyone, Im just starting out with C++, and am curious to know how "delete <pointer>", knows about the number of memory locations to free. I read somewhere that delete frees up space...
by: Jason | last post by:
Hello, I am trying to dynamically create a table, then set its <td>'s onclick: var table = document.createElement("table"); var row = table.insertRow(-1); var td = row.insertCell(-1);...
by: ismailc | last post by:
Hi, I need help please. Update system to to new version & moved on to .Net2 But now my code that worked in my .Net1 xslt does not work. .Net1 fine: <xsl:stylesheet...
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: lllomh | last post by:
How does React native implement an English player?
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.