天天看點

C#程式“System.ArgumentOutOfRangeException: 不是有效的 Win32 FileTime”問題解決問題:解決:

問題:

    C#程式在使用hessian調用java程式時報“System.ArgumentOutOfRangeException: 不是有效的 Win32 FileTime”異常,該異常不是每次都出現,而是在選擇日期範圍不同時會出現。

Exception by proxy call
System.ArgumentOutOfRangeException: 不是有效的 Win32 FileTime。
參數名: fileTime
   在 System.DateTime.FromFileTimeUtc(Int64 fileTime)
   在 hessiancsharp.io.CHessianInput.ReadObject()
   在 hessiancsharp.io.CMapDeserializer.ReadMap(AbstractHessianInput abstractHessianInput)
   在 hessiancsharp.io.CSerializerFactory.ReadMap(AbstractHessianInput abstractHessianInput, String strType)
   在 hessiancsharp.io.CHessianInput.ReadObject()
   在 hessiancsharp.io.CMapDeserializer.ReadMap(AbstractHessianInput abstractHessianInput)
   在 hessiancsharp.io.CSerializerFactory.ReadMap(AbstractHessianInput abstractHessianInput, String strType)
   在 hessiancsharp.io.CHessianInput.ReadObject()
   在 hessiancsharp.io.CObjectDeserializer.ReadMap(AbstractHessianInput abstractHessianInput, Object result)
   在 hessiancsharp.io.CObjectDeserializer.ReadMap(AbstractHessianInput abstractHessianInput)
   在 hessiancsharp.io.CHessianInput.ReadObject(Type expectedType)
   在 hessiancsharp.io.CCollectionDeserializer.ReadGenericList(AbstractHessianInput abstractHessianInput)
   在 hessiancsharp.io.CCollectionDeserializer.ReadList(AbstractHessianInput abstractHessianInput, Int32 intListLength)
   在 hessiancsharp.io.CHessianInput.ReadObject(Type expectedType)
   在 hessiancsharp.io.CHessianInput.ReadReply(Type expectedType)
   在 hessiancsharp.client.CHessianMethodCaller.DoHessianMethodCall(Object[] arrMethodArgs, MethodInfo methodInfo)不是有效的 Win32 FileTime。
參數名: fileTime
           

解決:

   hessian調用傳回的是一個清單,輸入參數有起始時間,經過反複測試,隻是在某個時間段才會發生該異常。通過二分法逐漸縮小範圍,定位到一天的資料,這天資料中有一條記錄的日期為“0001-01-03 00:00:00.0”,該日期看起來不怎麼正常,通過查詢資料得知,Hessian中處理時間時,當時間早于1601年1月1日時,産生異常錯誤(見後面的參考連結)。

  将改條資料修改為2018年,錯誤消失。

  這個問題最後的解決雖然很簡單,連程式都不用改,但是查找問題原因卻花費了很多的時間。在排查問題時,還是應該從相關性來考慮,既然報錯為日期錯誤,就應該首先圍繞日期排查問題的所在,前面一直在考慮是不是記錄數過多的問題(因為縮小時間範圍就不報錯),而真正的原因是:縮小時間範圍,有問題的記錄沒有被包含在内。

參考:

http://digital.ni.com/public.nsf/allkb/880D1CF3D1A6810286257B9700483B07