deserializing and XML file [.csdl file EntityFramework]

V

VRSki

I am trying to deserialize a .csdl file, generated by EdmGen.exe (part of MS
Entity Framework). The file itself is an xml file, even though it has a .csdl
extension. But unfortunately, the second line contains an element that
doesn't seem to be supported by XML serializer:

------- XML start --------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<Schema Namespace="SomeProject" Alias="Self"
xmlns="http://schemas.microsoft.com/ado/2006/04/edm">
<Element1>data</Element1>
</Schema>
------- XML end --------------------------------------------------------

Here is the code I use to deserialize this fileL:

// read in the file into the stream
System.IO.Stream oCsdlXml = ....

// create the serializer -- Schema class contains Element1 member
XmlSerializer oSerializer = new XmlSerializer(typeof(Schema));

// this line below throws exception:
Schema oSchema = oSerializer.Deserialize(oCsdlXml) as Schema;

Exception: "There is an error in XML document (2, 2)"
Internal Exception: "<Schema
xmlns='http://schemas.microsoft.com/ado/2006/04/edm'> was not expected."

If I take out this part from the xml file -- it all works and my Element1 is
properly deserialized:

xmlns="http://schemas.microsoft.com/ado/2006/04/edm"


Is that a truly invalid XML construct? Is there any way to deserialize this
using attribute overrides?

Thank you for your help,
VR
 
N

not_a_commie

The data type that you are trying to serialize into -- it has a
different namespace declared for the 'Schema' element than what is
declared in your XML itself.
 
V

VRSki

Could you please help me out here? I am not sure what you mean by "it has a
different namespace declared for the 'Schema'"..

The element I am trying to serialize the stream to IS Schema:

XmlSerializer oSerializer = new XmlSerializer(typeof(Schema));

And Schema is a pretty straight-forward class:

namespace SomeNamespace
{
[Serializable]
public class Schema
{
public Schema() {}
public string Element1() {get;set;}
}
}

What namespace should I change in Schema class to make it work? Are you
saying namespace SomeNamespace should be renamed?

Thanks again for your help.
VR
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top