diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md
index 9c8f3dc863f..2958b18487d 100644
--- a/src/OpenTelemetry/CHANGELOG.md
+++ b/src/OpenTelemetry/CHANGELOG.md
@@ -2,12 +2,17 @@
## Unreleased
+* Throw NotSupportedException when using `SetErrorStatusOnException` method for
+ Tracing in Mono Runtime and Native AOT environment because the dependent
+ `Marshal.GetExceptionPointers()` API is not supported on these platforms.
+ ([#5374](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5374))
+
* Fixed an issue where `LogRecord.Attributes` (or `LogRecord.StateValues` alias)
could become out of sync with `LogRecord.State` if either is set directly via
the public setters. This was done to further mitigate issues introduced in
1.5.0 causing attributes added using custom processor(s) to be missing after
upgrading. For details see:
- [#5169](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5169)
+ ([#5169](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5169))
* Fixed an issue where `SimpleExemplarReservoir` was not resetting internal
state for cumulative temporality.
diff --git a/src/OpenTelemetry/Trace/Builder/TracerProviderBuilderExtensions.cs b/src/OpenTelemetry/Trace/Builder/TracerProviderBuilderExtensions.cs
index 76f23be65f4..a4c39becf16 100644
--- a/src/OpenTelemetry/Trace/Builder/TracerProviderBuilderExtensions.cs
+++ b/src/OpenTelemetry/Trace/Builder/TracerProviderBuilderExtensions.cs
@@ -24,6 +24,12 @@ public static class TracerProviderBuilderExtensions
/// .
/// Enabled or not. Default value is true.
/// Returns for chaining.
+ ///
+ /// This method is not supported in native AOT or Mono Runtime as of .NET 8.
+ ///
+#if NET7_0_OR_GREATER
+ [RequiresDynamicCode("The code for detecting exception and setting error status might not be available.")]
+#endif
public static TracerProviderBuilder SetErrorStatusOnException(this TracerProviderBuilder tracerProviderBuilder, bool enabled = true)
{
tracerProviderBuilder.ConfigureBuilder((sp, builder) =>
diff --git a/src/OpenTelemetry/Trace/ExceptionProcessor.cs b/src/OpenTelemetry/Trace/ExceptionProcessor.cs
index 815670792d1..f0084d36cfb 100644
--- a/src/OpenTelemetry/Trace/ExceptionProcessor.cs
+++ b/src/OpenTelemetry/Trace/ExceptionProcessor.cs
@@ -23,19 +23,13 @@ public ExceptionProcessor()
#else
// When running on netstandard or similar the Marshal class is not a part of the netstandard API
// but it would still most likely be available in the underlying framework, so use reflection to retrieve it.
- try
- {
- var flags = BindingFlags.Static | BindingFlags.Public;
- var method = typeof(Marshal).GetMethod("GetExceptionPointers", flags, null, Type.EmptyTypes, null)
- ?? throw new InvalidOperationException("Marshal.GetExceptionPointers method could not be resolved reflectively.");
- var lambda = Expression.Lambda>(Expression.Call(method));
- this.fnGetExceptionPointers = lambda.Compile();
- }
- catch (Exception ex)
- {
- throw new NotSupportedException($"'{typeof(Marshal).FullName}.GetExceptionPointers' is not supported", ex);
- }
+ var flags = BindingFlags.Static | BindingFlags.Public;
+ var method = typeof(Marshal).GetMethod("GetExceptionPointers", flags, null, Type.EmptyTypes, null)
+ ?? throw new InvalidOperationException("Marshal.GetExceptionPointers method could not be resolved reflectively.");
+ var lambda = Expression.Lambda>(Expression.Call(method));
+ this.fnGetExceptionPointers = lambda.Compile();
#endif
+ this.fnGetExceptionPointers(); // attempt to access pointers to test for platform support
}
///