Bug 4053 - XamlObjectWriter calls EndInit() on child before setting property to parent
Summary: XamlObjectWriter calls EndInit() on child before setting property to parent
Status: NEEDINFO
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML (show other bugs)
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-03-23 00:35 UTC by Curtis Wensley
Modified: 2012-05-17 13:58 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Reproduces the issue (5.45 KB, application/zip)
2012-05-14 12:25 UTC, Curtis Wensley
Details

Description Curtis Wensley 2012-03-23 00:35:14 UTC
A follow up to bug #3003, the XamlObjectWriter calls EndInit() on child objects before setting the child to a parent property, instead of after.  It does seem to call EndInit() after adding a child to a parent collection properly, just not when setting a parent property.

Attached is a sample, which produces this output in MS.NET:

Parent Constructed
ISupportInitialize.BeginInit: Parent
XamlObjectWriterSettings.AfterBeginInit: Parent
XamlObjectWriterSettings.BeforeProperties: Parent
XamlObjectWriterSettings.XamlSetValue: Parent Title, Member: Title
Parent.Title_set: Parent
Child Constructed
ISupportInitialize.BeginInit: Child
XamlObjectWriterSettings.AfterBeginInit: Child
XamlObjectWriterSettings.BeforeProperties: Child
XamlObjectWriterSettings.XamlSetValue: child 3, Member: AssociatedProperty
Parent.SetAssociatedProperty: child 3
XamlObjectWriterSettings.XamlSetValue: Child Title 3, Member: Title
Child.Title_set: Child
XamlObjectWriterSettings.AfterProperties: Child
XamlObjectWriterSettings.XamlSetValue: Child, Member: SingularChild
Parent.SingularChild_set: Child
ISupportInitialize.EndInit: Child
XamlObjectWriterSettings.AfterEndInit: Child
XamlObjectWriterSettings.AfterProperties: Parent
ISupportInitialize.EndInit: Parent
XamlObjectWriterSettings.AfterEndInit: Parent
Loaded Parent

In Mono 2.11, it produces this output:

Parent Constructed
ISupportInitialize.BeginInit: Parent
XamlObjectWriterSettings.AfterBeginInit: Parent
XamlObjectWriterSettings.BeforeProperties: Parent
XamlObjectWriterSettings.XamlSetValue: Parent Title, Member: Title
Parent.Title_set: Parent
Child Constructed
ISupportInitialize.BeginInit: Child
XamlObjectWriterSettings.AfterBeginInit: Child
XamlObjectWriterSettings.BeforeProperties: Child
XamlObjectWriterSettings.XamlSetValue: child 3, Member: AssociatedProperty
Parent.SetAssociatedProperty: child 3
XamlObjectWriterSettings.XamlSetValue: Child Title 3, Member: Title
Child.Title_set: Child
XamlObjectWriterSettings.AfterProperties: Child
ISupportInitialize.EndInit: Child
XamlObjectWriterSettings.AfterEndInit: Child
XamlObjectWriterSettings.XamlSetValue: Child, Member: SingularChild
Parent.SingularChild_set: Child
XamlObjectWriterSettings.AfterProperties: Parent
ISupportInitialize.EndInit: Parent
XamlObjectWriterSettings.AfterEndInit: Parent
Loaded Parent

Note that in Mono, the line:

Parent.SingularChild_set: Child

happens after:

ISupportInitialize.EndInit: Child
XamlObjectWriterSettings.AfterEndInit: Child

whereas in MS.NET, it is the other way around.
Comment 1 Atsushi Eno 2012-05-14 04:53:02 UTC
Sorry, I noticed this so late now. Could you provide the repro case?

So far I tried the repro at #3003, which worked as identical as .NET.
Comment 2 Curtis Wensley 2012-05-14 12:25:23 UTC
Created attachment 1881 [details]
Reproduces the issue

Ah, forgot to attach the repro for this one.

The last test I did for #3003 didn't test setting singular children properties.

Thanks!
Comment 3 Atsushi Eno 2012-05-17 05:36:02 UTC
I examined the code and the repro many times, but the only conclusion I can say is, this is a bug in .NET Framework. There is no reason Child's EndInit() can be invoked *after* the Parent.set_Child() is invoked. How come could this call to the setter be predictable? I have no answer to this question.
Comment 4 Curtis Wensley 2012-05-17 13:58:48 UTC
Hm, well I do have code that depends on this behaviour.  For example, the parent calls a method in the child when it is set to the parent property..  I need the EndInit of the child to be called after that (it depends on values passed from the parent).  I could change my code to do this differently (e.g. chain the parent's endinit to each of the children), but that is not ideal.

If you think about how the Child EndInit() works with collections (it is called AFTER adding to the parent collection), having it the MS.NET way in this case makes sense and is consistent.

Note You need to log in before you can comment on or make changes to this bug.