visual-studio 调试:当类型被标记为可序列化时如何调试“类型未标记为可序列化”异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2611756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:44:29  来源:igfitidea点击:

Debugging: How to debug "Type is not marked as serializable" exception when the type IS marked as serializable

asp.netvisual-studiodebuggingserializationcassini

提问by rism

I'm trying to:

我试图:

((Request.Params["crmid"] != null))

in a web page. But it keeps throwing a serialization exception:

在网页中。但它不断抛出序列化异常:

Type 'QC.Security.SL.SiteUser' in assembly 'QC.Security, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

在程序集“QC.Security, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null”中键入“QC.Security.SL.SiteUser”未标记为可序列化。

The type, a custom IIdentity, is however marked as serializable as follows:

然而,自定义 IIdentity 类型被标记为可序列化,如下所示:

 [Serializable()]
    public class SiteUser : IIdentity
    {
        private long _userId;
        public long UserId { get { return _userId; } set { _userId = value; } }
        private string _name;
        public string Name { get { return _name; } }
        private bool _isAuthenticated;
        public bool IsAuthenticated { get { return _isAuthenticated; } }
        private string _authenticationType;
        public string AuthenticationType { get { return _authenticationType; } }

I've no idea how to debug this as I cant step into the serializer code to find out why its falling over. The call stack is only one frame deep before it hits [External Code]. And the error message is next to useless given that the type is clearly marked as serializable. Trial and error adjustments also produced a Type is not resolved for member exception.

我不知道如何调试它,因为我无法进入序列化程序代码以找出它失败的原因。调用堆栈在到达[外部代码]之前只有一帧深。考虑到类型明确标记为可序列化,错误消息几乎无用。试错调整也产生了一个 Type is not resolve for member 异常。

It was working fine. But now "all of a sudden" it doesn't which typically means some dumb bug in Visual Studio but rebooting doesn't help "this" time. So now I dont know if it's a stupid VS bug or a completely unrelated error for which Im getting a serialization exception or something I'm doing wrong.

它工作正常。但现在“突然”它并不意味着 Visual Studio 中的一些愚蠢的错误,但重新启动对“这次”没有帮助。所以现在我不知道这是一个愚蠢的 VS 错误还是一个完全不相关的错误,我收到了序列化异常或我做错了什么。

The truth is I just dont trust VS anymore given the number of wild goose chases Ive been on over the last several months which were "fixed" by rebooting VS 2008 or some other rediculous workaround.

事实是我只是不再相信 VS,因为我在过去几个月中一直在进行的野鹅追逐的数量通过重新启动 VS 2008 或其他一些可笑的解决方法“修复”。

回答by rism

O.k so I've fixed the problem. It was/is yet another VS / Cassini issue. As per thisurl and thisurl the workaround is to make SiteUser inherit from MarshalByRefObject.

好的,我已经解决了这个问题。这是/现在是另一个 VS / Cassini 问题。根据这个url 和这个url,解决方法是让 SiteUser 从 MarshalByRefObject 继承。

This is neccessary because:

这是必要的,因为:

The issue is that cassini will break into separate AppDomains at will, which doesn't happen in IIS (even though they say it CAN).Because of this, when Atlas is trying to convert to the JSON to something on the server, it does something and switches and the .User custom principal doesn't deserialize because the assembly is not in the GAC and not registered with the other AppDomain.

问题是 cassini 会随意闯入单独的 AppDomain,这在 IIS 中不会发生(即使他们说可以)。因此,当 Atlas 尝试将 JSON 转换为服务器上的某些内容时,它会执行某些操作并进行切换,并且 .User 自定义主体不会反序列化,因为程序集不在 GAC 中且未在其他 AppDomain 中注册。

"Developers developers developers cough"

“开发商开发商开发商咳嗽