1

BinaryFormatter によって作成されたファイルを逆シリアル化しようとすると、次の例外がスローされます。

ArgumentException: 同じキーを持つアイテムが既に追加されています。

スタック トレースは BinaryFormatter の Deserialize メソッドから始まりますが、衝突の原因となっているコード内のクラスを特定できません。

[Serializable]属性でマークされた 100 以上のクラスをシリアル化しています

原因が重複した名前を持つフィールドに関連している可能性があることを示唆する別の質問を見ました。ただし、100以上のクラス間で衝突を引き起こしているフィールドを見つけることができず、コードを手作業で調べる以外に、それを追跡するより効率的な方法を知りません。

すべてのクラスのフィールドを手動で調べる以外に、この問題のデバッグを開始するより良い方法はありますか? そもそも衝突の別の原因があるのでしょうか? この問題に関する洞察を提供していただければ幸いです。

例外内容

System.ArgumentException was unhandled
  Message=An item with the same key has already been added.
  Source=mscorlib
  StackTrace:
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.OnDeserialization(Object sender)
   at System.Runtime.Serialization.DeserializationEventHandler.Invoke(Object sender)
   at System.Runtime.Serialization.ObjectManager.RaiseDeserializationEvent()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
   at SPX.Saves.Save`1.Read() in .\SPX.Save\Save.cs:line 42
   at OGUR.States.MainMenuState.Update() in .\OGUR\OGUR\States\MainMenuState.cs:line 64
   at SPX.States.StateManager.Update() in .\SPX.States\StateManager.cs:line 30
   at OGUR.Game.Update(GameTime gameTime) in .\OGUR\OGUR\Game.cs:line 63
   at Microsoft.Xna.Framework.Game.Tick()
   at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
   at Microsoft.Xna.Framework.GameHost.OnIdle()
   at Microsoft.Xna.Framework.WindowsGameHost.RunOneFrame()
   at Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e)
   at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at Microsoft.Xna.Framework.WindowsGameHost.Run()
   at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
   at Microsoft.Xna.Framework.Game.Run()
   at OGUR.EntryPoint.Main(String[] args) in .\OGUR\OGUR\EntryPoint.cs:line 15
InnerException: 
4

0 に答える 0