Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions docs/core/compatibility/11.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ See [Breaking changes in ASP.NET Core 11](/aspnet/core/breaking-changes/11/overv

| Title | Type of change |
|-------------------------------------------------------------------|-------------------|
| [Assembly.GetCallingAssembly behavior changes when stack trace support is disabled](core-libraries/11/assembly-getcallingassembly-stacktracesupport-disabled.md) | Behavioral change |
| [CborReader and CborWriter enforce a default maximum nesting depth](core-libraries/11/cbor-max-depth.md) | Behavioral change |
| [CRC32 validation added when reading ZIP archive entries](core-libraries/11/ziparchive-entry-crc32-validation.md) | Behavioral change |
| [DateOnly and TimeOnly TryParse methods throw for invalid input](core-libraries/11/dateonly-timeonly-tryparse-argumentexception.md) | Behavioral change |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: "Breaking change: Assembly.GetCallingAssembly behavior changes when stack trace support is disabled"
description: "Learn about the breaking change in .NET 11 where Assembly.GetCallingAssembly can throw NotSupportedException when stack trace support is disabled."
ms.date: 08/03/2026
ai-usage: ai-assisted
---

# Assembly.GetCallingAssembly behavior changes when stack trace support is disabled

<xref:System.Reflection.Assembly.GetCallingAssembly?displayProperty=nameWithType> now supports Native AOT and uses stack trace data to resolve the caller. If stack trace support is disabled, the method now throws <xref:System.NotSupportedException> on both Native AOT and CoreCLR.

## Version introduced

.NET 11 Preview 7

## Previous behavior

Previously, on Native AOT, <xref:System.Reflection.Assembly.GetCallingAssembly?displayProperty=nameWithType> always threw <xref:System.PlatformNotSupportedException>. Previously, on CoreCLR, the method returned the calling assembly even if `StackTraceSupport` was set to `false`.

## New behavior

Starting in .NET 11, on Native AOT, <xref:System.Reflection.Assembly.GetCallingAssembly?displayProperty=nameWithType> returns the calling assembly by inspecting stack trace data. Starting in .NET 11, on both Native AOT and CoreCLR, the method throws <xref:System.NotSupportedException> if `StackTrace.IsSupported` is `false`, for example when the `StackTraceSupport` feature switch is set to `false`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Waiting to see if StackTrace.IsSupported can be an xref or what exactly it refers to.


The exception message is:

> Unable to retrieve stack trace information when StackTraceSupport feature switch is set to false.

## Type of breaking change

This change is a [behavioral change](../../categories.md#behavioral-change).

## Reason for change

To return a correct caller, <xref:System.Reflection.Assembly.GetCallingAssembly?displayProperty=nameWithType> requires stack trace data. If stack trace support is unavailable, the runtime can't determine the caller reliably. The runtime now throws <xref:System.NotSupportedException> instead of returning an incorrect result. For Native AOT support details, see [dotnet/runtime#129963](https://github.com/dotnet/runtime/pull/129963).

## Recommended action

If you publish with `StackTraceSupport` set to `false` and your app calls <xref:System.Reflection.Assembly.GetCallingAssembly?displayProperty=nameWithType>, expect <xref:System.NotSupportedException>. Use one of these options:

- Enable stack trace support by removing the switch or setting `StackTraceSupport` to `true`.
- Remove calls to <xref:System.Reflection.Assembly.GetCallingAssembly?displayProperty=nameWithType>.
- Catch <xref:System.NotSupportedException> and handle the fallback path explicitly.

## Affected APIs

- <xref:System.Reflection.Assembly.GetCallingAssembly?displayProperty=fullName>
2 changes: 2 additions & 0 deletions docs/core/compatibility/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ items:
href: 11.md
- name: Core .NET libraries
items:
- name: Assembly.GetCallingAssembly behavior change when stack-trace support disabled
href: core-libraries/11/assembly-getcallingassembly-stacktracesupport-disabled.md
- name: CborReader and CborWriter enforce a default maximum nesting depth
href: core-libraries/11/cbor-max-depth.md
- name: CRC32 validation added when reading ZIP archive entries
Expand Down
2 changes: 1 addition & 1 deletion docs/core/deploying/trimming/trimming-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Several feature areas of the framework libraries come with trimmer directives th
| `MetadataUpdaterSupport` | When set to `false`, removes metadata update&ndash;specific logic related to hot reload. |
| `MetricsSupport` | When set to `false`, removes support for <xref:System.Diagnostics.Metrics> instrumentation. |
| `StackTraceLineNumberSupport` (.NET 11+) | (`PublishAot` only.) When set to `true`, generates additional line number information in the output executable module. Stack traces (for example, <xref:System.Environment.StackTrace?displayProperty=nameWithType> and <xref:System.Exception.ToString*?displayProperty=nameWithType>) will include information about file names and line numbers at runtime. This information is similar to the information generated into debugging symbol files (PDB/DWO/dSYM files). However, for apps published with `PublishAot`, the runtime doesn't read the native symbol files and the debugging symbols are only used by debuggers. |
| `StackTraceSupport` (.NET 8+) | When set to `false`, removes support for generating stack traces (for example, <xref:System.Environment.StackTrace?displayProperty=nameWithType> or <xref:System.Exception.ToString*?displayProperty=nameWithType>) by the runtime. The amount of information that is removed from stack trace strings might depend on other deployment options. This option does not affect stack traces generated by debuggers. |
| `StackTraceSupport` (.NET 8+) | When set to `false`, removes support for generating stack traces (for example, <xref:System.Environment.StackTrace?displayProperty=nameWithType> or <xref:System.Exception.ToString*?displayProperty=nameWithType>) by the runtime. Methods that require stack trace data, such as <xref:System.Reflection.Assembly.GetCallingAssembly?displayProperty=nameWithType>, throw <xref:System.NotSupportedException> in .NET 11 and later when this option is `false`. The amount of information that is removed from stack trace strings might depend on other deployment options. This option does not affect stack traces generated by debuggers. |
| `UseNativeHttpHandler` | When set to `true`, uses the default platform implementation of <xref:System.Net.Http.HttpMessageHandler> for Android and iOS and removes the managed implementation. |
| `UseSizeOptimizedLinq` (.NET 10+) | When set to `true`, removes some of the throughput optimizations in LINQ that adversely affect the size of the application. Defaults to `true` with `PublishAot`; it might not be possible to natively compile some applications with this property set to `false`. |
| `UseSystemResourceKeys` | When set to `true`, strips exception messages for `System.*` assemblies. When an exception is thrown from a `System.*` assembly, the message is a simplified resource ID instead of the full message. |
Expand Down
Loading