我有一个奇怪的问题,自己无法解决。我的MVP项目中的一个类被设计成单例模式,却导致了一个InvalidCastException
异常。
错误的源头在于这段代码,其中反序列化对象被赋值给该类的实例变量:engineObject = (ENGINE)xSerializer.Deserialize(str);
。每当我尝试将我的UserControl之一添加到Form或不同的UC时,这个异常就会出现。所有我的UC都有一个特殊的presenter,它访问上述单例类的实例变量。
这是我尝试在某个地方添加UC时得到的:
'System.TypeInitializationException: The type initializer for 'MVP.Model.EngineData' threw an exception. ---->
System.InvalidCastException: [A]Engine cannot be cast to [B]Engine. Type A originates from 'MVP.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither'
at location '[...]\AppData\Roaming\Microsoft\VisualStudio\9.0\ProjectAssemblies\uankw1hh01\MVP.Model.dll'.
Type B originates from 'MVP.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither'
at location '[...]\AppData\Roaming\Microsoft\VisualStudio\9.0\ProjectAssemblies\u_hge2de01\MVP.Model.dll'
...
我有两个程序集,它们并不来自我的项目文件夹,而是来自 VS 临时文件夹?我搜索了很多,只找到了这个:IronPython 异常:[A]Person 无法转换为 [B]Person。有一个解决方案,但它涉及 IronPhyton,我不知道在我的项目中该在哪里使用它。