开发者

InvalidCastException thrown after install on new machine

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

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.

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 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 'LoadNeit开发者_如何转开发her' at location 'C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'.

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 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.

Edit: 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.


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.

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.


I understand your problem i think your code is not a managed code Your code should target the CLR. if you done that correctly your code can work anywhere No matter whether it is 32 bit or a 64 bit machine.

I may be wrong but try managed code in c# you will get Solution.

All the best

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