public void SerializableExceptionTest()
    {
        var message         = "Foo Bar Buzz";
        var innerMessage    = "Inner Foo Bar Buzz";
        var innerStackTrace = "";

        Exception ex;
        string?   stackTrace;

        try
        {
            try
            {
                throw new OperationCanceledException(innerMessage);
            }
            catch (Exception inner)
            {
                innerStackTrace = inner.StackTrace;
                throw new InvalidOperationException(message, inner);
            }
        }
        catch (Exception x)
        {
            stackTrace = x.StackTrace;
            ex         = x;
        }

        var serializableException = ex.ToSerializableException();
        var base64string          = SerializableException.ToBase64String(serializableException);
        var result = SerializableException.FromBase64String(base64string);

        Assert.Equal(message, result.Message);
        Assert.Equal(stackTrace, result.StackTrace);
        Assert.Equal(typeof(InvalidOperationException).FullName, result.ExceptionType);

        Assert.Equal(innerMessage, result.InnerException?.Message);
        Assert.Equal(innerStackTrace, result.InnerException?.StackTrace);
        Assert.Equal(typeof(OperationCanceledException).FullName, result.InnerException?.ExceptionType);

        var serializableException2 = ex.ToSerializableException();

        Assert.Equal(serializableException, serializableException2);
    }
    public static void Invoke(Exception exceptionToReport)
    {
        try
        {
            var serializedException   = exceptionToReport.ToSerializableException();
            var base64ExceptionString = SerializableException.ToBase64String(serializedException);
            var args = $"crashreport -exception=\"{base64ExceptionString}\"";

            var path = Process.GetCurrentProcess().MainModule?.FileName;
            if (string.IsNullOrEmpty(path))
            {
                throw new InvalidOperationException($"Invalid path: '{path}'");
            }

            ProcessStartInfo startInfo = ProcessStartInfoFactory.Make(path, args);
            using Process? p = Process.Start(startInfo);
        }
        catch (Exception ex)
        {
            Logger.LogWarning($"There was a problem while invoking crash report: '{ex}'.");
        }
    }
示例#3
0
 /// <summary>
 /// Sets the exception when it occurs the first time and should be reported to the user.
 /// </summary>
 public void SetException(Exception ex)
 {
     SerializedException   = ex.ToSerializableException();
     Base64ExceptionString = SerializableException.ToBase64String(SerializedException);
     HadException          = true;
 }