Closed RFBomb closed 3 weeks ago
See also #1199
@riQQ - glad I'm not the only one. The repo I'm working on has a super-basic console app, so I tested that real quick as a minimal-reproduceable project, and it was not able to be reproduced!!
This seems to be resolved by nuget package 0.3.106
, which generates Windows.Win32.VariableLengthInlineArray<T>
instead
Closing this as A) it appears to be a duplicate, and B) updating the nuget pkg for this library resolved the issue.
Thanks for the quick response!
Just for reference here, here is the generated code:
Net462
internal struct VariableLengthInlineArray<T>
where T : unmanaged
{
internal T e0;
[UnscopedRef]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal Span<T> AsSpan(int length)
{
unsafe
{
fixed (void* p = &this.e0)
{
return new Span<T>(p, length);
}
}
}
}
Net8.0
internal struct VariableLengthInlineArray<T>
where T : unmanaged
{
internal T e0;
internal ref T this[int index]
{
[UnscopedRef]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => ref Unsafe.Add(ref this.e0, index);
}
[UnscopedRef]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal Span<T> AsSpan(int length)
{
return MemoryMarshal.CreateSpan(ref this.e0, length);
}
}
Actual behavior
Windows.Wdk.byte.InlineArrays.g.cs
andWindows.Wdk.char.InlineArrays.g.cs
both cause project to not build due toRelevant section of CSWin32 : https://github.com/microsoft/CsWin32/blob/66fe74557fb1412085f01be9cd27c20e7af97de8/src/Microsoft.Windows.CsWin32/Generator.InlineArrays.cs#L608
Note : This ONLY occurs if using the System.Memory Nuget package!
Generated Code: (with System.Memory)
Generated code without System.Memory ( Note how the error occurs, even though the line doesn't exist! )![image](https://github.com/microsoft/CsWin32/assets/20431767/997bc15b-30bd-475b-94e2-a32cdc5ecc4b)
Expected behavior
Generate code compatible with the target ( in this case Net462 and Net48 )
Repro steps
NativeMethods.txt
content: REPARSE_DATA_BUFFERMultitarget Net462 or Net48 along with your .Net of choice
NativeMethods.json
content (if present): not applicableAny of your own code that should be shared?
Context
0.3.49
- NugetLangVersion
(if explicitly set by project): 9