Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlSerializer Deserializing Property with same name as its enum type no longer works #16918

Closed
devobra opened this issue Sep 18, 2019 · 3 comments · Fixed by #16965
Closed

XmlSerializer Deserializing Property with same name as its enum type no longer works #16918

devobra opened this issue Sep 18, 2019 · 3 comments · Fixed by #16965

Comments

@devobra
Copy link

@devobra devobra commented Sep 18, 2019

Steps to Reproduce

Android

  1. Download attached project and launch debug for BugReproduction-Deserialize-Android
  2. Press the + floating action button to serialize/deserialize the test class that has 5 enum properties with the same name as the enum.
  3. A toast will inform you which of the 5 properties deserialized properly and which didn't.

iOS
Same as Android, just debug BugReproduction-Deserialize-iOS and press the Button

BugReproduction-Deserialize.zip

Current Behavior

Deserializing an Object Property which has the same name as the type of enum it contains has unpredictable results. It can succeed or fail depending on the specific number of fields in the Class and whether those fields have the same name as their type.

In addition, if the object being created has a Property that accepts objects, the XmlSerializer may set one of the XmlNodes it failed to read as the value of such a Property.

Expected Behavior

Deserializing an Object Property which has the same name as the type of enum it contains works like any other property.

On which platforms did you notice this

[X] Xamarin iOS
[X] Xamarin Android
[X] Xamarin Mac
[ ] .Net Console Project on Visual Studio for Mac

Version Used:

Mono Framework MDK
Runtime:
Mono 6.0.0.334 (2019-02/6256b82d62f) (64-bit)
Package version: 600000334

This specific problem with deserialization appears to be new. I do not know when it broke exactly but I believe it was working with Mono 5.14 Commit 000780c. It does not happen on a .Net console project that uses Mono, so it may be specific to the Mono version that is bundled with Xamarin.

Stacktrace

no stack trace.

The XmlSerializer fires the UnknownElement event for each Property that fails to deserialize.

Edit : updated to add that the bug also occurs on Xamarin Mac but not in a Dot Net console application that uses Mono.

@devobra devobra changed the title XmlmSerializer Deserializing Property with same name as its enum type no longer works XmlSerializer Deserializing Property with same name as its enum type no longer works Sep 18, 2019
@marek-safar marek-safar added this to the 2019-08 (6.6.xx) milestone Sep 19, 2019
@marek-safar

This comment has been minimized.

Copy link
Member

@marek-safar marek-safar commented Sep 19, 2019

@steveisok, please check if it's a regression

@devobra

This comment has been minimized.

Copy link
Author

@devobra devobra commented Sep 19, 2019

Just a hunch, but given that :

-the Serializer code doesn't seem to have changed in a long time
-the bug can cause objects to end up in the wrong field (an XmlNode ends up in one of the fields of the object being created)

The problem could be a bug with Reflection rather than with the Serializer itself.

@steveisok

This comment has been minimized.

Copy link
Contributor

@steveisok steveisok commented Sep 19, 2019

We think the bug was at least surfaced w/ this commit and are trying to figure out if it applies the mobile profile only.

https://github.com/mono/mono/pull/11194/files#diff-ae54d9565e735005686191de0f19ed50R431-R435

TBH @devlead, I wondered the same thing re: reflection.

