C# 编译dll中的序列化异常

C# 编译dll中的序列化异常,c#,asp.net,web-applications,serialization,dll,C#,Asp.net,Web Applications,Serialization,Dll,我继承了一个电子商务ASP.NET(c代码隐藏)web应用程序。我们最近移动了服务器,这有点麻烦。我对IIS服务器配置和处理此类大型项目的经验很少。大多数问题现在都已解决,但我们在一个关键部分遇到了问题,因为客户试图付款。 当客户确认付款时,应用程序遇到以下错误: Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session

我继承了一个电子商务ASP.NET(c代码隐藏)web应用程序。我们最近移动了服务器,这有点麻烦。我对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
谷歌搜索结果表明,我应该向受影响的类声明添加
[Serializable]
,但这是在一个已编译的dll中,我没有csproj。 代码在以前的服务器上运行良好,我不相信对代码做了任何更改,只对web.config做了更改-我能做什么

web.config的sessionstate部分显示

更新1:使用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:哈,我后来发现它正确地处理了付款,但是在用户收到交易之前,抛出了上面的
无法序列化会话状态的
错误
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; }
    }
具体地说,错误CS0122:“System.Runtime.Remoting.Messaging.Message”由于其保护级别而无法访问。我可以看出这是因为Message是一个内部类。但我肯定不能更改它的可访问性级别,因为它是System.Runtime命名空间的一部分。复制并重命名它肯定会再次引发同样的问题?
现在有人能帮我吗

最终更新
看起来,在所有这些之后,它是SSL证书(请参见下面的答案)

您需要了解新服务器是旧服务器的更新版本,还是旧服务器的旧版本。如果它是一个旧版本,那么升级到新版本,事情就应该正常了


如果是较新的,那么是您的代码(您有源代码)将这些不可序列化的对象置于会话状态吗?如果是这样,那么您可以创建自己的类来镜像旧类的属性。使类可序列化,并将类的实例置于会话状态。当您退出会话状态时,创建旧类的实例。

如果代码以前仅使用内存状态提供程序,则这可能是。。。棘手的当默认提供程序不需要时,序列化过程(通过数据库状态提供程序使用的
BinaryFormatter
)需要
[Serializable]
属性,这是一个难点

你能编辑多少代码?有吗?例如,您可以更改使事物进入/脱离状态的代码吗?您也许可以使用具有必要属性的单独(可序列化)DTO,并使用自己的代码在它们之间进行转换

其他选择:

  • 返回内存中的提供程序(并向集群挥手告别)
  • 编写一个不使用BinaryFormatter的提供程序

我对后者有一些想法,但我怀疑这会是微不足道的

如果您真的想要代码,可以尝试使用Reflector的类视图。至少,它可以帮助您验证
[Serializable]
是否是问题类定义的一部分。

如果问题只是如何使应用程序在没有此错误的情况下运行,快速解决方案是将sessionState元素的mode属性设置为“InProc”.

我现在认为,当我们安装新的SSL证书时,出现了这个问题

新证书有邮政编码扩展,我们的支付商户汇丰银行不接受通过其CPI支付网关进行扩展


安装正确的SSL证书似乎终于解决了这个问题。

问题是什么?否,我需要应用程序正常工作,而不是在没有错误的情况下运行。将seesionState更改为“InProc”会导致在向购物车添加产品时不更新购物车!这真是太棒了。我使用Reflector导出代码,将
[Serializable]
添加到类中,编译它,用新的dll覆盖现有的dll,解决了眼前的问题,尽管另一个类现在触发了相同的错误。我也将为这个类(以及任何辅助类)重复这个过程。很高兴它有帮助。这正是我认为如果缺少属性就是问题所在,你可以做的。是的,确实解决了眼前的问题(实际上是两次),但现在我被困在原始帖子的更新中)服务器版本是相同的:2.0.50727.3082