【问题标题】:Telerik Grid Setting working with a web-site project but not with a web-applicationTelerik Grid Setting 适用于网站项目,但不适用于 Web 应用程序
【发布时间】:2019-04-18 18:35:51
【问题描述】:

我有一个需要转换为网络应用程序的网站项目。在解决了所有编译错误后,我在从Telerik's website 获得的一段代码中遇到了运行时异常。

在我反序列化网格设置数据的部分我得到一个异常

System.ArgumentException
  HResult=0x80070057
  Message=The serialized data is invalid.
  Source=BMS.WebApp
Inner Exception 1:
SerializationException: Unable to find assembly 'App_Code.5gd62bdt, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
public static GridSettingsCollection LoadFromSerializedData(string data)
        {
            LosFormatter formatter = new LosFormatter();
            // the line that throws the exception: formatter.Deserialize(data)
            return (GridSettingsCollection)formatter.Deserialize(data);
        }

当它是一个网站项目时,这没有问题。我猜以 App_Code.* 开头的程序集通常意味着它正在运行时编译。我尝试清除所有 ASP 临时文件夹。

非常感谢任何帮助。谢谢。

【问题讨论】:

    标签: c# asp.net telerik


    【解决方案1】:

    这不是 Telerik 本身的问题,而是一般的序列化问题。 Telerik 示例中的GridSettingsCollection 使用[Serializable] 属性,而该属性又使用BinaryFormatter 进行序列化。除了二进制对象数据,它还存储序列化对象的类元数据,包括程序集名称。

    如果更改程序集名称(在将网站转换为 Web 应用程序时发生)并且仍需要使用旧的序列化数据,则必须使用 SerializationBinder,如 this answer

    【讨论】:

    • 但是如果 Telerik 在后台使用 BinaryFormatter,我如何将 binaryFormatter.Binder 强制执行到我创建的新方法?
    猜你喜欢
    • 1970-01-01
    • 2022-06-21
    • 1970-01-01
    • 2018-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多