Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / January 2006

Tip: Looking for answers? Try searching our database.

Why does the default Deserializer crash on array index expressions?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eric Pierce - 05 Jan 2006 20:46 GMT
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
Eric Pierce - 05 Jan 2006 21:03 GMT
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

> Greetings,
>
[quoted text clipped - 32 lines]
>
> - Eric
Dira - 06 Jan 2006 08:43 GMT
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:

> 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
[quoted text clipped - 40 lines]
> >
> > - Eric
Eric Pierce - 09 Jan 2006 20:19 GMT
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

> Hi Eric,
>
[quoted text clipped - 66 lines]
>> >
>> > - Eric

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.