###前提・実現したいこと
こんにちは。いつもたいへんお世話になります。
###発生している問題・エラーメッセージ
自作のUWPアプリケーションで、nullエラーで困っています。
場所を特定したいのですが、特定できずにいます。
こういうとき、どうするれば場所を特定できるでしょうか?
たとえばConsoleだとMainのなかをtry-catch
WPFなら、InitializerかWindow_Loadedでぜんぶをtry-catch
とかで、たいていぜんぶの処理を網羅できます。
UWPの場合は、いわゆるMainに相当するものが見当たらず。
コンストラクタなのか、OnNavigatedToなのか、Page_Loadedなのか、あるいはぜんぜん違うのか。
スレッド 0x1398 はコード 0 (0x0) で終了しました。 Exception thrown: 'System.NullReferenceException' in uwp.exe プログラム '[4208] uwp.exe' はコード -1 (0xffffffff) で終了しました。
ちなみに処理としては、ボタンクリックで、httpclientを読んで、非同期で処理しています。
C#
1public async void httpsend(string message) { 2 try { 3 client = new HttpClient(); 4 client.BaseAddress = new Uri(uri); 5 var content = new FormUrlEncodedContent(new Dictionary<string, string> 6 { 7 { "id", id }, 8 { "body", message } 9 }); 10 11 var response = await client.PostAsync(client.BaseAddress, content);// これのさなかに落ちる。 12 } 13 catch (Exception exception) { 14 Debug.WriteLine(exception.Message);//しかしここには来ない。 15 } 16}
C#
1App.g.i.cs 2 partial class App : global::Windows.UI.Xaml.Application 3 { 4 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks"," 14.0.0.0")] 5 private bool _contentLoaded; 6 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks"," 14.0.0.0")] 7 [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 8 public void InitializeComponent() 9 { 10 if (_contentLoaded) 11 return; 12 13 _contentLoaded = true; 14#if DEBUG && !DISABLE_XAML_GENERATED_BINDING_DEBUG_OUTPUT 15 DebugSettings.BindingFailed += (sender, args) => 16 { 17 global::System.Diagnostics.Debug.WriteLine(args.Message); 18 }; 19#endif 20#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION 21 UnhandledException += (sender, e) => 22 { 23 if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();//ここにくる。 24 }; 25#endif 26 }
###補足情報(言語/FW/ツール等のバージョンなど)
Windows10 Home 1709 64bit
Microsoft Visual Studio Community 2017
Version 15.1 (26403.3) Release
VisualStudio.15.Release/15.1.0+26403.3
Microsoft .NET Framework
Version 4.7.02556
インストールされているバージョン:Community
Visual C# 2017 00369-60000-00001-AA631
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/18 13:00