Microsoft Developer Network > Forums Home > BizTalk Server Forums > BizTalk Server General > What's wrong with xlangMessage.GetPropertyValue (BT2009)
Ask a questionAsk a question
 

AnswerWhat's wrong with xlangMessage.GetPropertyValue (BT2009)

  • Thursday, September 17, 2009 10:50 AMWell0549 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have a specific function to get the value of a context property.
    It works for ALL context properties except for 'BTS.MessageType'

    if i do

    xlangMessage.GetPropertyValue(typeof(BTS.MessageType))


    I  get the following exception.

    Exception type: System.Xml.XmlException
    Message: Data at the root level is invalid. Line 1, position 1.
    Source: System.Xml
    StackTrace:
       at System.Xml.XmlTextReaderImpl.Throw(Exception e)
       at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
       at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
       at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
       at System.Xml.XmlTextReaderImpl.Read()
       at System.Xml.XmlTextReader.Read()
       at Microsoft.XLANGs.Core.Value.GetActualMessageTypeName()
       at Microsoft.XLANGs.Core.Part.GetActualMessageTypeName()
       at Microsoft.BizTalk.XLANGs.BTXEngine.BTXMessage._getBTSMessageType(XMessage msg, XmlQName propQName)
       at Microsoft.XLANGs.Core.PropertyHanlderCollection.Get(XMessage msg, XmlQName propQName, Object& res)
       at Microsoft.XLANGs.Core.XMessage.GetGenericProperty(XmlQName propQName, Object& val)
       at Microsoft.XLANGs.Core.XMessage.InternalGetContextProperty(XmlQName propQName)
       at Microsoft.XLANGs.Core.XMessage.GetPropertyValue(Type propType)
       at Microsoft.BizTalk.XLANGs.BTXEngine.BTXMessage.GetPropertyValue(Type propType)
       at Microsoft.XLANGs.Core.MessageWrapperForUserCode.GetPropertyValue(Type propType)
      
    Well0549

    This happens ONLY when i am using UNTYPED messaging !, for typed messages everything works as expected
    • Edited byWell0549 Thursday, September 17, 2009 11:12 AMExtra info
    •  

Answers

  • Thursday, September 17, 2009 1:16 PMWell0549 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    And after digging around in Reflector I found the following code.....

    public override object GetPropertyValue(Type propType)
    {
        if (this._opContext != null)
        {
            PropertyMetadata metadata = PropertyMetadata.For(propType);
            if (metadata == null)
            {
                throw new ArgumentNullException("PropertyMetadata pm = PropertyMetadata.For( propType )");
            }
            XmlQName qName = metadata.QName;
            object obj2 = this._opContext[qName];
            if (obj2 != null)
            {
                return obj2;
            }
        }
        if (!(propType.FullName == "BTS.MessageType"))
        {
            return this._msg.GetPropertyValue(propType);
        }
        string messageTypeName = MessageMetadata.For(this._msg).MessageTypeName;
        if (messageTypeName == "http://schemas.microsoft.com/BizTalk/2003/Any#Root")
        {
            string nonGenericContextProperty = (string) this._msg.InternalGetNonGenericContextProperty(propType);
            if (nonGenericContextProperty != null)
            {
                return nonGenericContextProperty;
            }
        }
        return messageTypeName;
    }
    
     
    
     
    
    


    So there is definitely something stinky going on with BTS.MessageType.
    I found this piecece of code in :

    public override object GetPropertyValue(Type propType);
    Declaring Type: Microsoft.XLANGs.Core.MessageWrapperForTracking
    Assembly: Microsoft.XLANGs.Engine, Version=3.0.1.0
    Well0549

