Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
GitHub or Developer Community with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
I have a xml schema file which uses a "choice".
I used xsd to generate a class file for that schema.
When i now try to deserialize a XML file based on that schema into a class instance i get the following error message
Unhandled Exception: System.InvalidOperationException: There is an error in XML document. ---> System.InvalidOperationException: Read by order only possible for encoded/bare format
at System.Xml.Serialization.ClassMap.GetElement (Int32 index) [0x00000] in <filename unknown>:0
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadMembers (System.Xml.Serialization.ClassMap map, System.Object ob, Boolean isValueList, Boolean readBySoapOrder) [0x00000] in <filename unknown>:0
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadClassInstanceMembers (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob) [0x00000] in <filename unknown>:0
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadClassInstance (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, Boolean checkType) [0x00000] in <filename unknown>:0
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadObject (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, Boolean checkType) [0x00000] in <filename unknown>:0
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadRoot (System.Xml.Serialization.XmlTypeMapping rootMap) [0x00000] in <filename unknown>:0
at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadRoot () [0x00000] in <filename unknown>:0
at System.Xml.Serialization.XmlSerializer.Deserialize (System.Xml.Serialization.XmlSerializationReader reader) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
The code itself works: It works with microsoft .net and works also pretty well with with mono 2.6.7 ... but it seems that all mono version after 2.6.7 (2.8, 2.10) are no longer able to process the "choice" ?
Would you mind providing a self-contained test case that exhibits the problem?
Please reopen the bug with the test case.
Created attachment 1223 [details]
example for the choice issue
The attached files contains two important files:
test2.xsd, which is the used schema (very simple)
and test2.cs, which is the generated class file from the xsd. This file has been generated using
xsd test2.xsd /c /order
Important: The issue with mono only occurs, if the option "/order" was used - if this option is not used, the test program run's without problems, too.
requested information was attached
I wanted to use to DotCMIS library for a multiplatform application, but it uses <xsd:choice> so Mono crashes.
I also confirm Josef's test case reproduces the bug.
Mono JIT compiler version 188.8.131.52 (Debian 184.108.40.206-1ubuntu2.2)
It has been 7 months, any idea when this bug will be fixed?
I tried to fix that bug by commenting out the assertion at line 410 of System.Xml.Serialization/XmlTypeMapping.cs
That prevents the exception from happening, but unfortunately the resulting deserialized data is null.
So the problem must be somewhere else.
@Raoul: If you don't need the latest additions to XmlSerialization, you can work around this issue like this:
Fetch the mono sources of the version you want (e.g. 2.10.9) - and the sources of mono-2.6.7 (which is IMHO the last working version without that defect!). Extract both source trees - then replace all files in mcs/class/System.XML/System.Xml.Serialization with the files from 2.6.7 ... configure and compile.
It is a stupid and dangerous workaround - but it seems to work for me.
@Josef: Thanks for the tip! Unfortunately, I am developing a Mono app intended to be downloaded by many users, and I can't ask them to mess with their system.
I am now using a workaround: I removed all "Order" parameters/lines in the code generated by Visual C# (actually by the WSDL "Add Service" feature, which probably uses xsd.exe). It seems to be working so far.
I tested more, and I get this error:
There is an error in XML document.
So I guess I can't do without Order :-/
Which means I desperately need to fix this bug.
I can confirm that Josef's hack works.
For anyone willing to use Mono for XML or web services, here is how to fix the problem on Ubuntu:
sudo apt-get install devscripts fakeroot
sudo apt-get build-dep mono-runtime
export DEB_BUILD_OPTIONS="debug nostrip noopt"
fakeroot apt-get source -b mono-runtime
rm -rf mono-220.127.116.11/mcs/class/System.XML/System.Xml.Serialization
git clone git://github.com/mono/mono.git
git checkout mono-2-6-7
cp -r ../mono-2-6-7/mcs/class/System.XML/System.Xml.Serialization mono-18.104.22.168/mcs/class/System.XML/
dpkg-buildpackage -rfakeroot -uc -b
sudo dpkg -i --force-overwrite *.deb
Created attachment 2828 [details]
Fixes deserialization of choice with ordered read.
I have added the patch that fixed ordered deserialization of array of choices.
Should work for single choices too.
Sorry, patch also makes line endings consistent (LF) and formats some lines (MSVS-style).
I am not sure it won't break something since the code was not pretty and some things remained unclear. Developers definitely should add some xml-documentation...
I created a pull request from Roman's patch:
I cancelled the formatting changes to make the diff easier to understand:
Lluis, can you review the provided patch on github?
Nicolas/Roman: any chance you guys can provide a test case that we can use to validate the fix?
Comment #2 contains a test case
Miguel, I will write a test case within 3 days, based on the test case in comment 2.
Note: I have not tested the patch yet.
I wrote a test in "mono/tests" and sent a pull request:
I tried to follow the guidelines and patterns observed in other tests.
That might a problem with my setup, but recently I get "mdoc: There is an error in XML document" messages, and a person called Jester explained how it might be due to the patch:
Yep. My mistake. Since all memers in my program are marked with Order, i've never run into it.
I fixed my patch branch, now MDOC and everything build fine.
Pull request: https://github.com/mono/mono/pull/495/commits
Thanks, patch applied!
Created attachment 3080 [details]
Fix for failed tests
I addded one more patch to fix failed tests reported here https://github.com/mono/mono/pull/495 by garuma.
Patch must be applied after the previous one.
Created pull request https://github.com/mono/mono/pull/522