Skip to content

System.Xml.XmlSerializer cannot serialize System.Nullable<t> as attribute #1412

Closed
Woodpile37/runtime
#47

Description

@shmuelie
System.InvalidOperationException occurred
  HResult=-2146233079
  Message=Cannot serialize member 'ResX' of type System.Nullable`1[System.Double]. XmlAttribute/XmlText cannot be used to encode complex types.
  Source=System.Xml.XmlSerializer
  StackTrace:
       at System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping(MemberMapping accessor, FieldModel model, XmlAttributes a, String ns, Type choiceIdentifierType, Boolean rpc, Boolean openModel, RecursionLimiter limiter)
  InnerException: 

Activity

  1. joshfree commented on May 3, 2016

    @joshfree
    Member
  2. khdang commented on May 3, 2016

    @khdang
    Member

    @SamuelEnglard can you provide an example to reproduce this issue?

  3. shmuelie commented on May 3, 2016

    @shmuelie
    ContributorAuthor
    using System;
    
    namespace SerializeNull
    {
        public class Program
        {
            public class TestSerialize
            {
                [System.Xml.Serialization.XmlAttribute]
                public double? Attr
                {
                    get;
                    set;
                }
            }
    
            public static void Main(string[] args)
            {
                System.Xml.Serialization.XmlSerializer s = new System.Xml.Serialization.XmlSerializer(typeof(TestSerialize));
                using (System.IO.MemoryStream m = new System.IO.MemoryStream())
                {
                    s.Serialize(m, new TestSerialize() { Attr = 1 });
                    m.Seek(0, System.IO.SeekOrigin.Begin);
                    Console.WriteLine((new System.IO.StreamReader(m)).ReadToEnd());
                }
                Console.ReadLine();
            }
        }
    }

    This should do it

  4. SGuyGe commented on May 5, 2016

    @SGuyGe
    Contributor

    Does this also happen on desktop .NET?

  5. shmuelie commented on May 6, 2016

    @shmuelie
    ContributorAuthor

    @SGuyGe Can reproduce in Desktop .NET 2.0 through 4.6.2

  6. assigned and unassigned on Jun 3, 2016
  7. karelz commented on Nov 4, 2016

    @karelz
    Member

    Someone needs to debug it and find out which code to change.

  8. self-assigned this
    on Jul 19, 2018
  9. huanwu commented on Aug 16, 2018

    @huanwu
    Contributor

    The fix is more complex than expected. Move to future. Refer dotnet/corefx#30536.

  10. removed their assignment
    on Aug 22, 2018
  11. added this to the Future milestone on Jan 7, 2020
  12. added
    enhancementProduct code improvement that does NOT require public API changes/additions
    help wanted[up-for-grabs] Good issue for external contributors
    and removed
    untriagedNew issue has not been triaged by the area owner
    on Jan 7, 2020
  13. added and removed
    untriagedNew issue has not been triaged by the area owner
    help wanted[up-for-grabs] Good issue for external contributors
    enhancementProduct code improvement that does NOT require public API changes/additions
    on Feb 28, 2020
  14. StephenBonikowsky commented on Feb 28, 2020

    @StephenBonikowsky
    Contributor

    Due to the complexity of the fix and that it also exists in the full framework and that it is also a corner case will not fix.

  15. ghost locked as resolved and limited conversation to collaborators on Dec 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions