我們有混合的C#和VB.NET(3.5)項目網絡解決方案(注:一些vb.net文件確實有選項嚴格關閉)。我們的代碼作爲DotNetNuke 4.8中的模塊運行。在某些情況下,我們的應用程序會崩潰的方法:序列化投擲的ArgumentException/InvalidCastException的:調試方法需要
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteString
在例外的縮短的消息是:
System.ArgumentException: "Error serializing value XYZ of type XYZ."
System.InvalidCastException: "Unable to cast object of type 'System.Int64'
to 'System.String'"
在堆棧跟蹤
無處是我們的代碼,它是最終只是系統代碼未能從我們的代碼序列化類型XYZ
。這意味着我不能打破一個斷點並調試XYZ的哪個確切屬性是問題。堆棧跟蹤屬性爲空,但在消息簡稱爲堆棧跟蹤:
DotNetNuke.Services.Exceptions.PageLoadException: "Error serializing value 'XYZ' of type 'XYZ.'"
System.ArgumentException: "Error serializing value 'XYZ' of type 'XYZ.'"
System.InvalidCastException: "Unable to cast object of type 'System.Int64' to type 'System.String'. "
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteString(NameInfo memberNameInfo, NameInfo typeNameInfo, Object stringObject)
// ...... etc.........
at System.Web.UI.Page.SaveAllState()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
// --- End of inner exception stack trace
在此跟蹤的所有相關線路開始System.
。頂行是DotNetNuke。但是,在第一個答案的建議之後,我自己編譯了DotNetNuke(4.8)代碼,結果發現代碼只是Server.GetLastError
,顯示InvalidCastException爲InnerException,沒有任何有關正在序列化的實際值或屬性名稱的附加信息。
接下來的問題是:我該如何發現串行器遇到麻煩的字段和值?
一些相關的問題/來考慮問題,而研究這個問題:
- 如果我看MSDN的Formatters.Binary部分我猜的ObjectWriter是內部二進制(如意見提出,紅色)?
- .NET甚至可以在將Int64轉換爲String時失敗?重述:Int64的值可能不會轉換爲字符串?但是,正如評論中所指出的那樣:Int64可以很容易地轉換爲字符串,但鑄造它們是一個不同的問題。
- 的Serialize方法不宣佈這一ArgumentException的或可能會出現InvalidCastException的(在例外部分)。
我試圖調查XYZ
和ildasm該類中的屬性類型,以查看任何違規行爲但找不到任何。
'(字符串)42L'引發InvalidCastException,也是如此任何其他Int64值。 Int64值不能被轉換爲'string'。 (儘管你可以使用'Convert.ToString(42L)'或'42L.ToString()'將它轉換爲'string'。) – dtb
ObjectWriter是'System.Runtime'中的'internal'類。 Serialization.Formatters.Binary'命名空間。 – dtb
嗯謝謝你的有用評論!說得通。想想我會更新這部分的問題。 – Jeroen