Tja da frag ich mich ewig warum die ‚DownloadStringAsyn‚-Methode der ‚WebClient‚-Klasse von .Net mir eine NullReferenz Exception zurück gibt und am Ende muss ich feststellen, dass es an meiner URL lag… Von vorne:
Ich versuche mit der ‚DownloadStringAsync‘-Methode die browser.html von ‚MPC-HC‚ abzurufen um so die dort aufgeführten Werte in der dazugehörigen Windows Phone 7 App zu verarbeiten. Dies aber funktioniert nie, da ich immer eine NullReferenz Exception zurückbekomme.
So sieht z.B. eine der aufgerufenen URLs aus:
http://10.41.2.2:13579/browser.html?path=C:\Users\username\Desktop
Das Problem?
Die ‚DownloadStringAsync‘-Methode kommt nicht mit den Backslash’s klar und wirft eine absolut nichts sagende Exception.
Die Lösung?
‚MPC-HC‘ akzeptiert es auch, wenn man den Pfad Namen durch Slash’s trennt. Und schon läufts 🙂 Dies ist natürlich kein Bugfix sondern lediglich ein Workaround. Der Bug selbst ist hier schon bei Microsoft gemeldet.
[Update]: Ok, ich habe nun ein gut funktionierenden Workaround gefunden, man muss nur alle Backslashs mit „%5C“ ersetzen dann klappt alles wie gewollt.
Exception Message Ausschnitt:
- error {"An exception occurred during a WebClient request. "} System.Exception {System.Net.WebException} + [System.Net.WebException] {"An exception occurred during a WebClient request. "} System.Net.WebException _data null System.Collections.IDictionary _HResult -2146233079 int - _innerException {""} System.Exception _data null System.Collections.IDictionary _HResult -2146233088 int + _innerException {"0x80000012"} System.Exception _message "" string + _methodDescs {System.IntPtr[9]} System.IntPtr[] _optionalData null object[] + Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal} HResult -2146233088 int - InnerException {"0x80000012"} System.Exception _data null System.Collections.IDictionary _HResult -2146233088 int _innerException null System.Exception _message "0x80000012" string + _methodDescs {System.IntPtr[15]} System.IntPtr[] _optionalData null object[] + Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal} HResult -2146233088 int InnerException Der Ausdruck konnte nicht ausgewertet werden. System.Exception Message "0x80000012" string StackTrace " at MS.Internal.XcpImports.CheckHResult(UInt32 hr)\r\n at MS.Internal.XcpImports.WebRequest_Send(InternalWebRequest request)\r\n at MS.Internal.InternalWebRequest.Send()\r\n at System.Net.Browser.ClientHttpWebRequest.PrepareAndSendRequest(String method, Uri requestUri, Stream requestBodyStream, WebHeaderCollection headerCollection, CookieContainer cookieContainer)\r\n at System.Net.Browser.ClientHttpWebRequest.BeginGetResponseImplementation()\r\n at System.Net.Browser.ClientHttpWebRequest.InternalBeginGetResponse(AsyncCallback callback, Object state)\r\n at System.Net.Browser.ClientHttpWebRequest.BeginGetResponse(AsyncCallback callback, Object state)\r\n at System.Net.WebClient.DownloadBits(WebRequest request, Stream writeStream, CompletionDelegate completionDelegate, AsyncOperation asyncOp)\r\n at System.Net.WebClient.DownloadStringAsync(Uri address, Object userToken)\r\n at MPC_Remote.MainPage.button1_Click(Object sender, RoutedEventArgs e)\r\n at System.Windows.Controls.Primitives.ButtonBase.OnClick()\r\n at System.Windows.Controls.Button.OnClick()\r\n at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)\r\n at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)\r\n at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)\r\n" string Message "" string StackTrace " at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)\r\n at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)\r\n at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)\r\n at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)\r\n at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassa.b__8(Object state2)\r\n at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state)\r\n at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.ThreadPool.WorkItem.doWork(Object o)\r\n at System.Threading.Timer.ring()\r\n" string _message "An exception occurred during a WebClient request. " string + _methodDescs {System.IntPtr[17]} System.IntPtr[] _optionalData null object[] + Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal} HResult -2146233079 int + InnerException {""} System.Exception Message "An exception occurred during a WebClient request. " string StackTrace " at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()\r\n at System.Net.DownloadStringCompletedEventArgs.get_Result()\r\n at MPC_Remote.MainPage.client_DownloadStringCompleted(Object sender, DownloadStringCompletedEventArgs e)\r\n at System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e)\r\n at System.Net.WebClient.DownloadStringOperationCompleted(Object arg)\r\n at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)\r\n at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)\r\n at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)\r\n at System.Delegate.DynamicInvokeOne(Object[] args)\r\n at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)\r\n at System.Delegate.DynamicInvoke(Object[] args)\r\n at System.Windows.Threading.DispatcherOperation.Invoke()\r\n at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)\r\n at System.Windows.Threading.Dispatcher.OnInvoke(Object context)\r\n at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)\r\n at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)\r\n at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)\r\n" string