2016-03-25 28 views
0

我的應用在一個設備上的某些時段崩潰,出現以下錯誤:無效的URI:指定了無效的端口。無法捕捉當前的堆棧跟蹤domain_UnhandledException System.UriFormatException

問題是,我找不到具體的方法導致此。而且它只在一些德國網絡區域的一臺設備上崩潰。堆棧跟蹤只顯示以下信息:

Current domain_UnhandledException. Stack trace: System.UriFormatException: Invalid URI: Invalid port specified. 
    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) 
    at System.Uri..ctor(String uriString) 
    at HttpServer.HttpClientContext.OnRequestLine(Object sender, RequestLineEventArgs e) 
    at System.EventHandler`1.Invoke(Object sender, TEventArgs e) 
    at HttpServer.Parser.HttpRequestParser.OnFirstLine(String value) 
    at HttpServer.Parser.HttpRequestParser.Parse(Byte[] buffer, Int32 offset, Int32 count) 
    at HttpServer.HttpClientContext.OnReceive(IAsyncResult ar) 
    at System.Net.LazyAsyncResult.Complete(IntPtr userToken) 
    at System.Net.ContextAwareResult.CompleteCallback(Object state) 
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
    at System.Net.ContextAwareResult.Complete(IntPtr userToken) 
    at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken) 
    at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) 
    at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) 

我可以得到一些想法,我怎麼能找到失事源?

+0

我們需要看到你的源代碼,而實際的端口號(錯誤消息的主題),是造成這個問題。 –

+0

崩潰在'HttpServer.HttpClientContext.OnRequestLine'中,它試圖創建一個無效的URI。現在,我們在這裏討論的是哪個'HttpServer'?它不能是'System.Web.Http'中的'HttpServer',因爲它不包含'HttpClientContext'屬性。你的代碼在哪個平臺上運行,它是什麼類型的應用程序? –

+0

源代碼不會幫助,因爲它是一個巨大的應用程序 - 這是一個wpf播放器的服務。 應用程序是x86,並在Windows 7上運行。 我認爲問題出在Assembly HttpServer.dll,v1.0.0.0 –

回答

0

發現新的細節來自:https://github.com/duplicati/httpserver/blob/master/HttpServer/HttpClientContext.cs

private void OnRequestLine(object sender, RequestLineEventArgs e) 
     { 
      _currentRequest.Method = e.HttpMethod; 
      _currentRequest.HttpVersion = e.HttpVersion; 
      _currentRequest.UriPath = e.UriPath; 
      // Initialize _currentRequest.Uri to a synthesized path. This will be the final value if the host header is not sent 
      string authority = _localEndPoint.Address.ToString(); 
      if (_localEndPoint.Port != 80) authority += ":" + _localEndPoint.Port; 
      _currentRequest.Uri = new Uri((IsSecured ? "https://" : "http://") + authority + e.UriPath); 
     } 
+0

此代碼在IPv6地址上失敗,這可能是您的問題。對於IPv6地址,地址部分必須用方括號[]括起來,以包含端口號,而這個代碼不能做到這一點。 –

+0

好主意! (( –

+0

)或者聯繫作者並讓他們修復他們該死的代碼(或者自己提出pull request),或者讓你的網絡人員設置一個IPv6到IPv4隧道,並解釋說你的應用程序在IPv6方面已經崩潰了,除此之外的任何事情都需要你重寫你的應用程序邏輯,這有點超出了本網站的範圍 –