locked
InnerException = {"The type WebServices.MP0352.NonDependentParents_Type was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."} RRS feed

  • Question

  • User1416033902 posted

    Hi all

    I am getting the folliowng error message:

    InnerException = {"The type WebServices.MP0352.NonDependentParents_Type was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."}

    The problem is in the line: 

      Dim nonDependantParents As New WebServices.MP0352.NonDependentParents_Type

    ....

     serviceData.ParentsForAsset.Item = nonDependantParents

    The object  serviceData.ParentsForAsset.Item is of type Object  and nonDependantParents is of type  WebServices.MP0352.NonDependentParents_Type

    How do I allocate serviceData.ParentsForAsset.Item to populate it with nonDependantParents ??????

    I understand that serviceData.ParentsForAsset.Item has to be populated with nonDependantParents, but the declaration of the property serviceData.ParentsForAsset.Item uses Object instead of the NonDependentParents_Type type.

    Please take a look to the XML code included in this post

    Source Code:

    Dim addAssetToStructure As WebServices.MP0352.AddAssetToStructureService
            Dim serviceData As New WebServices.MP0352.MP0352_AddAssetToStructure_001
            Dim result As WebServices.MP0352.MP0352_AddAssetToStructure_001_Result
    
    
            ' Read the URL for the web services from the app config file
            Dim url As String = myurl
    
    
            Try
    
           
            addAssetToStructure = InitializeAssetToStructureService(myRequiredAssetFields.UserId, myRequiredAssetFields.Password, myRequiredAssetFields.Org, myRequiredAssetFields.Tenant)
    
            serviceData.ASSETID = New WebServices.MP0352.EQUIPMENTID_Type
    
            '
            ' Add Organization info
            '
            With serviceData.ASSETID
    
                .EQUIPMENTCODE = EamID
                .DESCRIPTION =  EamDesc
                .ORGANIZATIONID = New WebServices.MP0352.ORGANIZATIONID_Type
                .ORGANIZATIONID.ORGANIZATIONCODE = myRequiredAssetFields.Org
    
            End With
    
            '
            '  Populates ParentsForAsset, NonDependentParents, NONDEPENDENTSYSTEM, SYSTEMID
            '     
            '
    
    
    
            serviceData.ParentsForAsset = New WebServices.MP0352.ParentsForAsset
    
    
            '
            '  Systemm ID 
            '   - EquipmentCode 
            '   - OrganizationID,
            ' 
    
            Dim systemID As New WebServices.MP0352.EQUIPMENTID_Type
    
            systemID.EQUIPMENTCODE = "TEST"
    
            Dim organizationID As New WebServices.MP0352.ORGANIZATIONID_Type
    
            organizationID.ORGANIZATIONCODE = myRequiredAssetFields.Org
    
            systemID.ORGANIZATIONID = New WebServices.MP0352.ORGANIZATIONID_Type
    
            systemID.ORGANIZATIONID = organizationID
    
            Dim nonDependantParents As New WebServices.MP0352.NonDependentParents_Type
            Dim nonDependentSystem As New WebServices.MP0352.SYSTEMPARENT_Type()
    
            With nonDependentSystem
                .SYSTEMID = New WebServices.MP0352.EQUIPMENTID_Type
                .SYSTEMID = systemID
            End With
    
    
           With nonDependantParents
                .NONDEPENDENTSYSTEM = New WebServices.MP0352.SYSTEMPARENT_Type() {nonDependentSystem}
           End With
    
                '
                '  Populates ServiceData 
                '
           serviceData.ParentsForAsset.Item = nonDependantParents      THE PROBLEM
    
                '
                '  Call Web service to populate the field Location (Atlas -TTRRSS)  
                '
    
                result = addAssetToStructure.AddAssetToStructureOp(serviceData)  THIS IS WHERE THE PROGRAM THROWS THE EXCEPTION 
    
    
    

    The Class ParentsForAsset

    '''<remarks/>
        <System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18408"),  _
         System.SerializableAttribute(),  _
         System.Diagnostics.DebuggerStepThroughAttribute(),  _
         System.ComponentModel.DesignerCategoryAttribute("code"),  _
         System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true, [Namespace]:="http://schemas.datastream.net/MP_functions/MP0352_001")>  _
        Partial Public Class ParentsForAsset
            
            Private itemField As Object
            
            '''<remarks/>
            <System.Xml.Serialization.XmlElementAttribute("AssetDependency", GetType(AssetDependency), [Namespace]:="http://schemas.datastream.net/MP_entities/AssetEquipment_001"),  _
             System.Xml.Serialization.XmlElementAttribute("LocationDependency", GetType(LocationDependency), [Namespace]:="http://schemas.datastream.net/MP_entities/AssetEquipment_001"),  _
             System.Xml.Serialization.XmlElementAttribute("PositionDependency", GetType(PositionDependency), [Namespace]:="http://schemas.datastream.net/MP_entities/AssetEquipment_001"),  _
             System.Xml.Serialization.XmlElementAttribute("SystemDependency", GetType(SystemDependency), [Namespace]:="http://schemas.datastream.net/MP_entities/AssetEquipment_001"),  _
             System.Xml.Serialization.XmlElementAttribute("NonDependentParents", GetType(NonDependentParents))>  _
            Public Property Item() As Object
                Get
                    Return Me.itemField
                End Get
                Set
                    Me.itemField = value
                End Set
            End Property
        End Class

    XML Code:

    <soap:Body>
        <MP0352_AddAssetToStructure_001 version="001" xmlns="http://schemas.datastream.net/MP_functions/MP0352_001">
          <ASSETID xmlns="http://schemas.datastream.net/MP_fields">
            <EQUIPMENTCODE>999999</EQUIPMENTCODE> 
            <ORGANIZATIONID>
              <ORGANIZATIONCODE>AAAAA</ORGANIZATIONCODE>
            </ORGANIZATIONID>
          </ASSETID>
          <ParentsForAsset>
            <NonDependentParents>
              <NONDEPENDENTSYSTEM xmlns="http://schemas.datastream.net/MP_fields">
                <SYSTEMID>
                  <EQUIPMENTCODE>AAA-999999</EQUIPMENTCODE>
                  <ORGANIZATIONID>
                    <ORGANIZATIONCODE>XXXX1</ORGANIZATIONCODE>
                  </ORGANIZATIONID>
                </SYSTEMID>
              </NONDEPENDENTSYSTEM>
            </NonDependentParents>
          </ParentsForAsset>
        </MP0352_AddAssetToStructure_001>
      </soap:Body>
    </soap:Envelope>

    Friday, July 11, 2014 7:40 AM

