You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C# 11.0 changes the ref safety rules. These changes are designed to support new scenarios that would previously have required unsafe code. In C# 11.0, we are able to provide the compiler with a more nuanced description of our intentions, and this enables it to recognize certain usage patterns as safe, which it would previously have had to reject as unsafe because its less detailed understanding of our code necessitated a more conservative approach.
Unfortunately, these new safety rules constitute a breaking change for code that makes use of ref struct. The upshot is that the Ais.NET codebase currently does not compile with the .NET 7.0 era SDK.
To participate in the newer, more flexible ref safety rules, it is necessary to provide the compiler with more information. C# 11.0 has introduced a new keyword, scoped for this purpose.
We should add the scoped keyword where necessary to enable the code to compile.
We also need to determine whether doing so causes problems for consumers of our library using pre-C# 11.0 compilation rules. When you build a component that relies on the new rules, the compiler emits a [module: RefSafetyRules(11)] annotation. It's not currently clear to me whether that renders the component unusable by older consumers. There are two possibilities:
older compilers will be unaware of this annotation, and will apply the older, more conservative rules, and that will be OK
libraries compiled under the newer, more flexible ref safety rules cannot be consumed by older compilers that don't know about those rules.
I'm hoping it's 1. If that's the case, we can just add the scoped annotations and make a new release available. But if it's 2, we will need to add a net7.0 target, and use conditional compilation to use these attributes on that target, but not the netstandard2.0 and netstandard2.1 targets.
The text was updated successfully, but these errors were encountered:
C# 11.0 changes the ref safety rules. These changes are designed to support new scenarios that would previously have required unsafe code. In C# 11.0, we are able to provide the compiler with a more nuanced description of our intentions, and this enables it to recognize certain usage patterns as safe, which it would previously have had to reject as unsafe because its less detailed understanding of our code necessitated a more conservative approach.
Unfortunately, these new safety rules constitute a breaking change for code that makes use of
ref struct
. The upshot is that the Ais.NET codebase currently does not compile with the .NET 7.0 era SDK.To participate in the newer, more flexible ref safety rules, it is necessary to provide the compiler with more information. C# 11.0 has introduced a new keyword,
scoped
for this purpose.We should add the
scoped
keyword where necessary to enable the code to compile.We also need to determine whether doing so causes problems for consumers of our library using pre-C# 11.0 compilation rules. When you build a component that relies on the new rules, the compiler emits a
[module: RefSafetyRules(11)]
annotation. It's not currently clear to me whether that renders the component unusable by older consumers. There are two possibilities:I'm hoping it's 1. If that's the case, we can just add the
scoped
annotations and make a new release available. But if it's 2, we will need to add anet7.0
target, and use conditional compilation to use these attributes on that target, but not thenetstandard2.0
andnetstandard2.1
targets.The text was updated successfully, but these errors were encountered: