Bug 11916 - System.Xml.Linq.XElement cannot be de/serialized
Summary: System.Xml.Linq.XElement cannot be de/serialized
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML (show other bugs)
Version: 2.10.x
Hardware: PC Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: marcos.henrich
URL:
Depends on:
Blocks:
 
Reported: 2013-04-23 14:35 UTC by Bryan Moulton
Modified: 2014-09-23 13:46 UTC (History)
5 users (show)

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


Attachments

Description Bryan Moulton 2013-04-23 14:35:30 UTC
The XmlSchemaProviderAttribute on System.Xml.Linq.XElement has the Method property set to null. This causes de/serialization to fail at System.Type.GetMethod. Sharepoint web services cannot be consumed due to this since they use XElement.

"Exception System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Argument cannot be null.\nParameter name: name\n 
at System.Type.GetMethod (System.String name, BindingFlags bindingAttr) [0x00006] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Type.cs:1064 \n 
at System.Runtime.Serialization.KnownTypeCollection.GetSerializableQName (System.Type type) [0x0000e] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:692 \n 
at System.Runtime.Serialization.KnownTypeCollection.RegisterIXmlSerializable (System.Type type) [0x00018] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:998 \n 
at System.Runtime.Serialization.KnownTypeCollection.DoTryRegister (System.Type type) [0x00054] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:768 \n 
at System.Runtime.Serialization.KnownTypeCollection.TryRegister (System.Type type) [0x0000c] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:743 \n 
at System.Runtime.Serialization.KnownTypeCollection.InsertItem (Int32 index, System.Type type) [0x00019] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:482 \n 
at System.Collections.ObjectModel.Collection`1[System.Type].Add (System.Type item) [0x0000c] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.ObjectModel/Collection.cs:79 \n 
at System.Runtime.Serialization.SerializationMap.CreateDataMemberInfo (System.Runtime.Serialization.DataMemberAttribute dma, System.Reflection.MemberInfo mi, System.Type memberType, System.String ownerNamespace) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/SerializationMap.cs:386 \n 
at System.Runtime.Serialization.SharedContractMap.GetMembers (System.Type type) [0x0010c] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/SerializationMap.cs:481 \n 
at System.Runtime.Serialization.SharedContractMap.Initialize () [0x00040] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/SerializationMap.cs:449 \n 
at System.Runtime.Serialization.KnownTypeCollection.RegisterContract (System.Type type) [0x0004f] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:1032 \n 
at System.Runtime.Serialization.KnownTypeCollection.DoTryRegister (System.Type type) [0x00046] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:765 \n 
at System.Runtime.Serialization.KnownTypeCollection.TryRegister (System.Type type) [0x0000c] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:743 \n 
at System.Runtime.Serialization.KnownTypeCollection.InsertItem (Int32 index, System.Type type) [0x00019] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:482 \n 
at System.Collections.ObjectModel.Collection`1[System.Type].Add (System.Type item) [0x0000c] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.ObjectModel/Collection.cs:79 \n 
at System.Runtime.Serialization.DataContractSerializer.RegisterTypeAsKnown (System.Type type) [0x00026] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/DataContractSerializer.cs:254 \n 
at System.Runtime.Serialization.DataContractSerializer.PopulateTypes (IEnumerable`1 knownTypes) [0x0007a] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/DataContractSerializer.cs:242 \n 
at System.Runtime.Serialization.DataContractSerializer..ctor (System.Type type, System.String rootName, System.String rootNamespace, IEnumerable`1 knownTypes) [0x00051] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/DataContractSerializer.cs:108 \n 
at System.ServiceModel.Dispatcher.DataContractMessagesFormatter.GetSerializer (System.ServiceModel.Description.MessagePartDescription partDesc) [0x00011] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseMessagesFormatter.cs:450 \n 
at System.ServiceModel.Dispatcher.DataContractMessagesFormatter.ReadMessagePart (System.ServiceModel.Description.MessagePartDescription part, System.Xml.XmlDictionaryReader r) [0x00037] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseMessagesFormatter.cs:438 \n 
at System.ServiceModel.Dispatcher.DataContractMessagesFormatter.MessageToParts (System.ServiceModel.Description.MessageDescription md, System.ServiceModel.Channels.Message message) [0x00116] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseMessagesFormatter.cs:420 \n 
at System.ServiceModel.Dispatcher.BaseMessagesFormatter.DeserializeReply (System.ServiceModel.Channels.Message message, System.Object[] parameters) [0x0004d] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseMessagesFormatter.cs:272 \n 
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply (System.ServiceModel.Channels.Message message, System.Object[] parameters) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseMessagesFormatter.cs:91 \n 
at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (System.ServiceModel.Description.OperationDescription od, System.Object[] parameters) [0x00256] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:564 \n 
at System.ServiceModel.MonoInternal.ClientRuntimeChannel.DoProcess (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters) [0x00038] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:496 \n 
at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Process (System.Reflection.MethodBase method, System.String operationName, System.Object[
Comment 1 Atsushi Eno 2013-04-23 16:48:41 UTC
I added a quick nullref check to go further than that exception in master [44f3d63].

However, the cause of the issue seems to be because mono doesn't support XmlSchemaProviderAttribute.IsAny property either in DataContractSerializer or XmlSerializer.

--------
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

//[XmlSchemaProvider("GetName")]
[XmlSchemaProvider(null, IsAny = true)]
public class Test : IXmlSerializable
{
    public static void Main()
    {
        var ds = new DataContractSerializer(typeof(Test));
        using (var xw = XmlWriter.Create(Console.Out))
            ds.WriteObject(xw, new Test());
	Console.WriteLine();
	new XmlSerializer(typeof(Test)).Serialize(Console.Out, new Test());
        Console.ReadLine();
    }

    static XmlQualifiedName GetName(XmlSchemaSet xs)
    {
        return new XmlQualifiedName("mytest");
    }

    void IXmlSerializable.WriteXml(XmlWriter writer)
    {
        writer.WriteElementString("dummy", "test");
    }

    void IXmlSerializable.ReadXml(XmlReader reader)
    {
        reader.ReadElementString("dummy");
    }

    XmlSchema IXmlSerializable.GetSchema()
    {
        return null;
    }
}

--------

mono output is like this. Note that those <Test> elements are unnecessary:

<?xml version="1.0" encoding="utf-8"?><Test xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/"><dummy>test</dummy></Test>
<?xml version="1.0" encoding="utf-8"?>
<Test>
  <dummy>test</dummy>
</Test>
Comment 2 Miguel de Icaza [MSFT] 2013-04-23 17:08:13 UTC
For completeness, this is the Windows output:

<?xml version="1.0" encoding="utf-8">
<dummy>test</dummy>
Comment 3 marcos.henrich 2014-08-18 05:58:57 UTC
The pull request for this issue can be found in the link below.
https://github.com/mono/mono/pull/1212
Comment 4 marcos.henrich 2014-08-18 06:54:18 UTC
Fixed in master 24005444c7c1c570db730f17b6d15dd66d3728b6.
Comment 5 Udham Singh 2014-09-23 13:46:42 UTC
I have checked this issue with builds XS 4.0.5.4-1 and Mono 2.10.11, and getting the same error mentioned in bug description with these builds. To reproduce this issue I have implemented the code provided in comment 1 in a console application, run the application and got the issue.

Exception log with builds XS 4.0.5.4-1 and Mono 2.10.11 :
https://gist.github.com/Udham1/2c73a0087de71629ffbf

I have also checked this issue with builds XS 5.5 (build 204) and Mono 3.10.0.16, and it is working fine with builds XS 5.5 (build 204) and Mono 3.10.0.16, I am getting the same output mentioned in comment 2, Hence closing this issue.

Screencast : http://screencast.com/t/RwJaBMstWQS

Environment Info :

=== Xamarin Studio ===

Version 5.5 (build 204)
Installation UUID: ce927b2a-2c07-44c5-b186-09cfdafba6dc
Runtime:
    Mono 3.10.0 ((detached/ac51002)
    GTK+ 2.24.23 (Raleigh theme)

    Package version: 310000016

=== Apple Developer Tools ===

Xcode 6.0.1 (6528)
Build 6A317

=== Xamarin.iOS ===

Version: 8.2.0.177 (Business Edition)
Hash: 3b73f2a
Branch: 
Build date: 2014-09-19 00:21:20-0400

=== Xamarin.Mac ===

Version: 1.11.0.1 (Business Edition)

=== Xamarin.Android ===

Version: 4.18.0.32 (Business Edition)
Android SDK: /Users/xamarin76/Desktop/android-sdk-macosx
    Supported Android versions:
        1.6    (API level 4)
        2.1    (API level 7)
        2.2    (API level 8)
        2.3    (API level 10)
        3.0    (API level 11)
        3.1    (API level 12)
        3.2    (API level 13)
        4.0    (API level 14)
        4.0.3  (API level 15)
        4.1    (API level 16)
        4.2    (API level 17)
        4.3    (API level 18)
        4.4    (API level 19)
        4.4.87 (API level 20)
        4.5    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Build Information ===

Release ID: 505000204
Git revision: 2affa3acc16487d4f8fb5cb33c49e2423469091e
Build date: 2014-09-23 07:14:56-04
Xamarin addins: c31fea2f959659225466adef1c0793a8d7eebcef

=== Operating System ===

Mac OS X 10.9.4
Darwin Xamarin76s-Mac-mini.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64

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