如何调试(步入)BinaryFormatter.Deserialize()? [英] How to debug (step into) BinaryFormatter.Deserialize()?
问题描述
我的应用尝试反序列化客户端发送的数据,并且失败,出现以下错误:
抛出异常:
' System.Runtime.Serialization.SerializationException'in mscorlib.dll
附加信息:无法获取成员'< .ctor> b__0'。
googling没有结果。好的,我决定我会进入反序列化逻辑,并试图找出究竟是什么导致的。嗯,一天过去了,我没有任何关系。
我使用了
My app tries to deserialize data sent by client and it fails with the following error:
Exception thrown: 'System.Runtime.Serialization.SerializationException' in mscorlib.dll
Additional information: Cannot get the member '<.ctor>b__0'.
googling gives no results. Okay, I decided I would step into deserialization logic and try to figure out what exactly is causing this. Well, a day has passed and I'm nowhere close.
I used instructions from Microsoft Reference Source website to configure Visual Studio. It does download something
MicrosoftPublicSymbols\mscorlib.pdb\
DCF1E4D31F6944AC87E7A634262BEE881\mscorlib.pdb (780kb)
E47257B512BA49BC9FC367C532FC5F1E2\mscorlib.pdb (953kb)
but debugger does not step in.
I googled more and found another way to do it - installed dotTrace app and used it as source server. And that does not help either. I still see the following:
Symbol Load Information
popup for mscorlib.pdb says
C:\Users\me\AppData\Local\Temp\SymbolCache\MicrosoftPublicSymbols\mscorlib.pdb\e47257b512ba49bc9fc367c532fc5f1e2\mscorlib.pdb: Symbols loaded.
I can step in into System.Windows.Forms, System.Linq, etc - so generally speaking, it works - it just this particular call to BinaryFormatter.Deserialize()
does not work. What could be the reasons for that and how can I get it to step into?
Could it be because of SecuritySafeCritical
attribute?
[System.Security.SecuritySafeCritical]
public Object Deserialize(Stream serializationStream)
I'm using VS 2015 .Net 4.5.2 (though I tried 4.5 with the same results).
Without any details i can assume this is compatibility issue with versions of objects you trying to serialize & deserialize. Looks like client sends you some old object bits(without lambda in constructor). And your server running newer version of software searching for some lambda method.
<.ctor>b__0 - is method name for first lambda method in .ctor (object constructor).
So for example if you had on client's machine object A:
class A {
public A() {
int a = 5;
int b = 7;
// Plain code, no lambdas
}
}
Then you updated your class on server introducing lambda in constructor:
class A {
public A() {
int a = 5;
int b = 7;
Func<int,int> some = x => x * 2 + a;
}
}
After that their binary representation is not the same, server version of A has private invisible method <.ctor>b__0 in it.
这篇关于如何调试(步入)BinaryFormatter.Deserialize()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!