CsWin32: Generator may fail with "Could not load file or assembly 'YamlDotNet..."

Currently for some reason the source generator starts to bail out when it sees GetCurrentProcess when called inside of dotnet build.

Oddly it seems to generate just fine from within Visual Studio even if I use the .NET 6 Preview 1/2 SDK’s.

CSC : warning CS8785: Generator 'SourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'GenerationFailedException' with message 'Failed while generating extern method: GetCurrentProcess' [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MiniDump.cs(15,21): error CS0234: The type or namespace name 'Windows' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(9,21): error CS0234: The type or namespace name 'Windows' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MiniDump.cs(88,132): error CS0246: The type or namespace name 'MINIDUMP_EXCEPTION_INFORMATION' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MiniDump.cs(88,180): error CS0246: The type or namespace name 'MINIDUMP_USER_STREAM_INFORMATION' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MiniDump.cs(88,231): error CS0246: The type or namespace name 'MINIDUMP_CALLBACK_INFORMATION' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(19,18): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(25,24): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(31,26): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(37,26): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(43,24): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(49,22): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(56,31): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(63,42): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(70,29): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(77,33): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(84,38): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(91,31): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(98,30): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(105,26): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(112,24): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(115,33): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(121,34): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(128,38): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(135,36): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(142,32): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(149,29): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(156,24): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(159,32): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(162,24): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(165,40): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]
C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump\MinidumpTypes.cs(170,26): error CS0103: The name 'MINIDUMP_TYPE' does not exist in the current context [C:\Users\User\Desktop\github\MyPackages\MiniDump\MiniDump.csproj]

This happens with my project with the following NativeMethods.txt:

GetCurrentProcess
GetCurrentProcessId
GetCurrentThreadId
MiniDumpWriteDump

The first 2 is used when calling MiniDumpWriteDump and the 3rd one is for when constructing the EXCEPTION_INFORMATION structure for the call.

and the following NativeMethods.json file:

{
  "$schema": "https://raw.githubusercontent.com/microsoft/CsWin32/main/src/Microsoft.Windows.CsWin32/settings.schema.json",
  "allowMarshaling": false
}

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 38 (36 by maintainers)

Commits related to this issue

Most upvoted comments

Ok, I have simplified the reproducibility of this issue down to clone git clone https://github.com/Elskom/Sdk.git --recursive --branch use-sourcegenerators followed by a build dotnet build --configuration Release 😂.

Also, I use the default one now, even with non default it still would get this error, and I tried every build of CsWin32 that was released to nuget.org with the same issue.

I use the .NET 6 SDK but on that project I target netstandard2.0, due to also needing to have the same build work with net461+, .net core 2.0+, and anything else that implement .NET Standard 2.0+.

Here is what I heard back from the Roslyn team:

Essentially the build works when you use msbuild but not “dotnet build”. The latter is happening on .NET Core and we don’t fully isolate anaylzers in independent ALC yet. It’s on the backlog for Dev17 / C# 10.

I am concerned however at the lack of isolation between analyzers that the C# compiler IMO ought to be providing so that one analyzer’s dependencies does not cause problems for another’s dependencies. I’ll follow up with the Roslyn team on this.

Hey @AArnott, I’m interested in hearing what is the take of the Roslyn team on it. Is there a link? Is it public issue?