private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // This form created to obtain UI synchronization context only using (new Form()) { // Store the shared JoinableTaskContext ThreadHelper.JoinableTaskContext = new JoinableTaskContext(); } // If an error happens before we had a chance to init the environment information // the call to GetInformation() from BugReporter.ShowNBug() will fail. // There's no perf hit calling Initialise() multiple times. UserEnvironmentInformation.Initialise(ThisAssembly.Git.Sha, ThisAssembly.Git.IsDirty); SerializableException?exception = null; string[] args = Environment.GetCommandLineArgs(); foreach (string arg in args) { string xml; try { xml = Base64Decode(arg); } catch (Exception ex) { exception = new(new Exception($"Failed to decode the error payload\r\n{arg}", ex)); continue; } try { exception = SerializableException.FromXmlString(xml); } catch (Exception ex) { exception = new(new Exception($"Failed to decode/parse error payload\r\n{xml}", ex)); } } // No specific info extracted from these exceptions string exceptionInfo = ""; exception ??= new(new Exception("Missing error payload")); new BugReportForm().ShowDialog(owner: null, exception, exceptionInfo, UserEnvironmentInformation.GetInformation(), canIgnore: true, showIgnore: false, focusDetails: false); }
public void Should_show_load_exception_info_correctly() { string path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"MockData/SimpleException.txt"); string content = File.ReadAllText(path); SerializableException exception = SerializableException.FromXmlString(content); RunFormTest( form => { Assert.AreEqual(exception.Message, form.GetTestAccessor().ExceptionMessageTextBox.Text); Assert.AreEqual(exception.Type, form.GetTestAccessor().ExceptionTextBox.Text); Assert.AreEqual(exception.TargetSite, form.GetTestAccessor().TargetSiteTextBox.Text); ListView listView = form.GetTestAccessor().ExceptionDetails.GetTestAccessor().ExceptionDetailsListView; Assert.AreEqual(10, listView.Items.Count); int index = 0; Assert.AreEqual("Exception", listView.Items[index].Text); Assert.AreEqual(exception.Type, listView.Items[index].SubItems[1].Text); index++; Assert.AreEqual("Message", listView.Items[index].Text); Assert.AreEqual(exception.Message, listView.Items[index].SubItems[1].Text); index++; Assert.AreEqual("Target Site", listView.Items[index].Text); Assert.AreEqual(exception.TargetSite, listView.Items[index].SubItems[1].Text); index++; Assert.AreEqual("Inner Exception", listView.Items[index].Text); Assert.AreEqual(exception.InnerException.Type, listView.Items[index].SubItems[1].Text); index++; Assert.AreEqual("Source", listView.Items[index].Text); Assert.AreEqual(exception.Source, listView.Items[index].SubItems[1].Text); index++; Assert.AreEqual("Stack Trace", listView.Items[index].Text); Assert.AreEqual(exception.StackTrace, listView.Items[index].SubItems[1].Text); foreach (var info in exception.ExtendedInformation) { index++; Assert.AreEqual(info.Key, listView.Items[index].Text); Assert.AreEqual(info.Value.ToString(), listView.Items[index].SubItems[1].Text); } // Count=1-based, index=0-based Assert.AreEqual(listView.Items.Count - 1, index); }, exception, exceptionInfo: "", environmentInfo: ""); }
public void ToString_should_be_same_from_round_trip(string testName, Action action) { using (ApprovalResults.ForScenario(testName)) { string message = string.Empty; string xml = string.Empty; try { action(); } catch (Exception ex) { xml = new SerializableException(ex).ToXmlString(); } SerializableException exception = SerializableException.FromXmlString(xml); Approvals.Verify(Sanitize(exception.ToString())); } }