akoeplinger added a commit that referenced this issue Sep 24, 2019
[This ](https://github.com/mono/mono/pull/11194/files#diff-ae54d9565e735005686191de0f19ed50R431-R435)change in `XmlTypeMapElementInfo.GetElement`  introduced the logic for handling the case of derived types deserialization. 
For some cases (like #16918) it breaks existing functionality because it returns wrong element for given element name after searching withing derived types collection.

![image](https://user-images.githubusercontent.com/3258267/65416085-bedc0500-ddff-11e9-941c-f24045c64121.png)

Unfortunately, what I can do here is just reverting the related changes.

Fixes #16918
akoeplinger added a commit that referenced this issue Sep 24, 2019
[This ](https://github.com/mono/mono/pull/11194/files#diff-ae54d9565e735005686191de0f19ed50R431-R435)change in `XmlTypeMapElementInfo.GetElement`  introduced the logic for handling the case of derived types deserialization. 
For some cases (like #16918) it breaks existing functionality because it returns wrong element for given element name after searching withing derived types collection.

![image](https://user-images.githubusercontent.com/3258267/65416085-bedc0500-ddff-11e9-941c-f24045c64121.png)

Unfortunately, what I can do here is just reverting the related changes.

Fixes #16918

Backport of #16965.

/cc @marek-safar @MaximLipnin
jonpryor added a commit to jonpryor/xamarin-android that referenced this issue Sep 24, 2019
Changes: mono/mono@bfbf823...6d40f13

Context: mono/mono#15646
Context: mono/mono#16689
Context: mono/mono#16759
Context: mono/mono#16824
Context: mono/mono#16918
Context: mono/mono#16974

Improve exception filtering within the debugger.
jonpryor added a commit to xamarin/xamarin-android that referenced this issue Sep 25, 2019
Changes: mono/mono@bfbf823...6d40f13

Context: mono/mono#15646
Context: mono/mono#16689
Context: mono/mono#16759
Context: mono/mono#16824
Context: mono/mono#16918
Context: mono/mono#16974

Improve exception filtering within the debugger.
jonpryor added a commit to xamarin/xamarin-android that referenced this issue Sep 27, 2019
Changes: mono/mono@bfbf823...6d40f13

Context: mono/mono#15646
Context: mono/mono#16689
Context: mono/mono#16759
Context: mono/mono#16824
Context: mono/mono#16918
Context: mono/mono#16974

Improve exception filtering within the debugger.
jonpryor added a commit to xamarin/xamarin-android that referenced this issue Dec 3, 2019
Changes: mono/api-snapshot@fc50bc4...45a61d9

        $ git diff --shortstat fc50bc4f...45a61d93
         22 files changed, 775 insertions(+), 474 deletions(-)

Changes: mono/cecil@a6c8f5e...a6a7f5c

        $ git diff --shortstat a6c8f5e1...a6a7f5c0
         55 files changed, 818 insertions(+), 530 deletions(-)

Changes: mono/corefx@1f87de3...49f1c45

        $ git diff --shortstat e4f7102b...49f1c453
         38 files changed, 1171 insertions(+), 419 deletions(-)

Changes: mono/linker@ebe2a1f...e8d054b

        $ git diff --shortstat ebe2a1f4...e8d054bf
         137 files changed, 5360 insertions(+), 1781 deletions(-)

Changes: mono/mono@8946e49...18920a8

        $ git diff --shortstat 8946e49a...18920a83
         1811 files changed, 47240 insertions(+), 48331 deletions(-)

Changes: xamarin/xamarin-android-api-compatibility@a61271e...50a3c52

        $ git diff --shortstat a61271e0...50a3c52d
         1 file changed, 2 insertions(+), 791 deletions(-)

Fixes: #3619

Context: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1005448
Context: https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/967582
Context: dotnet/coreclr#26370
Context: dotnet/coreclr#26479
Context: dotnet/corefx#40455
Context: dotnet/corefx#40578
Context: mono/mono#7377
Context: mono/mono#12421
Context: mono/mono#12586
Context: mono/mono#14080
Context: mono/mono#14725
Context: mono/mono#14772
Context: mono/mono#15261
Context: mono/mono#15262
Context: mono/mono#15263
Context: mono/mono#15307
Context: mono/mono#15308
Context: mono/mono#15310
Context: mono/mono#15646
Context: mono/mono#15687
Context: mono/mono#15805
Context: mono/mono#15992
Context: mono/mono#15994
Context: mono/mono#15999
Context: mono/mono#16032
Context: mono/mono#16034
Context: mono/mono#16046
Context: mono/mono#16192
Context: mono/mono#16308
Context: mono/mono#16310
Context: mono/mono#16369
Context: mono/mono#16380
Context: mono/mono#16381
Context: mono/mono#16395
Context: mono/mono#16411
Context: mono/mono#16415
Context: mono/mono#16486
Context: mono/mono#16570
Context: mono/mono#16605
Context: mono/mono#16616
Context: mono/mono#16689
Context: mono/mono#16701
Context: mono/mono#16712
Context: mono/mono#16742
Context: mono/mono#16759
Context: mono/mono#16803
Context: mono/mono#16808
Context: mono/mono#16824
Context: mono/mono#16876
Context: mono/mono#16879
Context: mono/mono#16918
Context: mono/mono#16943
Context: mono/mono#16950
Context: mono/mono#16974
Context: mono/mono#17004
Context: mono/mono#17017
Context: mono/mono#17038
Context: mono/mono#17040
Context: mono/mono#17083
Context: mono/mono#17084
Context: mono/mono#17133
Context: mono/mono#17139
Context: mono/mono#17151
Context: mono/mono#17180
Context: mono/mono#17278
Context: mono/mono#17549
Context: mono/mono#17569
Context: mono/mono#17665
Context: mono/mono#17687
Context: mono/mono#17737
Context: mono/mono#17790
Context: mono/mono#17924
Context: mono/mono#17931
Context: https://github.com/mono/mono/issues/26758
Context: https://github.com/mono/mono/issues/37913
Context: xamarin/xamarin-macios#7005
jonpryor added a commit to xamarin/xamarin-android that referenced this issue Dec 3, 2019
Changes: mono/api-snapshot@fc50bc4...45a61d9

        $ git diff --shortstat fc50bc4f...45a61d93
         22 files changed, 775 insertions(+), 474 deletions(-)

Changes: mono/cecil@a6c8f5e...a6a7f5c

        $ git diff --shortstat a6c8f5e1...a6a7f5c0
         55 files changed, 818 insertions(+), 530 deletions(-)

Changes: mono/corefx@1f87de3...49f1c45

        $ git diff --shortstat e4f7102b...49f1c453
         38 files changed, 1171 insertions(+), 419 deletions(-)

Changes: mono/linker@ebe2a1f...e8d054b

        $ git diff --shortstat ebe2a1f4...e8d054bf
         137 files changed, 5360 insertions(+), 1781 deletions(-)

Changes: mono/mono@8946e49...18920a8

        $ git diff --shortstat 8946e49a...18920a83
         1811 files changed, 47240 insertions(+), 48331 deletions(-)

Changes: xamarin/xamarin-android-api-compatibility@a61271e...50a3c52

        $ git diff --shortstat a61271e0...50a3c52d
         1 file changed, 2 insertions(+), 791 deletions(-)

Fixes: #3619

Context: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1005448
Context: https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/967582
Context: dotnet/coreclr#26370
Context: dotnet/coreclr#26479
Context: dotnet/corefx#40455
Context: dotnet/corefx#40578
Context: mono/mono#7377
Context: mono/mono#12421
Context: mono/mono#12586
Context: mono/mono#14080
Context: mono/mono#14725
Context: mono/mono#14772
Context: mono/mono#15261
Context: mono/mono#15262
Context: mono/mono#15263
Context: mono/mono#15307
Context: mono/mono#15308
Context: mono/mono#15310
Context: mono/mono#15646
Context: mono/mono#15687
Context: mono/mono#15805
Context: mono/mono#15992
Context: mono/mono#15994
Context: mono/mono#15999
Context: mono/mono#16032
Context: mono/mono#16034
Context: mono/mono#16046
Context: mono/mono#16192
Context: mono/mono#16308
Context: mono/mono#16310
Context: mono/mono#16369
Context: mono/mono#16380
Context: mono/mono#16381
Context: mono/mono#16395
Context: mono/mono#16411
Context: mono/mono#16415
Context: mono/mono#16486
Context: mono/mono#16570
Context: mono/mono#16605
Context: mono/mono#16616
Context: mono/mono#16689
Context: mono/mono#16701
Context: mono/mono#16712
Context: mono/mono#16742
Context: mono/mono#16759
Context: mono/mono#16803
Context: mono/mono#16808
Context: mono/mono#16824
Context: mono/mono#16876
Context: mono/mono#16879
Context: mono/mono#16918
Context: mono/mono#16943
Context: mono/mono#16950
Context: mono/mono#16974
Context: mono/mono#17004
Context: mono/mono#17017
Context: mono/mono#17038
Context: mono/mono#17040
Context: mono/mono#17083
Context: mono/mono#17084
Context: mono/mono#17133
Context: mono/mono#17139
Context: mono/mono#17151
Context: mono/mono#17180
Context: mono/mono#17278
Context: mono/mono#17549
Context: mono/mono#17569
Context: mono/mono#17665
Context: mono/mono#17687
Context: mono/mono#17737
Context: mono/mono#17790
Context: mono/mono#17924
Context: mono/mono#17931
Context: https://github.com/mono/mono/issues/26758
Context: https://github.com/mono/mono/issues/37913
Context: xamarin/xamarin-macios#7005
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.