Emit warning/error when System.Memory reference is missing but required by emitted code
Nobody has claimed this yet.
- 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
-
Create new .NET Framework 4.8 project or create .NET 5.0 project and change target framework to 'net48' or 'netstandard2.0'.
-
NativeMethods.txtcontent:
CharLower
-
NativeMethods.jsoncontent (if present): does not exist -
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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