Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw NotSupportedException when using SetErrorStatusOnException in Mono Runtime and Native AOT environment. #5374

Merged
merged 23 commits into from
Mar 2, 2024
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/OpenTelemetry/Trace/ExceptionProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

using System.Diagnostics;
using System.Runtime.InteropServices;
#if !NET6_0_OR_GREATER && !NETFRAMEWORK
#if NET6_0_OR_GREATER || NETFRAMEWORK
using System.Runtime.CompilerServices;

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Tests)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Tests)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Api.Tests)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Api.Tests)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check warning on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-stable

Using directive is unnecessary.

Check warning on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format-experimental

Using directive is unnecessary.
#else
using System.Linq.Expressions;
using System.Reflection;
#endif
Expand All @@ -19,7 +21,14 @@
public ExceptionProcessor()
{
#if NET6_0_OR_GREATER || NETFRAMEWORK
this.fnGetExceptionPointers = Marshal.GetExceptionPointers;
if (RuntimeFeature.IsDynamicCodeSupported)

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Tests)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Tests)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Api.Tests)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Api.Tests)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-stable

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / validate-packages / run-package-validation-experimental

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)

The name 'RuntimeFeature' does not exist in the current context

Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs

View workflow job for this annotation

GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)

The name 'RuntimeFeature' does not exist in the current context
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (RuntimeFeature.IsDynamicCodeSupported)
bool getExceptionPointersSupported = true;
try { Marshal.GetExceptionPointers(); } catch { getExceptionPointersSupported = false; }
if (!getExceptionPointersSupported)
throw new throw new NotSupportedException($"'{typeof(Marshal).FullName}.GetExceptionPointers' is not supported.");

Instead of calling RuntimeFeature.IsDynamicCodeSupported, can this just call the API to see whether it is supported?

Note that this API is also not supported in Mono (irrespective of whether IsDynamicCodeSupported is true or false), so it would cover the Mono.

Copy link
Contributor Author

@Yun-Ting Yun-Ting Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would it take to actually support the API in native AOT?

Yes, it should be possible to simulated the API in native AOT. The API would need to allocate a piece of memory with the same lifetime as the current exception in flight (if it was not previously allocated), fill it with gunk, and return the pointer to it. The "new" exception handling that is being enabled for CoreCLR and that is not internally based on SEH proves that it is possible.

(Also, as I have said earlier - introducing a new API that is explicitly designed for this scenario would be the proper solution.)

Thank you! I agree above is the proper way to handle the situation. Shall I log this feature request in the runtime repo?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall I log this feature request in the runtime repo?

Yes, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've filed a request to implement the API in runtime: dotnet/runtime#98878.
Chatted with @eerhardt, @jkotas and @reyang offline.

While the above API is being implemented, we may do the followings to avoid crashing the consumer's app:

  1. Annotate SetErrorStatusOnException() with [RequiresDynamicCode] to serve as a compile time warning for the consumer. One caveat of this approach is IsDynamicCode does not really explain the nature of this issue and may further confuse the consumer.
  2. Use try/catch to swallow the exception if users hit System.PlatformNotSupportedException upon calling Marshal.GetExceptionPointer(). Store the state in ExceptionProcessor() and dump the Message "Exception processor not supported" inside OnEnd(Activity activity).

Not sure which one is a better stopgap of this issue?
cc @MichalStrehovsky, @agocke

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed in today's SIG meeting.
I'll go with adding the compile time warning as was mentioned in 1. above.
Plus, guarding the extension method

public TracerProviderBuilder SetErrorStatusOnException(bool enabled)

with a try/catch on Marshal.GetExceptionPointers to avoid adding useless Processor at runtime (if user ever decided to suppress the compile time AOT warning.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to add try/catch block. We just have to call Marshal.GetExceptionPointers() once in the ExceptionProcessor ctor and rethrow the exception with our custom message.

@CodeBlanch Just to confirm this is what you suggested, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with either re-throwing or just silently failing & not adding the processor. Probably re-throwing is better to alert the users 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on re-throwing the exception at start-up.

{
throw new NotSupportedException($"'{typeof(Marshal).FullName}.GetExceptionPointers' is not supported when running native AOT.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to make this a build time error? I think that will help the developers to discover the issue earlier.

}
else
{
this.fnGetExceptionPointers = Marshal.GetExceptionPointers;
}
#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.
Expand Down
Loading