Linq To Xsd in Compact Framework 3.5

Oct 13, 2009 at 11:37 PM

Is it possible to use Linq To Xsd within applications targeting Compact Framework 3.5?

I tried:

- I use Sharpdevelop for cf development (Visual stidio std etc... is not an option);

- I compiled Linq to Xsd successfully targeting .net 3.5;

- merely switching target on a .net 3.5 app (working perfectly) to cf 3.5 brings this error:

The type 'System.Xml.Serialization.IXmlSerializable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. (CS0012) - C:\Documents and Settings\Parikkala\Documenti\SharpDevelop Projects\Paunet\Paunet\pauker.cs:29,22

but IXmlSerilizable should be supported under cf (downloaded ported and compiled a simple example).

- compiling XObjects targeting cf 3.5 brings a bunch of errors mainly because system.codedom (related to compiler service) is not supported within cf.

Thank you

Antonio Martino

May 17, 2010 at 11:55 AM
Edited May 17, 2010 at 11:56 AM

Hi Antonio,
I know it's been a while since you made your post, I'm writing this more as general knowledge to aid anyone using or developing Linq to XSD (L2Xsd) to get it working on the compact framework.

Firstly, from my investigations of trying to use the .NET 3.5 version of Linq To Xsd, it didn't appear [to me] to be currently compatible, that is to say it had compilation issues (as of Mid May 2010). Here's what I've found out so far about potential compact framework usage (VS 2008 Pro):

(Apologies if this seems like a 'Brain Dump')

  1. The "System.Xml.Serialization.IXmlSerializable' is defined in an assembly that is not referenced" error can be resolved by first removing the reference(s) to most of the 'System*' references AND 'mscorlib', and then using the Object Browser (right-click a reference) to re-add those references (write them down!), making sure to choose the ones that have '[compact framework]' after them. The Object browser view has a small add/plus icon just to the right of its 'Browse' drop-down and navigation arrows. Adding L2Xsd's 'Xml.Schema.Linq.dll' library reference (see <Linq to Xsd installation>/bin folder) might give you a warning (yellow triangle with exclamation). This is because, for some unknown reason, the [hint] path to the DLL not honoured. You'll need to select the Project itself (not the parent solution), right click and select 'unload project'. This will temporarily 'close' the project while still referring to it in the solution viewer. Once again, select and right-click the project, this time selecting the project's 'edit <yourProjName.csproj'. Here, find the <reference> xml node fragment which refers to 'Xml.Schema.Linq' and make its '<HintPath>' value absolute, meaning, add the drive letter/correct the path which corresponds to the actual location of the dll in question (this may mean removing the '../../' directory change references). When you've done that, select the project once again in the solution viewer, right-click, and reload the project. At this point, you might be greeted with 2 reference to the 'Xml.Schema.Linq*' library (one ending in 'dll'), remove the one with the warning symbol.
  2. A further reason I was unable to compile the Linq to Xsd generated classes was because of a reference to 'System.Diagnostics.DebuggerBrowsableAttribute', added extensively to the generated classes, appears not  to be available to the compact famework version of the 'System.Diagnostics' namespace (see the 'mscorlib' library references, using Object Viewer). Therefore having the Linq to Xsd toolset *not* include this particular attribute would probably be a good step towards being able to use Linq to Xsd within compact-framework-destined
    projects.
  3. (Having removed the DebugBrowsable attribute from the Linq-to-Xsd-generated classes), I then found a build error which didn't make sense, given that the artefacts in question ARE available to the code (according to Object Viewer and my library references). Basically, my final, unresolved problem was one where some of the Linq-to-Xsd-generated classes implemented interfaces/methods held within the 'Xml.Schema.Linq.dll' reference, specifically the  'Xml.Schema.Linq.ILinqToXsdTypeManager' and ' Xml.Schema.Linq.IXMetaData' interfaces. The error, '<SomeSuperInterfaceName.SomeImplementedMethodName> explicit interface declaration is not a member of interface', seemed to suggest that the methods being implemented in the Linq-to-Xsd-generated-class were NOT available within the original interface, when they appeared to be, after I checked the generated metadata class via Object Viewer (I didn't have the Linq-2-xsd source code). A fragment of the generated class, which corresponds to our in-house version of the cXML schema (they only publish a DTD) is provided below for illustration purposes.

