mamift / LinqToXsdCore

LinqToXsd ported to .NET Core (targets .NET Standard 2 for generated code and .NET Core 3.1, .NET 5+ for the code generator CLI tool).
Microsoft Public License
41 stars 15 forks source link

Null Reference Exception with ILinqToXsdTypeManager #35

Open lucky85008 opened 2 years ago

lucky85008 commented 2 years ago

Thanks for updating LINQToXsdCore. We used it to generate the C# file. In my scenario, we have to create WCF Service Contract based on C# generated code (Because client requirement and they not converted to .Net Core). And I am getting error deep in ILinqToXsdTypeManager when I calling the service from WCF Client Code.

I am working with a large set of XSDs (40-50 XSDs, as which sent by chiefengineer) and XML message is created based on these XSDs. C# file is generated from the XSDs (LINQToXsdCore tool)

I coped this C# file and add it in .Net 4.8 Project and create the dll. Most of the unit tests are passing. I used this DLL and create WCF Service. DLL is used to create the OperationContract and custom arguments get passed (not an integer or string, it is custom classes) In unit test (same solution, not with WCF Client ) , I read the valid XML ,XmlSerializer , Deserialize and pass it to OperationContract as arguments and Objects are fills with data from XML. All is well.

Now I run the WCF service in visual studio and call it from another Visual studio as a WCF client (same way as unit test). I am not referencing the service in project but creating the CustomChannelFactory and passing the config of the service. WCF Service is getting called and I can see it in the debugger and it hit OperationContract . But Objects are NOT getting fill the xml data , as it is done in the unit test. I can see the raw XML coming through as content but objects are not getting filled. Those objects are getting Null Reference Exception. Untyped and Content have the XML which I sent. See blow.

Everything looks good , service OperationContract getting called but data is not getting filled, Hope I explained well :) , and I am sure you see this error a thousand times. object are not getting filled but in Unit test , they are. Untyped and Content have the XML.

i am not sure what I am missing and how to debug it. WCF logs are not helpful. Please let me know if you need more info.

From Unit Test image

From Client: image

Error :

" at Xml.Schema.Linq.XTypedServices.GetAnnotation(Type t, XElement xe)\r\n at Xml.Schema.Linq.XTypedServices.ToXTypedElement(XElement xe, ILinqToXsdTypeManager typeManager, Type rootType, Type contentType)\r\n at Xml.Schema.Linq.XTypedServices.ToXTypedElement[W,T](XElement xe, ILinqToXsdTypeManager typeManager)\r\n at aoc.efiling.ecf.extension.CoreFilingMessage.opExplicit(XElement xe) in C:\**\AOC.eFiling.ecf.exchange.2.2.xsd.cs:line 211906\r\n at aoc.efiling.ecf.exchange.ReviewFiling.ReviewFilingRequestType.get_CoreFilingMessage() in C:****\AOC.eFiling.ecf.exchange.2.2.xsd.cs:line 837459\r\n at aoc.efiling.ecf.exchange.ReviewFiling.ReviewFilingRequest.get_CoreFilingMessage() in C:***\AOC.eFiling.ecf.exchange.2.2.xsd.cs:line 838025"

at Xml.Schema.Linq.XTypedServices.GetAnnotation(Type t, XElement xe) at Xml.Schema.Linq.XTypedServices.ToXTypedElement(XElement xe, ILinqToXsdTypeManager typeManager, Type rootType, Type contentType) at Xml.Schema.Linq.XTypedServices.ToXTypedElement[W,T](XElement xe, ILinqToXsdTypeManager typeManager) at oasis.legalxml.courtfiling.MessageReceiptMessage.MessageReceiptMessage.op_Explicit(XElement xe)

mamift commented 2 years ago

Hello,

I just wanted to acknowledge receipt of your issue; this is an interesting error. I myself have not used and also not seen, thus far, anyone use LinqToXsdCore for de/serialisation with WCF; I thought WCF came with it's own XML serialisation/deserialisation libraries?

One thing that comes to mind is that there is an explicit conversion operator generated by the LinqToXsd tool; are you able to check if it is being called? Look for static explicit operator in generated code.

lucky85008 commented 2 years ago

Hi Mamift,

Thanks for replying it. Yes, WCF does have its own XML serialisation/deserialisation. It is defined on OperationContract as [XmlSerializerFormat(Style = OperationFormatStyle.Document, Use = OperationFormatUse.Literal)]

