RE: OptionalFieldAttribute not needed with BinaryFormatter in .net

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi Andy,

Thanks for your feedback!

Yes, with your sample project, I can reproduce out this strange behavior.

I have performed some deeper debugging regarding this issue. I found that
the FileNotFoundException is generated by Assembly.GetType, which is
finally invoked by
System.Runtime.Serialization.FormatterServices.GetTypeFromAssembly.

By setting breakpoint at
System.Runtime.Serialization.FormatterServices.GetTypeFromAssembly and
performing some tracing, I found that this method is invoked several times.
Each time for a type, so it will loop through the deserialization object
and call FormatterServices.GetTypeFromAssembly for each child type in this
object.

Also, the exception is generated when using
FormatterServices.GetTypeFromAssembly for a strange type name:
"System.Collections.Generic.KeyValuePair`2[[System.String, mscorlib,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089],[DemoDictionarySerializeIssue.Item,
DemoDictionarySerializeIssue, Version=1.0.0.4, Culture=neutral,
PublicKeyToken=3379bf4a1aba6400]]"

Since the currently debugging assembly version is 1.0.0.5, while
Assembly.GetType is trying to retrieve Version=1.0.0.4, it will attempt to
locate assembly with strong name below:
"DemoDictionarySerializeIssue, Version=1.0.0.4, Culture=neutral,
PublicKeyToken=3379bf4a1aba6400"

However, this assembly is changed to 1.0.0.5, so the loading fails.

So this issue seems to be with Generic of .Net2.0. I am not sure if this
issue is a bug or not. I will try to contact our CLR team regarding it.
Thanks.

Additionally, I found that without strong name to sign the assembly, it
will eliminate this issue, do you have any special request to strong name
the assembly?

Regarding the caching application block issue, I will also try to consult
internally and hope there is some workaround for it. I will get back to you
ASAP. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

.