Skip to content

CsWin32 should avoid Unsafe.SkipInit when it doesn't exist in the compilation #1199

@AArnott

Description

@AArnott

Discussed in #1191

Originally posted by thxkiwi May 31, 2024
I have a project that I wrote using targeting framework net80 and trying to get it working with net481/LangVersion 10.

CsWin32: 0.3.106
Using Visual Studio 17.10.0.

I've modified the SDK project files to be

  <PropertyGroup>
    <TargetFramework>net481</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <Platforms>x64</Platforms>
	  <LangVersion>10</LangVersion>
	  <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
  </PropertyGroup>

CsWin32 is generating Windows.Win32.char.InlineArrays.g.cs:84 - Unsafe.SkipInit(out __char_260 result);

		public static unsafe implicit operator __char_260(ReadOnlySpan<char> value)
		{
			Unsafe.SkipInit(out __char_260 result);
			Span<char> target = new Span<char>(result.Value, SpanLength);
			value.CopyTo(target);
			int initLength = value.Length;
			target.Slice(initLength, SpanLength - initLength).Clear();
			return result;
		}

That seems to be .NET 8 only still.

Am I missing something (including "the point") here? It seemed possible and reasonable to target net481 and LangVersion 10.

Help and guidance greatly appreciated.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions