From 4a5a98fac5599fc09dc07b7b3a825e658fa39196 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Tue, 10 May 2022 14:35:17 -0700 Subject: [PATCH] add breaking change --- docs/core/compatibility/7.0.md | 1 + .../7.0/collectible-assemblies.md | 41 +++++++++++++++++++ docs/core/compatibility/toc.yml | 4 ++ 3 files changed, 46 insertions(+) create mode 100644 docs/core/compatibility/core-libraries/7.0/collectible-assemblies.md diff --git a/docs/core/compatibility/7.0.md b/docs/core/compatibility/7.0.md index 90713ef94ba11..6ccf7ccd87981 100644 --- a/docs/core/compatibility/7.0.md +++ b/docs/core/compatibility/7.0.md @@ -29,6 +29,7 @@ If you're migrating an app to .NET 7, the breaking changes listed here might aff | - | :-: | :-: | - | | [API obsoletions with non-default diagnostic IDs](core-libraries/7.0/obsolete-apis-with-custom-diagnostics.md) | ✔️ | ❌ | Preview 1 | | [C++/CLI projects in Visual Studio](core-libraries/7.0/cpluspluscli-compiler-version.md) +| [Collectible Assembly in non-collectible AssemblyLoadContext](core-libraries/7.0/collectible-assemblies.md) | ❌ | ✔️ | Preview 5 | | [FullPath and OldFullPath return fully qualified path](core-libraries/7.0/filesystemeventargs-fullpath.md) | ✔️ | ❌ | Preview 1 | | [Generic type constraint on PatternContext\](core-libraries/7.0/patterncontext-generic-constraint.md) | ❌ | ❌ | Preview 3 | | [SerializationFormat.Binary is obsolete](core-libraries/7.0/serializationformat-binary.md) | ❌ | ❌ | Preview 2 | diff --git a/docs/core/compatibility/core-libraries/7.0/collectible-assemblies.md b/docs/core/compatibility/core-libraries/7.0/collectible-assemblies.md new file mode 100644 index 0000000000000..4032de3ecbe4b --- /dev/null +++ b/docs/core/compatibility/core-libraries/7.0/collectible-assemblies.md @@ -0,0 +1,41 @@ +--- +title: ".NET 7 breaking change: Collectible Assembly in non-collectible AssemblyLoadContext" +description: Learn about the .NET 7 breaking change in core .NET libraries where resolving a collectible Assembly in a non-collectible AssemblyLoadContext results in a FileLoadException. +ms.date: 05/10/2022 +--- +# Collectible Assembly in non-collectible AssemblyLoadContext + +.NET incorrectly allowed garbage-collectible assemblies to resolve into a non-collectible . In some cases, this lead to runtime crashes or unexpected exceptions. This change prevents the incorrect behavior by throwing an exception when the or event returns a collectible and the is non-collectible. + +## Previous behavior + +Returning a collectible in the override or the event of a non-collectible doesn't cause any exceptions to be thrown. + +## New behavior + +Returning a collectible in the override or the event of a non-collectible throws a with a as the inner exception. + +## Version introduced + +.NET 7 Preview 5 + +## Type of breaking change + +This change can affect [binary compatibility](../../categories.md#binary-compatibility). + +## Reason for change + +This change fixes a bug. The collectible would be garbage-collected while the that has a reference to it is alive for the rest of the process lifetime. If the code running in that context references anything from that `Assembly` after it's collected, it would crash the runtime or result in a , , or other kinds of bad behavior. + +## Recommended action + +Don't return collectible assemblies in or the event of a non-collectible . A possible workaround is to change the `AssemblyLoadContext` to be collectible by passing `true` for the `isCollectible` parameter in its constructor, and then keep a reference to that `AssemblyLoadContext` forever to make sure it's never collected. + +## Affected APIs + +- +- event + +## See also + +- [Use collectible AssemblyLoadContext](../../../../standard/assembly/unloadability.md#use-collectible-assemblyloadcontext) diff --git a/docs/core/compatibility/toc.yml b/docs/core/compatibility/toc.yml index d47aecf4d2088..40c9361f85c3b 100644 --- a/docs/core/compatibility/toc.yml +++ b/docs/core/compatibility/toc.yml @@ -43,6 +43,8 @@ items: href: core-libraries/7.0/obsolete-apis-with-custom-diagnostics.md - name: C++/CLI projects in Visual Studio href: core-libraries/7.0/cpluspluscli-compiler-version.md + - name: Collectible Assembly in non-collectible AssemblyLoadContext + href: core-libraries/7.0/collectible-assemblies.md - name: FullPath and OldFullPath return fully qualified path href: core-libraries/7.0/filesystemeventargs-fullpath.md - name: Generic type constraint on PatternContext @@ -729,6 +731,8 @@ items: href: core-libraries/7.0/obsolete-apis-with-custom-diagnostics.md - name: C++/CLI projects in Visual Studio href: core-libraries/7.0/cpluspluscli-compiler-version.md + - name: Collectible Assembly in non-collectible AssemblyLoadContext + href: core-libraries/7.0/collectible-assemblies.md - name: FullPath and OldFullPath return fully qualified path href: core-libraries/7.0/filesystemeventargs-fullpath.md - name: Generic type constraint on PatternContext