Closed Aniobodo closed 1 year ago
The API change from public static ref T AsRef<T>(in T source)
to public static ref T AsRef<T>(ref readonly T source)
was approved in https://github.com/dotnet/runtime/issues/85911#issuecomment-1624189321 and merged in https://github.com/dotnet/runtime/pull/89736 on 2023-08-02.
scoped
had already been added between .NET 6.0 and .NET 7.0.
Is a PlatformNotSupportedException actually thrown at run time? Although the C# code includes throw new PlatformNotSupportedException();
, the C++ code should replace the method body with a different one so that the throw
is never executed.
[Intrinsic]
: https://github.com/dotnet/runtime/blob/92959931a32a37a19d8e1b1684edc6db0857d7de/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/Unsafe.cs#L662-L678METHOD__UNSAFE__AS_REF_IN
: https://github.com/dotnet/runtime/blob/92959931a32a37a19d8e1b1684edc6db0857d7de/src/coreclr/vm/corelib.h#L674GM_RefT_RetRefT
: https://github.com/dotnet/runtime/blob/92959931a32a37a19d8e1b1684edc6db0857d7de/src/coreclr/vm/metasig.h#L301METHOD__UNSAFE__AS_REF_IN
: https://github.com/dotnet/runtime/blob/92959931a32a37a19d8e1b1684edc6db0857d7de/src/coreclr/vm/jitinterface.cpp#L6808-L6822https://dotnet.microsoft.com/en-us/download/dotnet/8.0 says .NET SDK 8.0.100-rc.1 supports "Visual Studio 2022 (v17.8 latest Preview)".
https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/8.0/version-requirements however says "Versions 8.0.1xx of the .NET SDK require Visual Studio version 17.7 and MSBuild version 17.7."
@KalleOlaviNiemitalo thanks for the citations. Now with VS 2022 17.8.0 Preview: I did not get an exception at runtime. Also, the compiler Error CS1620 does not show up. So I hope that the final release of .NET 8/VS 2022 17.8.0 will be okay.
Going to close this as it's fixed when using a supported VS version for the SDK in use.
Describe the bug
In .NET 7, there is the method ref T AsRef(in T source); in the Unsafe class. I use this method basically for large readonly structs.
Now in .NET 8 RC1, that method is missing and instead there is ref T AsRef(scoped ref readonly T source);
This new method in .NET 8 is empty and throws PlatformNotSupportedException exception.
In VS, the compiler displays Error CS1620 when the new method in .NET is used like this: Unsafe.AsRef(ref ReadOnlyStructInstance)
I did not find any information regarding this change, so:
To Reproduce
Exceptions (if any)
Further technical details
VS 2022 Version 17.7.4