karron

Hi, I miss a trouble in my current workflow project, and it will cause my workflow instance terminate. The exception as following. It says ServerIdentity is not marked as serializable, but ServerIdentity is absolutely serializable.. anyone can help me thanks a lot.


Code Snippet

Type 'System.Runtime.Remoting.ServerIdentity' in Assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable. System.Runtime.Serialization.SerializationException: Type 'System.Runtime.Remoting.ServerIdentity' in Assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable. 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(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter) 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 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph) at System.Workflow.ComponentModel.Activity.Save(Stream stream, IFormatter formatter) at System.Workflow.ComponentModel.Activity.Save(Stream stream) at System.Workflow.Runtime.WorkflowStateRollbackService.CheckpointInstanceState() at System.Workflow.Runtime.WorkflowExecutor.System.Workflow.ComponentModel.IWorkflowCoreRuntime.CheckpointInstanceState(Activity currentActivity) at System.Workflow.ComponentModel.ActivityExecutionContext.CheckpointInstanceState() at System.Workflow.ComponentModel.TransactedContextFilter.ExecuteActivity(Activity activity, ActivityExecutionContext context, Boolean locksAcquired) at System.Workflow.ComponentModel.TransactedContextFilter.Execute(Activity activity, ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime) at System.Workflow.Runtime.Scheduler.Run()



Re: Windows Workflow Foundation Type 'System.Runtime.Remoting.ServerIdentity' is not marked as serializable.

Tomas Restrepo

Karron,

Actually, ServerIdentity is not serializable. Do you have a remoted object as a member of your worklow class (or custom activity) If so, that wouldn't likely work without you writing custom code to enable it, as WF wouldn't have a way of reconnecting the proxy to the remote object when the workflow was deserialized from the persistence service and recreated in memory (well, it has no way of saving it in the first place, but you get the idea).





Re: Windows Workflow Foundation Type 'System.Runtime.Remoting.ServerIdentity' is not marked as serializable.

karron

I haven't any remote objects, but I use dynamic proxy for my business services, maybe it's the point. And an other things, the exception is not raised every times, it happened randomly.





Re: Windows Workflow Foundation Type 'System.Runtime.Remoting.ServerIdentity' is not marked as serializable.

Tomas Restrepo

The dynamic proxy indeed could be the problem. Looks like you might need to find a way to avoid making those objects directly part of your WF model (or get rid of the dynamic proxy). It probably only happens sometimes because you only hit it when certain activities are cloned at specific moments, or only when a persistence point is reached and you have a persistence service configured.





Re: Windows Workflow Foundation Type 'System.Runtime.Remoting.ServerIdentity' is not marked as serializable.

karron

I consider getting rid of dynamic proxies in my workflow models, hope it resolve my problem. Thanks a lot for your kind help.





Re: Windows Workflow Foundation Type 'System.Runtime.Remoting.ServerIdentity' is not marked as serializable.

Carl Cook

I'm grappling with this same issue. I can create a variety of our component objects and save them like this (as you can tell, this is prototype code):

Dim myArrayList As ArrayList

myArrayList = New ArrayList

For Each Obj In MySerializableObjects

myArrayList.Add(Obj)

Next

If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

Dim formatter As New Runtime.Serialization.Formatters.Binary.BinaryFormatter

Dim stream As New FileStream(SaveFileDialog1.FileName, _

FileMode.Create, FileAccess.Write, FileShare.None)

formatter.Serialize(stream, ProgramVersion)

Try

formatter.Serialize(stream, myArrayList) <==== FAILS (conditionally)

Catch ex As Exception

MsgBox("Cannot Save")

finally

stream.Close()

End Try

End If

I have a remoting server elsewhere (runs as a service). All objects are serializable and MarshalByRef. I can save fine if I don't "run" my objects on the server, but once I do, I cannot save due to the subject error. Assigning them to the server to run is "ByVal" within the server itself, but since they are MarshalByRef, I think they ByRef anyway. Ok, so I get a genius idea (NOT) and try to send copies to the server (Copy function implemented by us, within each object). Oops. MarshalByRef , I believe, leaves me with the same problem ( ) somehow, though I don't know why, because each object is making new instances of itself within the Copy function.

Ok, so I get another genius idea (NOT), I make new "fresh" objects of the same type, but then I realize that the user sets the properties of the actual ones that are remoted and thus won't be setting the properties of my 2nd set (and no one likes keeping two sets of "books" anyway). Bad, bad design.

Humm... I seem to be stuck.

One more "genius" idea to try: Try to build an array using copies, then serialize to disk.

There are great minds here that solve these types of issues in a flash. I pray someone has some good suggestions for us semi-newbies (ok, new to .NET).

THANKS!





Re: Windows Workflow Foundation Type 'System.Runtime.Remoting.ServerIdentity' is not marked as serializable.

Carl Cook

I just realized that this is in the WF section. For reference, I'm not doing WF stuff, but standard .NET 2.0 using VB 2005.





Re: Windows Workflow Foundation Type 'System.Runtime.Remoting.ServerIdentity' is not marked as serializable.

Carl Cook

I think I've hijacked this thread

I found my problem. *I CAN SAVE NOW* I was not copying a new instance, but the one that had been remoted, of a particular object out of the many; a callback object held between the main objects. Once I corrected that one thorny hidden shrub in the forest, I can copy my objects and I no longer get the error when saving the copies.

Thanks.