Yes , static explicit operator is there in following class.

public static explicit operator CoreFilingMessage(XElement xe) { return XTypedServices.ToXTypedElement<CoreFilingMessage, aoc.efiling.ecf.extension.CoreFilingMessageType>(xe, LinqToXsdTypeManager.Instance as ILinqToXsdTypeManager); }

=================================== ///

/// /// The structure of a Filing including any Payment Information will be documented in this section. This describes the filing transaction between the Filing Assembly MDE and the Filing Review MDE. This information will become part of the Record Docketing between the Filing Review MDE and the Court Record MDE but does not necessarily describe the information that is actually stored in the Court Record. /// /// [XmlSchemaProviderAttribute("CoreFilingMessageSchemaProvider")] public partial class CoreFilingMessage: global::oasis.legalxml.courtfiling.CoreFilingMessage.CoreFilingMessage, IXMetaData, IXmlSerializable {

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private aoc.efiling.ecf.extension.CoreFilingMessageType ContentField;

private static readonly System.Xml.Linq.XName xName = System.Xml.Linq.XName.Get("CoreFilingMessage", "http://schema.azcourts.az.gov/aoc/efiling/ecf/extension/2.2");

**public static explicit operator CoreFilingMessage(XElement xe) { return XTypedServices.ToXTypedElement<CoreFilingMessage, aoc.efiling.ecf.extension.CoreFilingMessageType>(xe, LinqToXsdTypeManager.Instance as ILinqToXsdTypeManager); }**

/// <summary>
/// <para>
/// The structure of a Filing including any Payment Information will be documented in this section. This describes the filing transaction between the Filing Assembly MDE and the Filing Review MDE. This information will become part of the Record Docketing between the Filing Review MDE and the Court Record MDE but does not necessarily describe the information that is actually stored in the Court Record.
/// </para>
/// </summary>
public CoreFilingMessage() :
        base(true)
{
  SetInnerType(new aoc.efiling.ecf.extension.CoreFilingMessageType());
}

/// <summary>
/// <para>
/// The structure of a Filing including any Payment Information will be documented in this section. This describes the filing transaction between the Filing Assembly MDE and the Filing Review MDE. This information will become part of the Record Docketing between the Filing Review MDE and the Court Record MDE but does not necessarily describe the information that is actually stored in the Court Record.
/// </para>
/// </summary>
public CoreFilingMessage(aoc.efiling.ecf.extension.CoreFilingMessageType content) :
        base(true)
{
  SetInnerType(content);
}

public override XElement Untyped
{
  get
  {
    return base.Untyped;
  }
  set
  {
    base.Untyped = value;
    this.ContentField.Untyped = value;
  }
}

public new virtual aoc.efiling.ecf.extension.CoreFilingMessageType Content
{
  get
  {
    return ContentField;
  }
}

/// <summary>
/// <para>
/// Occurrence: optional
/// </para>
/// <para>
/// Regular expression: (DocumentApplicationName?, DocumentBinary?, DocumentCategoryText*, DocumentDescriptionText?, DocumentEffectiveDate?, DocumentFileControlID?, DocumentFiledDate?, DocumentIdentification*, DocumentInformationCutOffDate?, DocumentPostDate?, DocumentReceivedDate?, DocumentSequenceID?, DocumentStatus?, DocumentTitleText?, DocumentLanguage?, DocumentSubmitter?, SendingMDELocationID, SendingMDEProfileCode, ElectronicServiceInformation*, Case, FilingConfidentialityIndicator?, FilingLeadDocument+, FilingConnectedDocument*, DocumentFiler?, ActivityRequest*, Metadata*)
/// </para>
/// </summary>
public virtual DocumentFiler DocumentFiler
{
  get
  {
    return this.ContentField.DocumentFiler;
  }
  set
  {
    this.ContentField.DocumentFiler = value;
  }
}