All Replies

  • Thursday, September 17, 2009 12:52 PMAbdul Rafay Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    You have to promote the BTS.MessageType property your self in the Custom Receive Pipeline component(Disassemble). If you are using untyped messages (System.Xml.XmlDocument) this property will not be promoted by the pipeline. Also you can make sure by opening the HAT tool and extracting the message context property and you can confirm that it is not being promoted.
    Abdul Rafay http://abdulrafaysbiztalk.wordpress.com/ Please mark this answer if it helps
  • Thursday, September 17, 2009 1:09 PMWell0549 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I think you are makin an error here.

    I said it worked for ALL context properties, promoted and not promoted.

    In the documentation it states :

    XLANGMessage.GetPropertyValue Method

    Returns the value of a content or context property.

    [Visual Basic]
    Public MustOverride Function GetPropertyValue( _
       ByVal propType As Type _
    ) As Object
    [C#]
    public abstract object GetPropertyValue(
       Type propType
    );
    [C++]
    public: virtual Object* GetPropertyValue(
       Type* propType
    ) = 0;
    [JScript]
    public abstract function GetPropertyValue(
       propType : Type
    ) : Object;

    Parameters

    propType
    Message context or message context property type. These types are defined using a property schema. 

    Exceptions

    Exception TypeCondition
    InvalidCastException The value of the property that appears in the data or context of the message cannot be converted into the property’s field type.
    InvalidPropertyTypeException A data property that is not defined on the message is being accessed.
    AmbiguousXPathException XPath associated with the property did not resolve to a single value.

    Remarks

    Returns null if the property does not exist on the message.

    Message context and message context property types are defined using a property schema. For more information, see MessageContextPropertyBase and MessageDataPropertyBase.

    Even the exception i get is not documented............


    Well0549
  • Thursday, September 17, 2009 1:16 PMWell0549 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    And after digging around in Reflector I found the following code.....

    public override object GetPropertyValue(Type propType)
    {
        if (this._opContext != null)
        {
            PropertyMetadata metadata = PropertyMetadata.For(propType);
            if (metadata == null)
            {
                throw new ArgumentNullException("PropertyMetadata pm = PropertyMetadata.For( propType )");
            }
            XmlQName qName = metadata.QName;
            object obj2 = this._opContext[qName];
            if (obj2 != null)
            {
                return obj2;
            }
        }
        if (!(propType.FullName == "BTS.MessageType"))
        {
            return this._msg.GetPropertyValue(propType);
        }
        string messageTypeName = MessageMetadata.For(this._msg).MessageTypeName;
        if (messageTypeName == "http://schemas.microsoft.com/BizTalk/2003/Any#Root")
        {
            string nonGenericContextProperty = (string) this._msg.InternalGetNonGenericContextProperty(propType);
            if (nonGenericContextProperty != null)
            {
                return nonGenericContextProperty;
            }
        }
        return messageTypeName;
    }
    
     
    
     
    
    


    So there is definitely something stinky going on with BTS.MessageType.
    I found this piecece of code in :

    public override object GetPropertyValue(Type propType);
    Declaring Type: Microsoft.XLANGs.Core.MessageWrapperForTracking
    Assembly: Microsoft.XLANGs.Engine, Version=3.0.1.0
    Well0549
  • Thursday, September 24, 2009 8:49 PMThiago AlmeidaMVP, AnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    If the message is untyped then message type property won't be there so I'm not surprised it throws an exception (althought it should be a nicer looking exception instead of an xml exception)


    Thiago Almeida - http://connectedthoughts.wordpress.com
  • Thursday, November 05, 2009 12:22 PMWell0549 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Exceptions defined according to the documentation :

    Exception TypeCondition
    InvalidCastException The value of the property that appears in the data or context of the message cannot be converted into the property’s field type.
    InvalidPropertyTypeException A data property that is not defined on the message is being accessed.
    AmbiguousXPathException XPath associated with the property did not resolve to a single value.

    So i am really surprised to see an xml exception
    Well0549
  • Thursday, November 05, 2009 7:23 PMThiago AlmeidaMVP, AnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Message type is stored and retrieved as xml if you look through the path in the exception stack trace.

    public string GetActualMessageTypeName()
    {
        if (this._xdw != null)
        {
            XmlElement documentElement = this._xdw.GetXmlDocument().DocumentElement;
            if (documentElement == null)
            {
                return null;
            }
            return PartTypeMetadata.ComposeMessageType(documentElement.NamespaceURI, documentElement.LocalName);
        }
        XmlReader xmlReader = this.GetXmlReader();
        if (xmlReader != null)
        {
            while (xmlReader.Read())
            {
                if (XmlNodeType.Element == xmlReader.NodeType)
                {
                    return PartTypeMetadata.ComposeMessageType(xmlReader.NamespaceURI, xmlReader.LocalName);
                }
            }
            return null;
        }
        return null;
    }
    


    Thiago Almeida - http://connectedthoughts.wordpress.com
  • Friday, November 06, 2009 3:04 PMWell0549 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I agree, but the docuemntation states only three exceptions.....
    And i get an undocumented one.....
    ( that was my point )
    Well0549
  • Friday, November 06, 2009 7:51 PMThiago AlmeidaMVP, AnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I was just saying you shouldn't be surprised to see an xml exception since it's stored as XML. But also agree with you that the xml exception should have been handled more graceously and thrown a proper exception.
    Thiago Almeida - http://connectedthoughts.wordpress.com