Hichamveo
Hichamveo

Reputation: 514

JSON decoder : Object reference not set to an instance of an object

I get the following error on a JSON receive pipeline when calling a REST Get API :

There was a failure executing the response(receive) pipeline: "mycustomPiepeline,mycustomPieplelineAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=70f46ad2a5c6e8c0" Source: "JSON decoder" Send Port: "My webHttp send port" URI: "URL" Reason: Object reference not set to an instance of an object.

and also from an Insomnia call the response is : null

I found this solution from Mark's blog by using BRE pipeline framework, but I'm not using BRE.

I think to create a custom component pipeline to replace the null response with an empty body, is there any better suggestions?

I'm using BTS 2016 CU4

Upvotes: 0

Views: 1096

Answers (1)

Dijkgraaf
Dijkgraaf

Reputation: 11527

There is a possible fix from Microsoft FIX: WCF-WebHTTP Two-Way Send Response responds with an empty message and causes the JSON decoder to fail in BizTalk Server but that was in CU2 for 2016, so it looks like they didn't solve the issue 100% unless you didn't populate the AddMessageBodyForEmptyMessage property.

Mark's solution is more to do with some elements in a JSON payload created by the JSON Encoder having a null value, which itself is a work around for a bug in the JSON Encoder that is changing an empty string into a null.

If you don't want to use the BRE Pipeline Component (which hopefully will be available for BizTalk 2016 very soon as I know it is being worked on), then you can roll your own e.g. below, where InsertInEmpty is a parameter on the Pipeline Component that you can set what message to return if you get a empty body.

    #region IComponent members
    /// <summary>
    /// Implements IComponent.Execute method.
    /// </summary>
    /// <param name="pc">Pipeline context</param>
    /// <param name="inmsg">Input message</param>
    /// <returns>Original input message</returns>
    /// <remarks>
    /// IComponent.Execute method is used to initiate
    /// the processing of the message in this pipeline component.
    /// </remarks>
    public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
    {
        string dataOut = "";
        StreamReader sr = new StreamReader(inmsg.BodyPart.Data);

        if (InsertInEmpty != "" & inmsg.BodyPart.Data.Length == 0)
        {
                dataOut = InsertInEmpty;               
        }
        else 
        {   
            dataOut = dataOut + sr.ReadToEnd();
        }
        MemoryStream ms = new System.IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes(dataOut));
        inmsg.BodyPart.Data = ms;
        inmsg.BodyPart.Data.Position = 0;

        return inmsg;
    }
    #endregion

Upvotes: 0

Related Questions