Wednesday, June 1, 2011

Object reference not set to an instance of an object + BizTalk

Recently my team mate reported me an issue in his BizTalk application..
application does something like it gets the request from MSMQ then makes Database call get response from database and then write response to the response_MSMQ.

following is the error in eventlog:

Uncaught exception (see the 'inner exception' below) has suspended an instance of service (d18ebb96-bf15-bdd9-06f5-d2c07b2b4260)'.
The service instance will remain suspended until administratively resumed or terminated.
If resumed the instance will continue from its last persisted state and may re-throw the same unexpected exception.
InstanceId: 3e6974ee-1506-4eea-abcf-7c7b18cadf1b
Shape name:
ShapeId: 00000000-0000-0000-0000-000000000000
Exception thrown from: segment 19, progress 10
Inner exception: Object reference not set to an instance of an object.

Exception type: NullReferenceException
Source: ADDRECEIPTS_IN
Target Site: Microsoft.XLANGs.Core.StopConditions segment19(Microsoft.XLANGs.Core.StopConditions)
The following is a stack trace that identifies the location where the exception occured

at <>.segment19(StopConditions stopOn)
at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, S


There are two things I noticed :
1. When you look at the the Orchestration debugger for the the message it shows the message is sent to Database and no response is received fron SQL,, but certainly thats not the case as BizTalk has a concepts of persistance points, where it persists the state of orchestration at certain events of message flow, in my case it is the Send port by which I am sending message to database causes persistance.. and therefore it is showing me message flow till send shape. and after inspecting more a bit I concluded there in nothing wrong in response message from database. So definately something is going wrong between the sql send shape and the next persitance point.
So hereby is the problem with the code, where a .NET component is call and that piece of code is throwing this error. Hence, whenever you get this kind of error
a) make sure your are getting correct response message and it should'nt be null or something.
b) Look for the code there must be something which is screwing the stuff but deviating you from the issue root.

2) In case, I would have got this issue in first Activating Receive shape in orchestration, let me go to little back, when we create orchestration we define certain orchetration variable as well, as per the our business functionality.knowing the fact everything in BizTalk compiles to .NET code, If we try to assume an orchestration as class and Orchestration variables as class variables and when got this issue..Then I suggest to look at the code of constructors of orchestration variable defined types. there must be something wrong there.

Moral of the story: Handle exceptions properly and test exceptional handling, this is one of few things in programmers life which can soothe his burning @$$