By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,458 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,458 IT Pros & Developers. It's quick & easy.

very strange serializtion exception

P: n/a
Hi All,
I had working code that made custom serialization on objects that inherit from queue
in the inherited queue I create my own GetObjectData:
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)

{

lock (this.SyncRoot)

{

IEnumerator Ienum = this.GetEnumerator();

int i = 0;

MyObj _Obj = null;

while (Ienum.MoveNext())

{

i++;

_Obj = (MyObj)Ienum.Current;

info.AddValue("MyObj_" + i.ToString(), Ienum.Current);

}

info.AddValue("Count", i);

info.AddValue("StoreFileName", StoreFileName);

}

}

this code work correctly

after move couple of methods from internal class to the parent class ( I don't speak about the classes that make the serialization , only about the class that call the code that Will cause the serialization in my inherited queue objects )

I start to receive :

Fail: Type 'System.Net.Sockets.Socket' in Assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.
Fail: Type 'System.Net.Sockets.Socket' in Assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable. at System.Runtime.Serialization.FormatterServices.Int ernalGetSerializableMembers(RuntimeType type)
at System.Runtime.Serialization.FormatterServices.Get SerializableMembers(Type type, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitMemberInfo()
at System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
at System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.Serialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
at System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Serialize(Stream serializationStream, Object graph)
at ... -here is my hosted class that call the method that cause the serialization

I don't have any Socket objects not in the my queue class nor in the inside object !

also when debugging step by step the Exception thrown without any control not in specific line!

any suggestions ?

thanks

Oct 20 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Considerig it says

"is not marked as serializable"

You have probably added some dependancy to a class that is not marked as Serializable. Just a thought.
"semedao" <se*****@community.nospamwrote in message news:uy**************@TK2MSFTNGP04.phx.gbl...
Hi All,
I had working code that made custom serialization on objects that inherit from queue
in the inherited queue I create my own GetObjectData:
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)

{

lock (this.SyncRoot)

{

IEnumerator Ienum = this.GetEnumerator();

int i = 0;

MyObj _Obj = null;

while (Ienum.MoveNext())

{

i++;

_Obj = (MyObj)Ienum.Current;

info.AddValue("MyObj_" + i.ToString(), Ienum.Current);

}

info.AddValue("Count", i);

info.AddValue("StoreFileName", StoreFileName);

}

}

this code work correctly

after move couple of methods from internal class to the parent class ( I don't speak about the classes that make the serialization , only about the class that call the code that Will cause the serialization in my inherited queue objects )

I start to receive :

Fail: Type 'System.Net.Sockets.Socket' in Assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.
Fail: Type 'System.Net.Sockets.Socket' in Assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable. at System.Runtime.Serialization.FormatterServices.Int ernalGetSerializableMembers(RuntimeType type)
at System.Runtime.Serialization.FormatterServices.Get SerializableMembers(Type type, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitMemberInfo()
at System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
at System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.Serialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
at System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Serialize(Stream serializationStream, Object graph)
at ... -here is my hosted class that call the method that cause the serialization

I don't have any Socket objects not in the my queue class nor in the inside object !

also when debugging step by step the Exception thrown without any control not in specific line!

any suggestions ?

thanks

Oct 20 '06 #2

P: n/a
Set the debugger to break on any thrown CLR exception. Then go up the
stack to

System.Runtime.Serialization.FormatterServices.Get SerializableMembers(Type
type, StreamingContext context)

and check the locals for "type" to find out what class holds a Socket.
Walk down the stack as necessary, and you'll be able to find out which
of your objects is the culprit.

semedao wrote:
Hi All,
I had working code that made custom serialization on objects that inherit from queue
in the inherited queue I create my own GetObjectData:
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)

{

lock (this.SyncRoot)

{

IEnumerator Ienum = this.GetEnumerator();

int i = 0;

MyObj _Obj = null;

while (Ienum.MoveNext())

{

i++;

_Obj = (MyObj)Ienum.Current;

info.AddValue("MyObj_" + i.ToString(), Ienum.Current);

}

info.AddValue("Count", i);

info.AddValue("StoreFileName", StoreFileName);

}

}

this code work correctly

after move couple of methods from internal class to the parent class ( I don't speak about the classes that make the serialization , only about the class that call the code that Will cause the serialization in my inherited queue objects )

I start to receive :

Fail: Type 'System.Net.Sockets.Socket' in Assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.
Fail: Type 'System.Net.Sockets.Socket' in Assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable. at System.Runtime.Serialization.FormatterServices.Int ernalGetSerializableMembers(RuntimeType type)
at System.Runtime.Serialization.FormatterServices.Get SerializableMembers(Type type, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitMemberInfo()
at System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
at System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.Serialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
at System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Serialize(Stream serializationStream, Object graph)
at ... -here is my hosted class that call the method that cause the serialization

I don't have any Socket objects not in the my queue class nor in the inside object !

also when debugging step by step the Exception thrown without any control not in specific line!

any suggestions ?

thanks

------=_NextPart_000_000C_01C6F477.4B309B00
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-Google-AttachSize: 5221

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2963" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV>
<DIV><FONT face=Arial size=2>Hi All,</FONT></DIV>
<DIV><FONT face=Arial size=2>I had working code that made custom serialization
on objects that inherit from queue</FONT></DIV>
<DIV><FONT face=Arial size=2>in the inherited queue I create my own
GetObjectData:</FONT>
<P><FONT face=Arial size=2>public void GetObjectData(SerializationInfo info,
StreamingContext ctxt)</FONT></P>
<P><FONT face=Arial size=2>{</FONT></P>
<P><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; lock (this.SyncRoot)</FONT></P>
<P><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; {</FONT></P>
<P><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; IEnumerator
Ienum = this.GetEnumerator();</FONT></P>
<P><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int i =
0;</FONT></P>
<P><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MyObj _Obj
= null;</FONT></P>
<P><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while
(Ienum.MoveNext())</FONT></P>
<P><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</FONT></P>
<P><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; i++;</FONT></P>
<P><FONT face=Arial
size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp; _Obj =
(MyObj)Ienum.Current;</FONT></P>
<P><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; info.AddValue("MyObj_" + i.ToString(),
Ienum.Current);</FONT></P>
<P><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</FONT></P>
<P><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
info.AddValue("Count", i);</FONT></P>
<P><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
info.AddValue("StoreFileName", StoreFileName);</FONT></P>
<P><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; }</FONT></P>
<P><FONT face=Arial size=2>}</FONT></P>
<P><FONT face=Arial size=2></FONT>&nbsp;</P>
<P><FONT face=Arial size=2>this code work correctly</FONT></P>
<P><FONT face=Arial size=2>after move couple of methods from internal class to
the parent class&nbsp; ( I don't speak about the classes that make the
serialization , only about the class that call the code that Will cause the
serialization in my inherited queue objects )</FONT></P>
<P><FONT face=Arial size=2>I start to receive :</FONT></P>
<P><FONT face=Arial size=2>Fail: Type 'System.Net.Sockets.Socket' in Assembly
'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is
not marked as serializable.<BR>Fail: Type 'System.Net.Sockets.Socket' in
Assembly 'System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' is not marked as
serializable.&nbsp;&nbsp;&nbsp; at
System.Runtime.Serialization.FormatterServices.Int ernalGetSerializableMembers(RuntimeType
type)<BR>&nbsp;&nbsp; at
System.Runtime.Serialization.FormatterServices.Get SerializableMembers(Type type,
StreamingContext context)<BR>&nbsp;&nbsp; at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitMemberInfo()<BR>&nbsp;&nbsp;
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitSerialize(Type
objectType, ISurrogateSelector surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)<BR>&nbsp;&nbsp; at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.Serialize(Type
objectType, ISurrogateSelector surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)<BR>&nbsp;&nbsp; at
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Write(WriteObjectInfo
objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)<BR>&nbsp;&nbsp; at
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Serialize(Object
graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean
fCheck)<BR>&nbsp;&nbsp; at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Serialize(Stream
serializationStream, Object graph, Header[] headers, Boolean
fCheck)<BR>&nbsp;&nbsp; at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Serialize(Stream
serializationStream, Object graph)<BR>&nbsp;&nbsp; at ... -&gt; here is my
hosted class that call the method that cause the serialization</FONT></P>
<P><FONT face=Arial size=2></FONT>&nbsp;</P>
<P><FONT face=Arial size=2>I don't have any Socket objects not in the my queue
class nor in the inside object !</FONT></P>
<P><FONT face=Arial size=2>also when debugging step by step the Exception thrown
without any control not in specific line!</FONT></P>
<P><FONT face=Arial size=2>any suggestions ?</FONT></P>
<P><FONT face=Arial size=2>thanks</FONT></P></DIV></DIV></BODY></HTML>

------=_NextPart_000_000C_01C6F477.4B309B00--
Oct 20 '06 #3

P: n/a
Hi Semedao,

Based on my understanding, you meet the SerializationException for
'System.Net.Sockets.Socket' class, however, you can not identify which
object in your serialization Queue object referenced to the Socket class.
If I have misunderstood you, please feel free to tell me, thanks.

Martin has provided the correct approach for troubleshooting the root
cause. Below is some additionally information:

As we can see from the stack, the final managed method that caused the
exception is
System.Runtime.Serialization.FormatterServices.Int ernalGetSerializableMember
s method. So I lauched the Reflector tool to view the source code of this
method in .Net2.0 FCL. I find that it is the code snippet below that throws
the SerializationException:

private static MemberInfo[] InternalGetSerializableMembers(RuntimeType type)
{
.......
RuntimeType type1 = (RuntimeType) type.BaseType;
......
Type[] typeArray1 = null;
int num1 = 0;
bool flag1 = FormatterServices.GetParentTypes(type1, out
typeArray1, out num1);
if (num1 <= 0)
{
return infoArray1;
}
list1 = new ArrayList();
for (int num2 = 0; num2 < num1; num2++)
{
type1 = (RuntimeType) typeArray1[num2];
if (!FormatterServices.CheckSerializable(type1))
{
throw new
SerializationException(string.Format(CultureInfo.C urrentCulture,
Environment.GetResourceString("Serialization_NonSe rType"), new object[] {
type1.FullName, type1.Module.Assembly.FullName }));
}
.....
}

Yes, this code snippet logic retrieves the passed in "type"'s "BaseType"
and gets its parent types to fill the "typeArray1" variable. At last, it
will use FormatterServices.CheckSerializable() method to check each element
in the typeArray1. If any element is not serializable it will throw the
SerializationException.

So you should configure the debugger with the correct symbols server and
uncheck the "Just-My-Code" feature of VS2005, so that you can correct break
on the FormatterServices.InternalGetSerializableMembers() when the
exception is thrown.

1. Symbol Server path.
To set the symbol server path, you should input
"srv*c:\LocalSymbols*http://msdl.microsoft.com/download/symbols;" in the
Tools | Options | Debugging | Symbols as the directory. This will tell the
VS2005 debugger to lookup symbol from the Microsoft symbol server
"http://msdl.microsoft.com/download/symbols" and cache the downloaded
symbol in "c:\LocalSymbols" folder.

2. Just My Code setting
VS2005 contains a new feature named "Just-My-Code". Defaultly, JMC is
enabled, which means that VS2005 will not load symbol for non-user code. To
debug non-user code, we should disable this feature from Tools | Options |
Debugging, "Enable Just My Code" check box.(the VS2005 IDE maybe need
close&re-open to enable the
setting)
For more information about JMC, please refer to the blog link below:
"How can I debug Just My Code?"
http://blogs.msdn.com/jmstall/archiv...31/344832.aspx

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 23 '06 #4

P: n/a
Oh, I forget to mention that once the debugger breaks on the
FormatterServices.InternalGetSerializableMembers() method(Use the "Call
Stack" window to verify this), you may open the "Locals" window, it will
report all the local variables with the passed parameters. So you may view
the "type" parameter passed in the InternalGetSerializableMembers() method
to get a clue. If you still can not understand what this type comes from,
you may need to walk down the stack as Martin suggested.

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 23 '06 #5

P: n/a
thanks Jeffrey
I solved it
""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:3u**************@TK2MSFTNGXA01.phx.gbl...
Oh, I forget to mention that once the debugger breaks on the
FormatterServices.InternalGetSerializableMembers() method(Use the "Call
Stack" window to verify this), you may open the "Locals" window, it will
report all the local variables with the passed parameters. So you may view
the "type" parameter passed in the InternalGetSerializableMembers() method
to get a clue. If you still can not understand what this type comes from,
you may need to walk down the stack as Martin suggested.

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Oct 23 '06 #6

P: n/a
Cool, glad to hear that. If you need further help, please feel free to
post, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 24 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.