Answers

  • User1416033902 posted

    Hi Fuxiang Zhang,

    Thank you for your answer.

    Finally I found the problem! I replaced the type NonDependentParents_Type  by NonDependentParents  and it worked

     Dim nonDependantParents As New WebServices.MP0352.NonDependentParents_Type

    By
     Dim nonDependantParents As New WebServices.MP0352.NonDependentParents

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 15, 2014 7:29 AM

All replies

  • User-417640953 posted

    InnerException = {"The type WebServices.MP0352.NonDependentParents_Type was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."}

    Hi jsancn,

    Thank you post the issue to asp.net forum.

    Above error message means your web service try to serialize the inherited class.

    You can try to use the attribute XmlInclude to specify a known type to it like below.

    [XmlInclude(typeof(BankPayment))]
    [Serializable]
    public Payment 
    { 
      //.......
    
    }    

    Similar issues please follow below threads.

    http://stackoverflow.com/questions/11886290/use-the-xmlinclude-or-soapinclude-attribute-to-specify-types-that-are-not-known

    http://stackoverflow.com/questions/20003585/type-xxxx-not-expected-use-xmlinclude-or-soapinclude

    Hope this helps, thanks.

    Best Regards!

    Monday, July 14, 2014 6:12 AM
  • User1416033902 posted

    Hi Fixiang,

     I think that the Class ParentsForAsset is already using the attribute XmlInclude.  This class is part of the package  WebServices.MP0352.

     

     /// <remarks/>
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18408")]
        [System.SerializableAttribute()]
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.ComponentModel.DesignerCategoryAttribute("code")]
        [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://schemas.datastream.net/MP_functions/MP0352_001")]
        public partial class ParentsForAsset {
            
            private object itemField;
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute("AssetDependency", typeof(AssetDependency), Namespace="http://schemas.datastream.net/MP_entities/AssetEquipment_001")]
            [System.Xml.Serialization.XmlElementAttribute("LocationDependency", typeof(LocationDependency), Namespace="http://schemas.datastream.net/MP_entities/AssetEquipment_001")]
            [System.Xml.Serialization.XmlElementAttribute("PositionDependency", typeof(PositionDependency), Namespace="http://schemas.datastream.net/MP_entities/AssetEquipment_001")]
            [System.Xml.Serialization.XmlElementAttribute("SystemDependency", typeof(SystemDependency), Namespace="http://schemas.datastream.net/MP_entities/AssetEquipment_001")]
            [System.Xml.Serialization.XmlElementAttribute("NonDependentParents", typeof(NonDependentParents))]
            public object Item {
                get {
                    return this.itemField;
                }
                set {
                    this.itemField = value;
                }
            }
        }

     What I would like to know is how I can specify a known type in my vb code:

     serviceData.ParentsForAsset.Item = ?????

    From what I read on this link http://msdn.microsoft.com/en-us/library/aa302290.aspx  it is a example of  "when the types in the object graph that are passed to the method runtime do not match the types that were declared in the class at design-time".  And the solution to fix the problem as far as I understand is already implemented in the Class ParentsForAsset

     Thanks

     

    Monday, July 14, 2014 9:45 AM
  • User-417640953 posted

    Hi jsancn,

    Thanks for your response.

    I understand you have a property item in type "ParentsForAsset" which is a type of Object.

    And you want to serialize type "ParentsForAsset" and the Object property assigned a "NonDependentParents_Type".

    For this issue, I think we should specify a known type to the Object property like below.

     public class ChildType 
            { 
                public int ID { get; set; }
                public string Name { get; set; }
            }
    
            public class ContainerType
            {
                [XmlElementAttribute("ChildType_Object", typeof(ChildType))] 
                public Object Item1 { get; set; }
                public ChildType Item2 { get; set; }
            
            }

    Then serialize it like below.

    ContainerType obj = new ContainerType();
    obj.Item1 = new ChildType() { ID = 1, Name = "Jhon" };
    obj.Item2 = new ChildType() { ID = 2, Name = "Jhon2" };
    XmlSerializer serializer = new XmlSerializer(typeof(ContainerType));
    TextWriter writer = new StreamWriter("D:\\po.xml");
    serializer.Serialize(writer, obj); 
    Console.Write("Ok");

    The result will be like below.

    <ContainerType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <ChildType_Object>
        <ID>1</ID>
        <Name>Jhon</Name>
      </ChildType_Object>
      <Item2>
        <ID>2</ID>
        <Name>Jhon2</Name>
      </Item2>
    </ContainerType>

    However, I also see you have add the known type to it from below code.

      System.Xml.Serialization.XmlElementAttribute("NonDependentParents", GetType(NonDependentParents))>  _
            Public Property Item() As Object
    

    Please try to create small demo and other influences, thanks.

    Best Regards!

    Monday, July 14, 2014 10:09 PM
  • User1416033902 posted

    Hi Fuxiang Zhang,

    Thank you for your answer.

    Finally I found the problem! I replaced the type NonDependentParents_Type  by NonDependentParents  and it worked

     Dim nonDependantParents As New WebServices.MP0352.NonDependentParents_Type

    By
     Dim nonDependantParents As New WebServices.MP0352.NonDependentParents

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 15, 2014 7:29 AM