microsoft / microsoft/CsWin32

Emit warning/error when System.Memory reference is missing but required by emitted code

Open
#242 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C#
Stars
2.5k
Forks
124
Avg merge
1d 3h
Merged PRs (30d)
9

Description

Actual behavior

As soon as I add 'CharLower' to my NativeMethods.txt I get the following build error:

Error	CS0246	The type or namespace name 'Span<>' could not be found (are you missing a using directive or an assembly reference?)
C:\dev\_tests\ConsoleApp3\Microsoft.Windows.CsWin32\Microsoft.Windows.CsWin32.SourceGenerator\PWSTR.g.cs

Other methods like 'MFStartup' which don't take strings work fine.

Expected behavior

The project should compile without errors even if using .NET Framework v4.8 / netstandard2.0

Repro steps

  1. Create new .NET Framework 4.8 project or create .NET 5.0 project and change target framework to 'net48' or 'netstandard2.0'.

  2. NativeMethods.txt content:

CharLower
  1. NativeMethods.json content (if present): does not exist

  2. Build project

Context
  • CsWin32 version: 0.1.422-beta
  • Win32Metadata version (if explicitly set by project): default
  • Target Framework: net48 or netstandard2.0
  • LangVersion: 8.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with NativeMethods.txt containing CharLower while targeting net48 or netstandard2.0, then inspect the generated PWSTR.g.cs and the source generator's dependency handling. Compare the build output with and without a System.Memory reference. Done means the missing requirement is reported clearly or the generated project builds without the opaque Span<> CS0246 error.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.