locked
LinqToXsd exception with EntityFramework XSD: same cause of xsd.exe error?

    Question

  • Hi!

    First of all I apologize to open a new thread about this topic!

    As I already wrote here http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3170303&SiteID=1, I'd like to use LinqToXsd to read and expecially write Entity Framework's .edmx files.

    When building the project in Visual Studio 2008 and LinqToXsd Alpha 0.2, I get this error:

     

    Error 1 System.InvalidOperationException: Collection was modified. Enumeration operation may be not execute. <my_projects_path>\linq2xsd_2\linq2xsd_2\LinqToXsd linq2xsd_2

     

    So, i tried using console application linqtoxsd.exe, giving in input singles .xsd schemas.

    I've got no error with these:

    • System.Data.Resources.CodeGenerationSchema.xsd
    • System.Data.Resources.CSMSL.xsd
    • System.Data.Resources.ProviderServices.ProviderManifest.xsd
    • System.Data.Resources.EntityStoreSchemaGenerator.xsd

    Errors occured giving in input these:

    • Microsoft.Data.Entity.Design.Edmx.xsd
    • System.Data.Resources.CSDLSchema.xsd
    • System.Data.Resources.SSDLSchema.xsd

    Getting this exception and stacktrace:

    C:\Programmi\LINQ to XSD Preview\Bin>linqtoxsd System.Data.Resources.SSDLSchema.
    xsd
    LinqToXsd: error TX0001:

    System.InvalidOperationException: Collection was modified. The enumeration operation may not be executed.
       in System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resour
    ce)
       in System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
       in Microsoft.Xml.Schema.Linq.CodeGen.ContentInfo.TransformToStar(Int32 start,
     Int32 currState, FSM fsm, Set`1 visited)
       in Microsoft.Xml.Schema.Linq.CodeGen.ContentInfo.TransformToStar(Int32 start,
     Int32 currState, FSM fsm, Set`1 visited)
       in Microsoft.Xml.Schema.Linq.CodeGen.ContentInfo.MakeStarFSM(FSM origFsm, Sta
    teNameSource stateNames)
       in Microsoft.Xml.Schema.Linq.CodeGen.ContentInfo.ImplementFSMCardinality(FSM
    origFsm, StateNameSource stateNames)
       in Microsoft.Xml.Schema.Linq.CodeGen.GroupingInfo.MakeFSM(StateNameSource sta
    teNames)
       in Microsoft.Xml.Schema.Linq.CodeGen.GroupingInfo.MakeSequenceFSM(StateNameSo
    urce stateNames)
       in Microsoft.Xml.Schema.Linq.CodeGen.GroupingInfo.MakeFSM(StateNameSource sta
    teNames)
       in Microsoft.Xml.Schema.Linq.CodeGen.ClrContentTypeInfo.CreateFSM(StateNameSo
    urce stateNames)
       in Microsoft.Xml.Schema.Linq.CodeGen.XTypedElementBuilder.ImplementFSMMetaDat
    a()
       in Microsoft.Xml.Schema.Linq.CodeGen.TypeBuilder.ImplementIXMetaData()
       in Microsoft.Xml.Schema.Linq.CodeGen.TypeBuilder.ImplementInterfaces(Boolean
    enableServiceReference)
       in Microsoft.Xml.Schema.Linq.CodeGen.CodeDomTypesGenerator.ProcessType(ClrCon
    tentTypeInfo typeInfo, String parentIdentifier, Boolean globalType)
       in Microsoft.Xml.Schema.Linq.CodeGen.CodeDomTypesGenerator.GenerateTypes(ClrM
    appingInfo binding)
       in XObjectsGenerator.XObjectsGenerator.GenerateXObjects(XmlSchemaSet set, Str
    ing csFileName, String configFileName, String assemblyName, Boolean xmlSerializa
    ble)
       in XObjectsGenerator.XObjectsGenerator.Main(String[] args)
     
    Since my application must be able to read (ok, no problem with LINQ! Wink ) and write .edmx file i tried to use xsd.exe console application.
    With that, I had some problems (with same files above) caused by schemaLocation attribute in schemas (used for dependency and importing external schema).
    I solved them using this command: xsd.exe <schema_to_generate> /C <dependency_schemas>.
     
    Now my questions:
    1. Could the linqtoxsd error be related to xsd.exe error on schemaLocation attribute ?
    2. Is the above linqtoxsd.exe error a bug?
    3. Is there any known solution allowing use of .edmx schemas with linqtoxsd ?
    I apologize for this very long thread and i thank you in advance for support!
     
    Bye!
    Monday, December 01, 2008 2:01 PM

Answers

  • Some days ago i wrote to few XML Mvps and to XMLTeam. Email was pretty similar to this post.

    This is the answer from Shyam Pather, XMLTeam:

     

    Hello,


    It's likely you've run into a bug in LINQ to XSD (the existing release is an early alpha preview and is therefore not at the quality of a shipping product). Unfortunately, we are not currently doing development on LINQ to XSD, so I don't have a solution for your immediate problem. But there may be alternatives for some of what you are doing.

     

    For reading the edmx information without parsing XML, consider using the Metadata APIs in the Entity Framework. Specifically, have a look at the EdmItemCollection class (http://msdn.microsoft.com/en-us/library/system.data.metadata.edm.edmitemcollection.aspx). You can create one of these from your edmx file, then use the various Get...() methods to get at the information loaded from the edmx file.

     

    In V1 we do not support programmatically creating edmx files through this API. For that, I recommend using LINQ to XML directly. That would be the most lightweight and easy-to-code way to generate the XML.

     

    Hope this helps.
    -shyam

     

    Thursday, December 11, 2008 1:12 PM

All replies

  • Some days ago i wrote to few XML Mvps and to XMLTeam. Email was pretty similar to this post.

    This is the answer from Shyam Pather, XMLTeam:

     

    Hello,


    It's likely you've run into a bug in LINQ to XSD (the existing release is an early alpha preview and is therefore not at the quality of a shipping product). Unfortunately, we are not currently doing development on LINQ to XSD, so I don't have a solution for your immediate problem. But there may be alternatives for some of what you are doing.

     

    For reading the edmx information without parsing XML, consider using the Metadata APIs in the Entity Framework. Specifically, have a look at the EdmItemCollection class (http://msdn.microsoft.com/en-us/library/system.data.metadata.edm.edmitemcollection.aspx). You can create one of these from your edmx file, then use the various Get...() methods to get at the information loaded from the edmx file.

     

    In V1 we do not support programmatically creating edmx files through this API. For that, I recommend using LINQ to XML directly. That would be the most lightweight and easy-to-code way to generate the XML.

     

    Hope this helps.
    -shyam

     

    Thursday, December 11, 2008 1:12 PM
  • Hi Matteo,

    if you are still interested, there's something new about Linq2XSD.
    About a month ago the MS XML Team announced it's source code to be published on CodePlex: http://linqtoxsd.codeplex.com/ .

    Here you can find the according blog entry:
    http://blogs.msdn.com/xmlteam/archive/2009/06/03/linq-to-xsd-now-available-on-codeplex.aspx

    Best regards, Daniel
    • Edited by DRothmaler Wednesday, July 22, 2009 6:41 AM
    Wednesday, July 22, 2009 6:37 AM