InvalidCastException的抛出后,安装在新机 [英] InvalidCastException thrown after install on new machine

查看:191
本文介绍了InvalidCastException的抛出后,安装在新机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Visual Studio 2010,C#。

I've been using Visual Studio 2010, C#.

我一直对这个节目将近一年了。在这里面,我用存储在单独的XML文件来构建图像的信息。这一过程已经为我工作没有问题数百次。

I've been working on this program for almost a year now. In it, I'm using information stored in separate XML files to build images. This process has worked for me hundreds of times without a problem.

我已经迁移到一台新机器。在previous机器是32位,新的一个是64位。当我打开一个文件,试图反序列化,下面抛出异常:

I have migrated to a new machine. The previous machine was 32 bit, the new one is 64 bit. When I open a file and attempt to deserialize, the following exception is thrown:

System.InvalidCastException是未处理     消息= [A] System.Collections.Generic.List 1 [BookCreator.pageFontInfo]不能被转换为             [B] System.Collections.Generic.List 1 [BookCreator.pageFontInfo。   键入从A起​​源   mscorlib程序,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089'的背景下,LoadNeither在位置C:\ WINDOWS \ Microsoft.Net \组装\ GAC_64 \ mscorlib程序\ v4.0_4.0.0.0__b77a5c561934e089 \ mscorlib程序.dll文件。 B型的起源   mscorlib程序,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089'的背景下,LoadNeither在位置C:\ WINDOWS \ Microsoft.Net \组装\ GAC_64 \ mscorlib程序\ v4.0_4.0.0.0__b77a5c561934e089 \ mscorlib程序.dll文件。

System.InvalidCastException was unhandled Message=[A]System.Collections.Generic.List1[BookCreator.pageFontInfo] cannot be cast to [B]System.Collections.Generic.List1[BookCreator.pageFontInfo]. Type A originates from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Type B originates from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'.

下面是code生成错误:

Here is the code that generates the error:

        List<pageFontInfo> info;
        XmlSerializer serializer = new XmlSerializer(typeof(List<pageFontInfo>));
        TextReader tr = new StreamReader(openFile);
        info = (List<pageFontInfo>)serializer.Deserialize(tr); <---error thrown

pageFontInfo是内置序列化结构的自定义。它包含两个字符串,float,并且点的列表。我不知道是怎么了。我比较了列表的两个始发,并且它们是相同的。我完全难住了。这在迁移之前工作过上百次了过去。

pageFontInfo is a custom built Serializable struct. It contains two strings, a float, and a list of points. I have no idea what is going wrong. I've compared the two "originations" of the lists, and they are identical. I'm totally stumped. This has worked hundreds of times in the past before the migration.

编辑: 我只是检查。我同时运行已编译的.exe和源$ C ​​$另一台计算机上,这是64位C。所以,无论是哪里错了,现在没有什么关系了。这是具体到本次安装的Visual Studio 2010。

I just checked. I've run both the compiled .exe and source code on another machine that was 64 bit. So whatever is going wrong now does not have anything to do with that. It's specific to this installation of Visual Studio 2010.

推荐答案

找到了!我开始通过我的code步进,发现两个相同的组件实际上是不同的实例。我一直在使用该程序作为类库的网站。因此,在工作目录是项目的同时,当开始调试过程中创建的.exe文件一个.dll。

Found it! I started stepping through my code and found that the two identical assemblies were actually different instances. I've been using the program as a class library for a web site. So in the working directory was a .dll of the project along with the .exe created when beginning the debug process.

在负载时,程序加载这两个.dll和.exe文件。我所要做的就是进入工作目录,并删除它们。然后,错误走了。

On load, the program was loading both the .dll, and the .exe. All I had to do was go into the working directory, and delete them both. Then the error went away.

这篇关于InvalidCastException的抛出后,安装在新机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