在ASP.NET ViewState中序列化自定义类型的问题

时间:2022-01-23 15:54:55

I've got a little struct that I want to serialize in my ViewState. It looks something like this:

我有一个小结构,我想在我的ViewState中序列化。它看起来像这样:

[Serializable]
private struct DayMoney
{
    public readonly DateTime ValidFrom;
    public readonly string CurrencyCode;
    public readonly double Amount;
}

It serializes just fine, but when I perform a postback/callback, I get an exception for deserializing it. Wrapped in a long list of InnerException's the root cause seems to be:

序列化很好,但是当我执行回发/回调时,我得到一个异常,用于反序列化它。包含在一长串InnerException中的根本原因似乎是:

Unable to find assembly 'BussinessTripModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

无法找到程序集'BussinessTripModule,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'。

Which is kinda ridiculous, because that assembly is definately loaded in the current AppDomain.

这有点荒谬,因为该程序集肯定会加载到当前的AppDomain中。

WTF?

2 个解决方案

#1


This kind of problems is very difficult to diagnose.

这种问题很难诊断。

My suggestion is to use the Fusion Log Viewer to diagnose why your particular assembly is not found. Keep in mind that some specific options of Fuslogvw that are not so easy to setup, luckily google can help you a lot.

我的建议是使用Fusion Log Viewer来诊断未找到特定程序集的原因。请记住,Fuslogvw的一些特定选项并不容易设置,幸运的是谷歌可以帮助你很多。

But, to start... make your structure public, as someone else said!!!

但是,开始......让你的结构公开,就像别人说的那样!

#2


Your struct is private. Deserialisation happens in the framework itself, not in your assembly. It's probably that's the problem, make it public and see if that solves it

你的结构是私有的。反序列化发生在框架本身,而不是在程序集中。这可能是问题所在,让它公之于众,看看是否能解决问题

#1


This kind of problems is very difficult to diagnose.

这种问题很难诊断。

My suggestion is to use the Fusion Log Viewer to diagnose why your particular assembly is not found. Keep in mind that some specific options of Fuslogvw that are not so easy to setup, luckily google can help you a lot.

我的建议是使用Fusion Log Viewer来诊断未找到特定程序集的原因。请记住,Fuslogvw的一些特定选项并不容易设置,幸运的是谷歌可以帮助你很多。

But, to start... make your structure public, as someone else said!!!

但是,开始......让你的结构公开,就像别人说的那样!

#2


Your struct is private. Deserialisation happens in the framework itself, not in your assembly. It's probably that's the problem, make it public and see if that solves it

你的结构是私有的。反序列化发生在框架本身,而不是在程序集中。这可能是问题所在,让它公之于众,看看是否能解决问题