A random collection of epiphanies, thoughts and problem solutions pertaining to .NET and BizTalk.

Thursday, October 21, 2004

The property 'TargetSite' on type 'System.Exception' cannot be serialized because it is decorated with declarative security permission attributes.

Detailed error:
The property 'TargetSite' on type 'System.Exception' cannot be serialized because it is decorated with declarative security permission attributes. Consider using imperative asserts or demands in the property accessors.



Solution: System.Exception object can not be serialized to transfer over the HTTP channel. Obviously, we need to provide some mechanism to serialize its state to some transferable medium like string. And on the other end, typically web service, we need to deserialize it back to the exception object.



I have a BaseException class that derives from System.Exception class. It has
a public property called "ExceptionState" that serializes it to Base64String representation. It also has a static method "Reconstruct" that reconstructs it from the Base64String back to the BaseException object.




public class BaseException : Exception, ISerializable
{

//...

string state;
static BinaryFormatter binaryFormatter = new BinaryFormatter();

/// <summary>
/// Persiste BaseException object to the base 64 string. This property returns
/// a string representation of the exception state which could be used to
/// reconstruct this exception if desired. <see cref="Reconstruct"/> method.
/// This property is introduced to fix the following issue:
/// The property 'TargetSite' on type 'System.Exception' cannot be serialized
/// because it is decorated with declarative security permission attributes.
/// Consider using imperative asserts or demands in the property accessors.
/// </summary>
public string ExceptionState
{
get
{
if (state == null)
{
MemoryStream stream = new MemoryStream();
binaryFormatter.Serialize(stream, this);
stream.Seek(0, SeekOrigin.Begin);
state = Convert.ToBase64String(stream.ToArray());
}
return this.state;
}
}

/// <summary>
/// Reconstructs a <c>BaseException</c> from the supplied exceptionState
/// string. <see cref="ExceptionProperty"/> property comments.
/// </summary>
/// <param name="exceptionState">
/// Base 64 string representation of the xception</param>
/// <returns>
/// A reconstructed <c>BaseException</c> object; null if reconstruction failed.
/// </returns>
public static BaseException Reconstruct(string exceptionState)
{
byte [] buffer = Convert.FromBase64String(exceptionState);
Stream stream = new MemoryStream(buffer, 0, buffer.Length, false);
stream.Seek(0, SeekOrigin.Begin);
object obj = binaryFormatter.Deserialize(stream);
return obj as BaseException;
}
}

Scritping Functoid Catch


I experienced a problem when I was using the Inline XSLT inside the scripting functoid. I entered the XSLT first, then I scrolled the "Script type" dropdown to check out the template of "Inline C#". Then I clicked on the "OK" button without noticing that "Configure Functoid Scripts" dialog actually overwrites the the script type of my choice "Inline XSLT" with "Inline C#", even though your intention is to use XSLT. As a matter of fact, when you scroll the "Script type" dropdown to any other script types in front of the "Inline XSLT" inside the "Script type" dropdown, BizTalk will automatically uses the first available in the list even somtime it only has script in comments. When you compile your project, it will not signal error since all of the commented code, i.e. empty script, is considered valid by compiler. But when you run your orchestration, it will bomb. The solution is you need to rearrange the precedence of the inline scripts. To do this, right click inside of the map area; then go to the property window and bring up the "Script Type Precedence" dialog.
Image Hosted by ImageShack.us
I would test any BizTalk mapper before I compile my projects. To do so, simply right click on your map file and select "Test map" from the context menu.

Monday, October 18, 2004

BizTalk Xml Links ...


  • Import, Include or Redefine


    Even though you could use <xs:import> or <xs:include> to reuse existing schemas, I found that BizTalk having some proprietary processing for <xs:include>. It will copy the included schema verbatim whenever you place your <xs:include> node. Moreover, the schemas will also be included whenever they are referenced. Thus, you will have multi-rooted master schema if you use <xs:include>. I prefer to use the <xs:import> because it will maintain the single root in the master schema even you reference multiple existing external schemas.




  • Assign messages


  • Xml Namespace and XPATH


  • Elements vs. Attributes


  • IBM's When to use elements versus attributes

Sunday, October 17, 2004

Yet another BizTalk Naming Guideline Recommendations

For all BizTalk orchestration shapes, I would recommend to call a shape with its name (or its shorthand) and suffix it with a succint description. This is only a recommendation. You don't have to follow this convention. The recommendation strives to promote a common set of guidelines.



...................................................................
Shape Short Example
...................................................................
Call Orchestration CallOdx CallOdx_AssembleReply
Call Rules CallRule CallRule_LoanDecisioning
Compensate Compensate Compensate_BadTransactions
Construct Message Mkmsg Mkmsg_GetEntityParams
Decide Decide Decide_ProcessBorrower
Delay Delay Delay_OneHour
Group Grp Grp_GetFirstEntity
Listen Listen Listen_IncomingReq
Loop Loop Loop_ProcessAllApplications
Message Assignment Assign Assign_EntityMatchResultToReplyMsg
Parallel Actions Para Para_GetMatchAndMkReply
Port* Port Port_GetEntities
Receive Recv Recv_AppReq
Send Send Send_AppRep
Start Orchestration Init Init_PlaceOrder
Suspend Susp Susp_CreditEvaluationOdx
Terminate Stop Stop_CreditEvaluationOdx
Throw Exception Throw Throw_UnknownReqException
Transform Xform Xform_GetEntityParams

* Since orchestration's port name has nothing to do with the transfer protocol, the name should not contain the word like Soap, Http, File, etc.

Followers