/// <summary>
/// <para>
/// Occurrence: optional, repeating
/// </para>
/// <para>
/// Regular expression: (DocumentApplicationName?, DocumentBinary?, DocumentCategoryText*, DocumentDescriptionText?, DocumentEffectiveDate?, DocumentFileControlID?, DocumentFiledDate?, DocumentIdentification*, DocumentInformationCutOffDate?, DocumentPostDate?, DocumentReceivedDate?, DocumentSequenceID?, DocumentStatus?, DocumentTitleText?, DocumentLanguage?, DocumentSubmitter?, SendingMDELocationID, SendingMDEProfileCode, ElectronicServiceInformation*, Case, FilingConfidentialityIndicator?, FilingLeadDocument+, FilingConnectedDocument*, DocumentFiler?, ActivityRequest*, Metadata*)
/// </para>
/// </summary>
public virtual IList<ActivityRequest> ActivityRequest
{
  get
  {
    return this.ContentField.ActivityRequest;
  }
  set
  {
    this.ContentField.ActivityRequest = value;
  }
}

/// <summary>
/// <para>
/// Occurrence: optional, repeating
/// </para>
/// <para>
/// Regular expression: (DocumentApplicationName?, DocumentBinary?, DocumentCategoryText*, DocumentDescriptionText?, DocumentEffectiveDate?, DocumentFileControlID?, DocumentFiledDate?, DocumentIdentification*, DocumentInformationCutOffDate?, DocumentPostDate?, DocumentReceivedDate?, DocumentSequenceID?, DocumentStatus?, DocumentTitleText?, DocumentLanguage?, DocumentSubmitter?, SendingMDELocationID, SendingMDEProfileCode, ElectronicServiceInformation*, Case, FilingConfidentialityIndicator?, FilingLeadDocument+, FilingConnectedDocument*, DocumentFiler?, ActivityRequest*, Metadata*)
/// </para>
/// </summary>
public virtual IList<aoc.efiling.ecf.extension.Metadata> Metadata
{
  get
  {
    return this.ContentField.Metadata;
  }
  set
  {
    this.ContentField.Metadata = value;
  }
}

Dictionary<System.Xml.Linq.XName, System.Type> IXMetaData.LocalElementsDictionary
{
  get
  {
    IXMetaData schemaMetaData = ((IXMetaData)(this.Content));
    return schemaMetaData.LocalElementsDictionary;
  }
}

XTypedElement IXMetaData.Content
{
  get
  {
    return this.Content;
  }
}

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
System.Xml.Linq.XName IXMetaData.SchemaName
{
  get
  {
    return xName;
  }
}

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
SchemaOrigin IXMetaData.TypeOrigin
{
  get
  {
    return SchemaOrigin.Element;
  }
}

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
ILinqToXsdTypeManager IXMetaData.TypeManager
{
  get
  {
    return LinqToXsdTypeManager.Instance;
  }
}

public new static CoreFilingMessage Load(string xmlFile)
{
  return XTypedServices.Load<CoreFilingMessage, aoc.efiling.ecf.extension.CoreFilingMessageType>(xmlFile, LinqToXsdTypeManager.Instance);
}

public static new CoreFilingMessage Load(System.IO.TextReader xmlFile)
{
  return XTypedServices.Load<CoreFilingMessage, aoc.efiling.ecf.extension.CoreFilingMessageType>(xmlFile, LinqToXsdTypeManager.Instance);
}

public new static CoreFilingMessage Parse(string xml)
{
  return XTypedServices.Parse<CoreFilingMessage, aoc.efiling.ecf.extension.CoreFilingMessageType>(xml, LinqToXsdTypeManager.Instance);
}

public override XTypedElement Clone()
{
  return new CoreFilingMessage(((aoc.efiling.ecf.extension.CoreFilingMessageType)(this.Content.Clone())));
}

private void SetInnerType(aoc.efiling.ecf.extension.CoreFilingMessageType ContentField)
{
  this.ContentField = ((aoc.efiling.ecf.extension.CoreFilingMessageType)(XTypedServices.GetCloneIfRooted(ContentField)));
  XTypedServices.SetName(this, this.ContentField);
  base.SetSubstitutionMember(ContentField);
}

ContentModelEntity IXMetaData.GetContentModel()
{
  return ContentModelEntity.Default;
}

public static new XmlSchemaType CoreFilingMessageSchemaProvider(XmlSchemaSet schemas)
{
  LinqToXsdTypeManager.AddSchemas(schemas);
  XmlSchemaElement element = ((XmlSchemaElement)(schemas.GlobalElements[new XmlQualifiedName("CoreFilingMessage", "http://schema.azcourts.az.gov/aoc/efiling/ecf/extension/2.2")]));
  if ((element != null))
  {
    return element.ElementSchemaType;
  }
  return null;
}

}