Home » BizTalk ServerRSS

Calling external assembly problem. System.Data.SqlClient.SqlConnection' is not marked as serializabl

Hi everybody,

I try to access a database using an external assembly (Serializable) within
an orchestration.
First I describe the Assembly function I call
The function I call access a stored Procedure. This procedure got as
parameter the customerID and as result I get the axapta Address for this
specific customer.

That I had tested with a small win app which give me the expected result.

In the Orchestration I got an expression shape within an atomic scope.

Source:
PublicFunction GetSAPTarget(ByVal FirstNodeName AsString, ByVal ApplicationName AsString, ByVal Typename AsString) AsString

 

Dim strSQL AsString = ""

 

Dim connStr AsString = ""

connStr = regConnectionString

 

Dim cn AsNew SqlConnection(connStr)

 

Dim cmd AsNew SqlCommand("GetSAPTarget", cn)

cn.Open()

 

Try

cmd.Parameters.Add(

"@FirstNodeName", SqlDbType.NVarChar).Value = FirstNodeName

cmd.Parameters.Add(

"@ApplicationName", SqlDbType.NVarChar).Value = ApplicationName

cmd.Parameters.Add(

"@TypeName", SqlDbType.NVarChar).Value = Typename

cmd.CommandType = CommandType.StoredProcedure

GetSAPTarget = cmd.ExecuteScalar().ToString

 

Catch ex As Exception

 

Throw ex

 

Finally

cn.Close()

cn.Dispose()

 

EndTry

 

EndFunction

Deployment works fine (no errors).

So when I Receive a message I get everytime the following error message:

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: beb93e15-1a9a-4b65-b762-3f12b2cd375c

Shape name:

ShapeId: 00000000-0000-0000-0000-000000000000

Exception thrown from: segment 2, progress 20

Inner exception: Type 'System.Data.SqlClient.SqlConnection' in Assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

What is strange is that the error message appears in the event log after getting the right Target.

Can anybody help me here?

Thanks

Marcus

 

5 Answers Found

 

Answer 1

Forgot to mention:

 

I am using BTS 2009

 

Answer 2

Examining the stack trace might reveal what exactly is happening. 

I'm slightly confused by the fact that you suggest you are only calling  your code from within an atomic  scope. 

To be clear - it is not really important exactly where you're calling the function, what is important is whether or not an instance  of SqlConnection exsists within the orchestration  at a point where it tries to dehydrate

Difficult to know exactly what is going on without seeing the entire code, but could it be, for example that whilst you're calling the  function from within an atomic scope, the instance of the class lives outside this scope? 

If that is the case, is there a chance that the connection remains in memory when the process steps out of the scope  the tries to persist to the message  box?

 

If that is the case, and you can, try to move the variable into the scope so that it never gets serialised. 

If you can't, see if setting the connection to null after calling dispose  helps.

 

Answer 3

Hi Marcus,

as far as I can see from your code, you are not using any data, except the parameters  and the regConnectionString.

If you make the initialization of the regConnectionString local to the method, you could make the whole method static within a static class. Then you wouldn't have any persistence (Not marked  as Serializable ...) issues anymore, because you won't need a  orchestration  variable of your class, which is causing your problem. BizTalk is trying to serialize your whole custom class instance, which probably isn't even necessary.

Regards,

Leo

 

Answer 4

And here the entry of the event  log:

 

xlang/s engine event log  entry: Uncaught exception  (see the 'inner exception' below) has suspended  an instance  of service  'Orchestrations.ScaleOrchestration2009(91aa33b9-965a-a214-17d1-9fa92ab9aa07)'.
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: 7c4a5c73-2f8f-402b-87c3-ea951aa7f9b7
Shape name: Send2SAP
ShapeId: 4b34fa65-8c23-4b16-98c4-b43ec4074ff7
Exception thrown  from: segment  1, progress  48
Inner exception: type  'System.Data.SqlClient.SqlConnection' in Assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked  as serializable.
       
Exception type: SerializationException
Source: mscorlib
Target Site: System.Reflection.MemberInfo[] InternalGetSerializableMembers(System.RuntimeType)
The following is a stack trace that identifies the location where the exception occured

   at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
   at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
   at Microsoft.XLANGs.Core.ObjectSerializer._serialize(Object graph, StringLookup sl)
   at Microsoft.XLANGs.Core.ObjectSerializer.SerializeStateManager(IStateManager stateMgr, StringLookup lookup)
   at Microsoft.XLANGs.Core.Service.Persist(Boolean dehydrate, Context ctx, Boolean idleRequired, Boolean finalPersist, Boolean bypassCommit, Boolean terminate)
   at Microsoft.XLANGs.Core.ServiceContext.PendingCommit(Boolean ignore, XMessage msg)
   at Microsoft.XLANGs.Core.ExceptionHandlingContext.PendingCommit(Boolean ignoreCommit, XMessage msg)
   at Microsoft.BizTalk.XLANGs.BTXEngine.BTXPortBase.SendMessage(Int32 iOperation, XLANGMessage msg, Correlation[] initCorrelations, Correlation[] followCorrelations, Context cxt, Segment seg, ActivityFlags flags)
   at Orchestrations.ScaleOrchestration2009.segment1(StopConditions stopOn)
   at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, StopConditions stopCond, Exception& exp)

       

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

 

Answer 5

Hi Yossi,

 

the setting of my ScaleHelper = null was the solution.

 

Many thanks.

 

Marcus

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter