Search code examples
exceptioninitializationbiztalkbiztalk2006r2message-type

BizTalk keeps asking for initialization of ALREADY initialized messages


In my orchestration I have various steps that maps a flat file to 2 intermediate messages and eventually writes to SQL. First I made it without exception handling and it worked with a valid input file.

                msg0        msg1       msg2
┌──────┐  ┌─────┐  ┌───────┐  ┌───────┐  ┌─────┐
│ PIPE │-►│ RCV │-►│ MAP_1 │-►│ MAP_2 │-►│ SQL │
└──────┘  └─────┘  └───────┘  └───────┘  └─────┘

Now I'm trying to get the exceptions for every scope where I use a map. at the beginning of the orchestration, after the first Receive Shape, I put a Construct Message Shape that initializes all messages in the orchestration. I create the catch blocks (each with Construct shape for my fault_msg and its send shape), the FILE port, and build.

                             msg0          msg1          msg2
┌──────┐  ┌─────┐  ┌──────┬──┐  ┌───────┬──┐  ┌───────┬──┐  ┌─────┬──┐
│ PIPE │-►│ RCV │-►│ INIT │ex│-►│ MAP_1 │ex│-►│ MAP_2 │ex│-►│ SQL │ex│
└──────┘  └─────┘  └──────┴──┘  └───────┴──┘  └───────┴──┘  └─────┴──┘

VS KEEPS ASKING for msg initialization even in the map blocks for the messages that should enter ALREADY filled (or populated, or whatever the term is). Why is that?

EDIT: I figured out BT wants every msg initialized even when not used during exception handling. So I need to construct my custom fault message that will return the empty messages along with my custom fault message. In order to initialize them of course i need to declare at the beginning of the expression code this way:

    unusedMsg.Part = new System.Xml.XmlDocument();

Thing is now: the problem still comes out for the last mapping (sql):

           ┌──────────────────────┐
           │        scope         │
           │  ┌────────────────┐  │ 
┌──────┐   │  │      MAP       │  │    ┌────────┐
│ msg2 │ -►│  │ msg2  > sqlReq │  │ -► │ sqlReq │
└──────┘   │  └────────────────┘  │    └────────┘
           ├──────────────────────┤
           │         ex           │
           │  ┌────────────────┐  │
           │  │   construct    │  │    ┌────────┐
           │  │ msg2  > msgERR │  │ -► │ msgERR │
           │  └────────────────┘  │    └────────┘
           └──────────────────────┘

where it keeps asking this:

msg2.Part': message part has not been initialized in construct statement

and yet I know for sure that msg2 IS INITIALIZED because I had no exception producing it and I'm entering the new scope. How's that possible?


Solution

  • The error "message part has not been initialized in construct statement" occurs under the following circumstances in BizTalk

    1. Your construct shape is constructing the same message as one of the source messages. e.g in the following you need to remove msg2 from the messages constructed.

                    CORRECT                                  WRONG
             ┌──────────────────────┐               ┌──────────────────────┐
             │   CONSTRUCT MESSAGE  │               │   CONSTRUCT MESSAGE  │
             │ messages constructed │               │ messages constructed │
             │     sqlReq           │               │     sqlReq, msg2     │
             │  ┌────────────────┐  │               │  ┌────────────────┐  │
             │  │      MAP       │  │               │  │      MAP       │  │
             │  │ msg2  > sqlReq │  │               │  │ msg2  > sqlReq │  │
             │  └────────────────┘  │               │  └────────────────┘  │
             └──────────────────────┘               └──────────────────────┘
      
    2. You are constructing multiple messages in a construct shape, but a later message is dependent on you initialising another message earlier in the construct which is missing.

                    CORRECT                                  WRONG
             ┌──────────────────────┐               ┌──────────────────────┐
             │        Construct     │               │        Construct     │
             │ messages constructed │               │ messages constructed │
             │     sqlReq, sqlReq2  │               │     sqlReq, sqlReq2  │
             │  ┌────────────────┐  │               │                      │
             │  │      MAP       │  │               │                      │
             │  │ msg2  > sqlReq │  │               │                      │
             │  └────────────────┘  │               │                      │
             │  ┌────────────────┐  │               │  ┌────────────────┐  │
             │  │      MAP       │  │               │  │      MAP       │  │
             │  │sqlReq > sqlReq2│  │               │  │sqlReq > sqlReq2│  │
             │  └────────────────┘  │               │  └────────────────┘  │
             └──────────────────────┘               └──────────────────────┘
      

    The error "use of unconstructed message" occurs with the following.

    1. You are trying to use a message as a source inside a scope that is neither initialized at the start of the scope nor prior to the construct shape inside the scope.

    2. You are trying to use a message in an exception block that was initialized inside the scope you are trying to catch an exception for.

    3. You are using a message after a scope that is only constructed in some of the scope areas. It needs to be constructed in all the scope areas.