我一直在使用Visual Studio 2010 C#。在新機器上安裝後拋出InvalidCastException
我一直在爲這個計劃工作近一年了。其中,我使用存儲在單獨的XML文件中的信息來構建圖像。這個過程已經爲我工作了數百次,沒有任何問題。
我已經遷移到新機器。以前的機器是32位,新的是64位。當我打開一個文件,並試圖反序列化,下面的異常被拋出:
System.InvalidCastException was unhandled Message=[A]System.Collections.Generic.List
1[BookCreator.pageFontInfo] cannot be cast to [B]System.Collections.Generic.List
1[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'.
這裏是產生錯誤代碼:
List<pageFontInfo> info;
XmlSerializer serializer = new XmlSerializer(typeof(List<pageFontInfo>));
TextReader tr = new StreamReader(openFile);
info = (List<pageFontInfo>)serializer.Deserialize(tr); <---error thrown
pageFontInfo是一個定製的序列化結構。它包含兩個字符串,一個浮點數和一個點列表。我不知道發生了什麼問題。我比較了列表的兩個「起源」,它們是相同的。我完全被難住了。在遷移之前,這在過去已經運行了數百次。
編輯: 我剛查過。我在另一臺64位的機器上運行了編譯後的.exe和源代碼。所以現在不管發生什麼事都與此無關。這是特定於Visual Studio 2010的安裝。
我相信這是一些參考問題,你有什麼東西放在'GAC'這是造成一些歧義? – V4Vendetta