Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
AArnott opened this issue Jun 3, 2024 Discussed in #1191 · 1 comment · Fixed by #1208
Closed

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

AArnott opened this issue Jun 3, 2024 Discussed in #1191 · 1 comment · Fixed by #1208
Assignees

Comments

@AArnott
Copy link
Member

AArnott commented Jun 3, 2024

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.

@AArnott
Copy link
Member Author

AArnott commented Jun 3, 2024

Per the discussion this came from, the issue seems to be that Unsafe.SkipInit comes from a package that wasn't referenced in the compilation. CsWin32 should be more cautious about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant