调试:如何调试“类型未标记为可序列化”当类型标记为可序列化时出现异常

发布于 2024-08-28 07:41:30 字数 1128 浏览 0 评论 0原文

我正在尝试:

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

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

在中键入“QC.Security.SL.SiteUser” 装配'QC.Security, 版本=1.0.0.1,文化=中立, PublicKeyToken=null' 未标记为 可序列化。

然而,该类型(自定义 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; } }

我不知道如何调试它,因为我无法进入序列化程序代码以找出其失败的原因。在到达[外部代码]之前,调用堆栈只有一帧深。考虑到该类型被明确标记为可序列化,该错误消息几乎毫无用处。试错调整还产生了“类型未解决成员异常”。

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

事实是,我只是不再信任 VS,因为过去几个月里我进行了多次徒劳的追逐,这些问题都通过重新启动 VS 2008 或其他一些可笑的解决方法“修复”了。

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.

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

 [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.

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽容 2024-09-04 07:41:30

好的,我已经解决了这个问题。这是另一个 VS / 卡西尼号问题。根据 url 和 url 解决方法是让 SiteUser继承自 MarshalByRefObject。

这是必要的,因为:

问题是卡西尼号会破裂
随意进入单独的AppDomains,
这在 IIS 中不会发生(甚至
尽管他们说可以)。
因为
当 Atlas 试图转换时
到 JSON 到
服务器,它做一些事情并切换
并且 .User 自定义主体没有
反序列化,因为程序集是
不在 GAC 中且未注册
另一个应用程序域。

“开发者开发者开发者咳嗽

O.k so I've fixed the problem. It was/is yet another VS / Cassini issue. As per this url and this url the workaround is to make SiteUser inherit from 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.

"Developers developers developers cough"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文