Comments (8)
> dotnet --list-sdks
3.1.426 [C:\Program Files\dotnet\sdk]
5.0.203 [C:\Program Files\dotnet\sdk]
5.0.214 [C:\Program Files\dotnet\sdk]
5.0.406 [C:\Program Files\dotnet\sdk]
5.0.408 [C:\Program Files\dotnet\sdk]
5.0.416 [C:\Program Files\dotnet\sdk]
6.0.203 [C:\Program Files\dotnet\sdk]
6.0.300 [C:\Program Files\dotnet\sdk]
6.0.407 [C:\Program Files\dotnet\sdk]
8.0.201 [C:\Program Files\dotnet\sdk]
MSBuild is using SDK version 6.0.203.
from cswin32.
The Unsafe.Add
is a bit of a red herring here, from a ref safety standpoint the method looks like this:
internal ref T this[int index]
{
[UnscopedRef]
get => ref this.e0;
}
I guess the older compiler didn't know how to respect the [UnscopedRef] attribute
That is correct. The attribute was added in .NET 7 so the .NET 6 compiler doesn't attach any special meaning to it. From the perspective of .NET 6 compiler this method has no attribute and is a ref safety violation.
That's trouble though, because the source generator isn't told what the compiler version is, I think. I'll have to get the roslyn team's take on it.
Think it would be better to look at the language version than compiler version. That is available through parse options on the source files. In this case the language version is 9.0 which doesn't support ref fields, [UnscopedRef]
, etc ... That should be enough to know when this pattern is / isn't safe to code gen.
Note: in November the .NET 6 SDK goes out of support and at that time all supported compilers will be able to use these attributes. This pattern might be tricky to emit in older compilers.
from cswin32.
I can't repro the problem. Can you provide a minimal repro project?
I couldn't repro even when targeting net5.0-windows as you mentioned. But FYI, we probably won't fix any bugs that are unique to that target framework, since the runtime itself is no longer supported by Microsoft.
from cswin32.
cswin32-issue1205-repro.zip
The issue only occurs when building with Visual Studio 2019. I wasn't able to reproduce it in VS Code.
from cswin32.
Oh! In that case I suspect the issue is the .NET SDK version you're compiling with. Can you type dotnet --list-sdks
or otherwise tell me which SDK version you're using? VS2019 is a clue, but it isn't definitive.
from cswin32.
Great. I got it by using the 6.0.423 SDK and C# lang version 9. Investigating further...
from cswin32.
The C# language version isn't what does it. It's just the compiler version. The compiler that ships in .NET SDK 6.0.x fails where .NET SDK 8's compiler works. I guess the older compiler didn't know how to respect the [UnscopedRef]
attribute. I suspect the only workaround we can make in the source generator will be to avoid emitting the VariableLengthInlineArray<T>
type for that version of the compiler. That's trouble though, because the source generator isn't told what the compiler version is, I think. I'll have to get the roslyn team's take on it.
from cswin32.
With .NET Framework this also causes problems. If you don't include the latest System.Runtime.CompilerServices.Unsafe
package it fails to build with:
Error (active) CS0117 'Unsafe' does not contain a definition for 'SkipInit'
from cswin32.
Related Issues (20)
- IShellItemImageFactory.GetImage should return HRESULT HOT 1
- Add support for MAKEPOINTS, GET_X_LPARAM, GET_Y_LPARAM macros HOT 1
- APPBARDATA should compile on AnyCPU HOT 2
- CsWin32 should avoid Unsafe.SkipInit when it doesn't exist in the compilation HOT 1
- WlanOpenHandle doesn't support SafeHandle HOT 1
- The API "Gdi32" is ambiguous HOT 4
- Add `GET_WHEEL_DELTA_WPARAM` macro
- `TASKDIALOGCONFIG.pfCallback` should use associated enum for `msg` parameter
- NetFramework - Unsafe.SkipInit(out T value) unavailable HOT 3
- Inconsistent const in parameters of RmRegisterResources HOT 9
- LocalExternFunctions should use `DefaultDllImportSearchPaths`
- Code Quality: Use `WinMdRoot` instead of `winmdroot` to supress CS8981 (type name is ASCII lowercase only) HOT 5
- `PCWSTR` is not marked with `[GeneratedCode]`
- Many Win32 structs (HDC, HMONITOR, etc.) lack the IntPtr conversion operator.
- "Pointers cannot reference marshaled structures. Use ByRef instead" caused by VariableLengthInlineArray
- Latest WDK metadata fails to create DEVPKEY field
- Daily nuget feed not updating HOT 1
- IPropertyStoreCapabilities has no way to return its value
- MFTEnumEx signature incorrect
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cswin32.