473,414 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 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):

try
{
// 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);
}

try
{
context.OnComponentChanging();

// 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
appropriately.
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:

this.component
<undefined value>
this.component == null
false
this.component.GetType()
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:

Value
<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
value>"
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
dave@www..jwaonline..com
-----------------------------------------------------------------------
Jul 22 '05 #1
0 1832

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

Similar topics

5
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...
3
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...
3
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...
8
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...
2
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...
0
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...
5
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...
5
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);...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.