我继承了一个电子商务 ASP.NET(c# 代码隐藏)网络应用程序。我们最近移动了服务器,事实证明这有点麻烦。我对 IIS 服务器配置和处理此类大型项目的经验很少。大多数问题现已得到解决,但我们遇到了一个关键部分的问题,因为客户试图付款。
当客户确认付款时,应用程序遇到以下错误:
Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET
will serialize the session state objects, and as a result non-serializable objects or
MarshalByRef objects are not permitted. The same restriction applies if similar
serialization is done by the custom session state store in 'Custom' mode.
堆栈跟踪:
[SerializationException: Type 'PayerAuthentication.PayerAuthenticationServicePost' in Assembly 'PayerAuthentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.]
System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) +7733643
System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) +258
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() +111
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter) +161
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter) +51
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +410
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +134
System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +1577
Google 搜索结果表明我应该添加 [Serializable]
到受影响的类声明,但这是在我没有 csproj 的已编译 dll 中。
代码在以前的服务器上运行良好,我认为没有对代码进行任何更改,仅对 web.config 进行了更改 - 我该怎么办?
web.config 的 session 状态部分显示为 <sessionState mode="StateServer" />
UPDATE1:我使用 Reflector 导出了上面的类,使其可序列化,重新编译并替换了 dll。订购过程更进了一步,于是我遇到了另一个 dll 编译类的相同错误。我又一次能够使用 Reflector 查看代码,然后将其导出、编辑和重新编译。
现在我有同样的错误发生在:
SerializationException: Type 'System.Runtime.Remoting.Messaging.AsyncResult' in Assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.]
我不确定我能对此做些什么,因为这一定是 .net 系统文件的一部分!还有其他想法吗?
UPDATE2:哈,好吧,我随后发现它正在正确处理付款,但随后抛出了上面的 Unable to serialize the session state
System.Runtime.Remoting.Messaging.AsyncResult
上的错误在用户收到交易之前。不好。不确定现在如何前进...
UPDATE3:我尝试创建 System.Runtime.Remoting.Messaging.AsyncResult
的副本类,并使其可序列化,但这会导致不一致的可访问性问题。
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Security.Permissions;
using System.Runtime.Remoting.Messaging;
[Serializable, ComVisible(true)]
public class myAsyncResult : IAsyncResult, IMessageSink
{
// Fields
private AsyncCallback _acbd;
private Delegate _asyncDelegate;
private object _asyncState;
private ManualResetEvent _AsyncWaitHandle;
private bool _endInvokeCalled;
private bool _isCompleted;
private IMessageCtrl _mc;
private IMessage _replyMsg;
// Methods
internal myAsyncResult(Message m);
//[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
public virtual IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink);
private void FaultInWaitHandle();
public virtual IMessage GetReplyMessage();
public virtual void SetMessageCtrl(IMessageCtrl mc);
//[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
public virtual IMessage SyncProcessMessage(IMessage msg);
// Properties
public virtual object AsyncDelegate { get; }
public virtual object AsyncState { get; }
public virtual WaitHandle AsyncWaitHandle { get; }
public virtual bool CompletedSynchronously { get; }
public bool EndInvokeCalled { get; set; }
public virtual bool IsCompleted { get; }
public IMessageSink NextSink { [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)] get; }
}
具体来说,error CS0122: 'System.Runtime.Remoting.Messaging.Message' is inaccessible due to its protection level
.我可以看到这是因为 Message 是一个内部类。但我肯定无法更改它的可访问性级别,因为它是 System.Runtime 命名空间的一部分。制作副本并重命名它肯定会再次引发同样的问题,对吗?
现在有人可以帮助我吗?
最终更新 看起来,毕竟,它是 SSL 证书(见下面我的回答)
最佳答案
如果您真的想要代码,可以尝试使用 Reflector 的类 View 。至少,它可以帮助您验证 [Serializable]
是否是问题类定义的一部分。
关于c# - 编译的dll中的序列化异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1001692/