diff --git a/src/coreclr/System.Private.CoreLib/src/System/Exception.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Exception.CoreCLR.cs index 81b9be41cdf8..ebd4660a4bc3 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Exception.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Exception.CoreCLR.cs @@ -14,8 +14,6 @@ public partial class Exception : ISerializable { partial void RestoreRemoteStackTrace(SerializationInfo info, StreamingContext context) { - _remoteStackTraceString = info.GetString("RemoteStackTraceString"); // Do not rename (binary serialization) - // Get the WatsonBuckets that were serialized - this is particularly // done to support exceptions going across AD transitions. // @@ -245,8 +243,6 @@ internal void RestoreDispatchState(in DispatchState dispatchState) // See src\inc\corexcep.h's EXCEPTION_COMPLUS definition: private const int _COMPlusExceptionCode = unchecked((int)0xe0434352); // Win32 exception code for COM+ exceptions - private string? SerializationRemoteStackTraceString => _remoteStackTraceString; - private object? SerializationWatsonBuckets => _watsonBuckets; private string? SerializationStackTraceString diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Resources/Strings.resx b/src/coreclr/nativeaot/System.Private.CoreLib/src/Resources/Strings.resx index c65ac77e478f..0a35cbd8d6e0 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Resources/Strings.resx @@ -1137,6 +1137,9 @@ --- End of inner exception stack trace --- + + --- End of stack trace from previous location --- + Exception of type '{0}' was thrown. diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/StackTrace.CoreRT.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/StackTrace.CoreRT.cs index 2c988ad10652..c35ae4ec9e36 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/StackTrace.CoreRT.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/StackTrace.CoreRT.cs @@ -89,14 +89,13 @@ private void InitializeForIpAddressArray(IntPtr[] ipAddresses, int skipFrames, i } #if !TARGET_WASM - internal string ToString(TraceFormat traceFormat) + internal void ToString(TraceFormat traceFormat, StringBuilder builder) { if (_stackFrames == null) { - return ""; + return; } - StringBuilder builder = new StringBuilder(); foreach (StackFrame frame in _stackFrames) { frame.AppendToStackTrace(builder); @@ -104,8 +103,6 @@ internal string ToString(TraceFormat traceFormat) if (traceFormat == TraceFormat.Normal && builder.Length >= Environment.NewLine.Length) builder.Length -= Environment.NewLine.Length; - - return builder.ToString(); } #endif } diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.CoreRT.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.CoreRT.cs index f76d022b179e..c05b05ebc770 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.CoreRT.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.CoreRT.cs @@ -29,7 +29,6 @@ public MethodBase TargetSite private IDictionary CreateDataContainer() => new ListDictionaryInternal(); private string SerializationStackTraceString => StackTrace; - private string SerializationRemoteStackTraceString => null; private string SerializationWatsonBuckets => null; private string CreateSourceName() => HasBeenThrown ? "" : null; @@ -46,21 +45,29 @@ public MethodBase TargetSite private int _HResult; // HResult // To maintain compatibility across runtimes, if this object was deserialized, it will store its stack trace as a string - private string _stackTraceString; + private string? _stackTraceString; + private string? _remoteStackTraceString; // Returns the stack trace as a string. If no stack trace is // available, null is returned. - public virtual string StackTrace + public virtual string? StackTrace { get { - if (_stackTraceString != null) - return _stackTraceString; + string? stackTraceString = _stackTraceString; + string? remoteStackTraceString = _remoteStackTraceString; + // if no stack trace, try to get one + if (stackTraceString != null) + { + return remoteStackTraceString + stackTraceString; + } if (!HasBeenThrown) - return null; + { + return remoteStackTraceString; + } - return StackTraceHelper.FormatStackTrace(GetStackIPs(), true); + return remoteStackTraceString + StackTraceHelper.FormatStackTrace(GetStackIPs(), true); } } @@ -232,12 +239,6 @@ public DispatchState(IntPtr[] stackTrace) } } - [StackTraceHidden] - internal void SetCurrentStackTrace() - { - // TODO: Exception.SetCurrentStackTrace - } - // This is the object against which a lock will be taken // when attempt to restore the EDI. Since its static, its possible // that unrelated exception object restorations could get blocked @@ -289,5 +290,19 @@ internal unsafe byte[] SerializeForDump() return buffer; } } + + // Returns true if setting the _remoteStackTraceString field is legal, false if not (immutable exception). + // A false return value means the caller should early-exit the operation. + // Can also throw InvalidOperationException if a stack trace is already set or if object has been thrown. + private bool CanSetRemoteStackTrace() + { + // Check to see if the exception already has a stack set in it. + if (HasBeenThrown || _stackTraceString != null || _remoteStackTraceString != null) + { + ThrowHelper.ThrowInvalidOperationException(); + } + + return true; // CoreRT runtime doesn't have immutable agile exceptions, always return true + } } } diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj b/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj index 596dc2a75b66..6104c6a83c5c 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj @@ -210,6 +210,9 @@ Internal\TypeSystem\ModuleDesc.cs + + TypeSystem\Common\NotFoundBehavior.cs + Internal\TypeSystem\ParameterizedType.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs index 3c6ba961c79d..47d5b71a306e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs @@ -187,7 +187,6 @@ internal enum TraceFormat TrailingNewLine, // include a trailing new line character } -#if !CORERT /// /// Builds a readable representation of the stack trace, specifying /// the format for backwards compatibility. @@ -199,6 +198,7 @@ internal string ToString(TraceFormat traceFormat) return sb.ToString(); } +#if !CORERT internal void ToString(TraceFormat traceFormat, StringBuilder sb) { // Passing a default string for "at" in case SR.UsingResourceKeys() is true diff --git a/src/libraries/System.Private.CoreLib/src/System/Exception.cs b/src/libraries/System.Private.CoreLib/src/System/Exception.cs index cef527ee50d1..c53561a81713 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Exception.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Exception.cs @@ -47,6 +47,7 @@ protected Exception(SerializationInfo info, StreamingContext context) _innerException = (Exception?)(info.GetValue("InnerException", typeof(Exception))); // Do not rename (binary serialization) _helpURL = info.GetString("HelpURL"); // Do not rename (binary serialization) _stackTraceString = info.GetString("StackTraceString"); // Do not rename (binary serialization) + _remoteStackTraceString = info.GetString("RemoteStackTraceString"); // Do not rename (binary serialization) _HResult = info.GetInt32("HResult"); // Do not rename (binary serialization) _source = info.GetString("Source"); // Do not rename (binary serialization) @@ -110,7 +111,7 @@ public virtual void GetObjectData(SerializationInfo info, StreamingContext conte info.AddValue("InnerException", _innerException, typeof(Exception)); // Do not rename (binary serialization) info.AddValue("HelpURL", _helpURL, typeof(string)); // Do not rename (binary serialization) info.AddValue("StackTraceString", SerializationStackTraceString, typeof(string)); // Do not rename (binary serialization) - info.AddValue("RemoteStackTraceString", SerializationRemoteStackTraceString, typeof(string)); // Do not rename (binary serialization) + info.AddValue("RemoteStackTraceString", _remoteStackTraceString, typeof(string)); // Do not rename (binary serialization) info.AddValue("RemoteStackIndex", 0, typeof(int)); // Do not rename (binary serialization) info.AddValue("ExceptionMethod", null, typeof(string)); // Do not rename (binary serialization) info.AddValue("HResult", _HResult); // Do not rename (binary serialization) diff --git a/src/mono/System.Private.CoreLib/src/System/Exception.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Exception.Mono.cs index bb38f05e371b..490a19699e9f 100644 --- a/src/mono/System.Private.CoreLib/src/System/Exception.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Exception.Mono.cs @@ -143,7 +143,6 @@ private bool CanSetRemoteStackTrace() private static IDictionary CreateDataContainer() => new ListDictionaryInternal(); private static string? SerializationWatsonBuckets => null; - private string? SerializationRemoteStackTraceString => _remoteStackTraceString; private string? SerializationStackTraceString => GetStackTrace(true); } }