星期一, 12月 02, 2013

[Debug]Remoting遇上轉型不能

環境: WinFrom base on .net 4.5 & Enterprise Librayr 5.0 & Remoting

Remoting的程式在執行的時候遇到了這樣子的錯誤。
"Specified cast is not valid"
說是轉型的時候遇到了失敗,
到底是怎麼發生的呢? 具體來說我也是不太清楚XD


場景還原的話,就是客戶端程式執行的時候,
只要爆出Exception後,接下來的程式都會遇到轉型失敗的問題。
如果沒遇到Exception的話,程式倒是可以一直順利執行...

來看一下完整的錯誤訊息...

An exception of type 'System.Reflection.TargetInvocationException' occurred and was caught.-------------------------------------------------------------------------------------------11/28/2013 18:03:19Type : System.Reflection.TargetInvocationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089Message : Exception has been thrown by the target of an invocation.Source : mscorlibHelp link :Data : System.Collections.ListDictionaryInternalTargetSite : Void SerializationInvoke(System.IRuntimeMethodInfo, System.Object, System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext ByRef)HResult : -2146232828Stack Trace :Server stack trace:   at System.RuntimeMethodHandle.SerializationInvoke(IRuntimeMethodInfo method, Object target, SerializationInfo info, StreamingContext& context)   at System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context)   at System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder holder)   at System.Runtime.Serialization.ObjectManager.DoFixups()   at System.Runtime.Serialization.Formatters.Soap.ObjectReader.Deserialize(HeaderHandler handler, ISerParser serParser)   at System.Runtime.Serialization.Formatters.Soap.SoapFormatter.Deserialize(Stream serializationStream, HeaderHandler handler)   at System.Runtime.Remoting.Channels.CoreChannel.DeserializeSoapRequestMessage(Stream inputStream, Header[] h, Boolean bStrictBinding, TypeFilterLevel securityLevel)   at System.Runtime.Remoting.Channels.SoapServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)
Exception rethrown at [0]:   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)   at 

Additional Info:

     Inner Exception     ---------------     Type : System.InvalidCastException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089     Message : Specified cast is not valid.     Source : mscorlib     Help link :     Data : System.Collections.ListDictionaryInternal     TargetSite :     HResult : -2147467262     Stack Trace :    at System.Runtime.Remoting.Messaging.LogicalCallContext..ctor(SerializationInfo info, StreamingContext context)

從錯誤上簡單來解讀的話就是Remoting的序列化轉型失敗了。

至於怎麼解決呢...
在google上找了好久,總算讓我找到這篇跟我遇上的情境,
幾乎是一模一樣的...


照著上面說的,關掉了Enterprise Library Logging Block區段當中的
TraceEnable設定成false就解決了這樣的問題~ 呼~ 

至於為什麼會這樣,其實我也不是很了解,
只能透過
這篇文章大概的知道似乎是Logging Block的trace功能影響到了remoting時的序列化,
才會造成這樣的錯誤。
總之,問題解決了~
可喜可賀~ 可喜可賀~

沒有留言: