microsoft / CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.
MIT License
2.07k stars 87 forks source link

CS8785 due to missing `System.Text.Encodings.Web` assembly in Dev16.11 #1163

Closed oold closed 5 months ago

oold commented 6 months ago

Actual behavior

Building the project fails to generate the sources when a NativeMethods.json file exists.

The following warning is emitted:

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 'FileNotFoundException' with message 'Could not load file or assembly 'System.Text.Encodings.Web, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.'

Expected behavior

The sources are successfully generated during the build.

Repro steps

  1. NativeMethods.txt content:
    
    CopyFileEx
    CoTaskMemFree
    ExtractIconEx
    FileOpenDialog
    FileSaveDialog
    GetActiveWindow
    GetModuleFileName
    GetSystemWindowsDirectory
    GetWindowLongPtr
    HRESULT_FROM_WIN32
    IFileDialog
    IShellItem2
    ITaskbarList3
    SendMessage
    SetWindowLongPtr
    SHCreateItemFromParsingName
    ShellExecuteEx
    SHGetFileInfo
    SHGetKnownFolderItem
    SHGetStockIconInfo
    SHOpenFolderAndSelectItems
    SHParseDisplayName
    StrCmpLogical
    TaskbarList
    TaskDialogIndirect

E* FOLDERID ICON_ MAX_PATH MESSAGEBOXRESULT PBST S_ SEEMASK SHOW_WINDOW_CMD TASKDIALOG_ELEMENTS TASKDIALOGMESSAGES TD WIN32_ERROR WINDOW_EXSTYLE WM*


2. `NativeMethods.json` content (if present):
```json
{
  "$schema": "https://aka.ms/CsWin32.schema.json",
  "comInterop": {
    "preserveSigMethods": [
      "IFileDialogEvents"
    ]
  }
}
  1. Any of your own code that should be shared?

Context

AArnott commented 6 months ago

Note: Your target framework (net5.0-windows) is no longer supported.

System.Text.Encodings.Web being missing suggests you're running on a compiler that's older than one we test with. What .NET SDK or VS version are you building with?

oold commented 6 months ago

Running on the latest VS 16 version.

AArnott commented 5 months ago

It works for me:

image

Can you send more repro details?

AArnott commented 5 months ago

Actually, I could repro it after filling in the Nativemethods text files like you described.