all groups > dotnet windows forms designtime > january 2006 >
You're in the

dotnet windows forms designtime

group:

Why does the default Deserializer crash on array index expressions?


Why does the default Deserializer crash on array index expressions? Eric Pierce
1/5/2006 3:46:20 PM
dotnet windows forms designtime:

Greetings,

I have some windows forms controls that add their own code to the
InitializeComponents() method of the control or form that uses them. Until
now, this has gone pretty well as there are numerous examples out there for
doing this. My code inserts a method call at the end of the serialization
of the control that looks like this:

this.myNumericUpDown6.MyMethod(this.foo.bar);

This works fine. I'm doing my own code gen using a subclass of
CodeDomSerializer that I assign to my custom controls. The problem I'm
having arises when I generate expressions like this:

this.myNumericUpDown6.MyMethod(this.foo[1].bar);

The serialization works fine (or it wouldn't have generated the code) and
when I build it and run it works great. There's no problem with foo[1] not
being instantiated prior to the invocation of the MyMethod in
InializeComponents(). The problem occurrs when I go back design mode on the
form once this code is in place. The designer tries to deserialize it and
blows up. Instead of my form in the design view, I get an error message
with the red circle and white X that says "The designer cannot process the
code at line ..."

What do I have to do to make this kind of expression acceptable to the
designer? Right now I'm just using the default deserializer like all the
other examples. Do I have to do any custom code in the deserializer method
to handle indexers?

foo is an instance of a class that has an indexer. It's not a System.Array.

Thanks in advance for your help

- Eric

Re: Why does the default Deserializer crash on array index expressions? Eric Pierce
1/5/2006 4:03:27 PM

Also, I suppose I should mention that in both examples where I use foo.bar
and foo[1].bar, bar is a public field of an object class of my creation and
not a property or a base type (int, double, etc.).

Thanks again in advance for any help!

- Eric

[quoted text, click to view]

Re: Why does the default Deserializer crash on array index expressions? Dira
1/6/2006 12:43:27 AM
Hi Eric,

i have also experienced some strange behaviour from the deserializer.
It seems it doesn't distinsuish between certain syntactical
constructions.
The simplest solultion (to procede with the prorgam, not to understand
the reason) would be to use a method, not an indexer. The code is
generated "manually", so far i understand, so you can generate
this.myNumericUpDown6.MyMethod( this.foo_deserialize( 1).bar);
and implement
public your_type foo_deserialize( int ind){
return foo[ ind];
}
This will make the deserielizer happy, i suppose.

Regards,
DiRa

Eric Pierce schrieb:

[quoted text, click to view]
Re: Why does the default Deserializer crash on array index expressions? Eric Pierce
1/9/2006 3:19:30 PM
Hi DiRa.

I got it working using your suggestion.

Someday I'd like to know how to get the deserializer to understand the
foo[1].bar expression but I'm up and running now.

Thanks for your reply,

- Eric


[quoted text, click to view]

AddThis Social Bookmark Button