I hope that some of the above might help someone to get L2Xsd working on the compact framework (I'll do further digging/patching if I get time).


Cheers


Richard Joseph


P.S. I may post some of this to the issue tracker later at sometime, in the hope that the developers might pick up on some of these issues.

 

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.3603
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Schema;
using Xml.Schema.Linq;



/// <summary>
/// <para>
/// Regular expression: (Segment+ | AccountingSegment+)
/// </para>
/// </summary>
public partial class Accounting : XTypedElement, IXMetaData {
    
    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
    private XTypedList<Segment> SegmentField;
    
    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
    private XTypedList<AccountingSegment> AccountingSegmentField;
    
    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
    static Dictionary<XName, System.Type> localElementDictionary = new Dictionary<XName, System.Type>();
    
    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
    private static ContentModelEntity contentModel;
    
         public static explicit operator Accounting(XElement xe) { return XTypedServices.ToXTypedElement<Accounting>(xe,LinqToXsdTypeManager.Instance as ILinqToXsdTypeManager); }
    
    static Accounting() {
        BuildElementDictionary();
        contentModel = new ChoiceContentModelEntity(new NamedContentModelEntity(XName.Get("Segment", "")), new NamedContentModelEntity(XName.Get("AccountingSegment", "")));
    }
    
    /// <summary>
    /// <para>
    /// Regular expression: (Segment+ | AccountingSegment+)
    /// </para>
    /// </summary>
    public Accounting() {
    }
    
    public Accounting(IEnumerable<Segment> Segment) {
        this.SegmentField = XTypedList<Segment>.Initialize(this, LinqToXsdTypeManager.Instance, Segment, XName.Get("Segment", ""));
    }
    
    public Accounting(IEnumerable<AccountingSegment> AccountingSegment) {
        this.AccountingSegmentField = XTypedList<AccountingSegment>.Initialize(this, LinqToXsdTypeManager.Instance, AccountingSegment, XName.Get("AccountingSegment", ""));
    }
    
    /// <summary>
    /// <para>
    /// Occurrence: required, repeating, choice
    /// </para>
    /// <para>
    /// Regular expression: (Segment+ | AccountingSegment+)
    /// </para>
    /// </summary>
    public IList<Segment> Segment {
        get {
            if ((this.SegmentField == null)) {
                this.SegmentField = new XTypedList<Segment>(this, LinqToXsdTypeManager.Instance, XName.Get("Segment", ""));
            }
            return this.SegmentField;
        }
        set {
            if ((value == null)) {
                this.SegmentField = null;
            }
            else {
                if ((this.SegmentField == null)) {
                    this.SegmentField = XTypedList<Segment>.Initialize(this, LinqToXsdTypeManager.Instance, value, XName.Get("Segment", ""));
                }
                else {
                    XTypedServices.SetList<Segment>(this.SegmentField, value);
                }
            }
        }
    }
    
    /// <summary>
    /// <para>
    /// Occurrence: required, repeating, choice
    /// </para>
    /// <para>
    /// Regular expression: (Segment+ | AccountingSegment+)
    /// </para>
    /// </summary>
    public IList<AccountingSegment> AccountingSegment {
        get {
            if ((this.AccountingSegmentField == null)) {
                this.AccountingSegmentField = new XTypedList<AccountingSegment>(this, LinqToXsdTypeManager.Instance, XName.Get("AccountingSegment", ""));
            }
            return this.AccountingSegmentField;
        }
        set {
            if ((value == null)) {
                this.AccountingSegmentField = null;
            }
            else {
                if ((this.AccountingSegmentField == null)) {
                    this.AccountingSegmentField = XTypedList<AccountingSegment>.Initialize(this, LinqToXsdTypeManager.Instance, value, XName.Get("AccountingSegment", ""));
                }
                else {
                    XTypedServices.SetList<AccountingSegment>(this.AccountingSegmentField, value);
                }
            }
        }
    }
    
    /// <summary>
    /// <para>
    /// Occurrence: required
    /// </para>
    /// </summary>
    public string name {
        get {
            XAttribute x = this.Attribute(XName.Get("name", ""));
            return XTypedServices.ParseValue<string>(x, XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).Datatype);
        }
        set {
            this.SetAttribute(XName.Get("name", ""), value, XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).Datatype);
        }
    }
    
    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
    Dictionary<XName, System.Type> IXMetaData.LocalElementsDictionary {
        get {
            return localElementDictionary;
        }
    }
    
    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
    XName IXMetaData.SchemaName {
        get {
            return XName.Get("Accounting", "");
        }
    }
    
    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
    SchemaOrigin IXMetaData.TypeOrigin {
        get {
            return SchemaOrigin.Element;
        }
    }
    
    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
    ILinqToXsdTypeManager IXMetaData.TypeManager {
        get {
            return LinqToXsdTypeManager.Instance;
        }
    }

 

Oct 19, 2010 at 1:29 PM

Hi,

I have LinqToXSD 1.1.0 working in Compact Framework 3.5.

Instructions (ish) are here

Regards,

J1M.