Skip to content

System.MissingMethodException at System.Windows.Forms.Application.SetHighDpiMode(System.Windows.Forms.HighDpiMode) in GreenShot unit tests #2925

@DotNetAppCompatFeiWang

Description

@DotNetAppCompatFeiWang
  • .NET Core Version:

.NET Core SDK (reflecting any global.json):
Version: 5.0.100-preview.1.20125.9
Commit: 12e88ed2e5

Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.100-preview.1.20125.9\

Host (useful for support):
Version: 5.0.0-preview.1.20120.5
Commit: 3c523a6a7a

.NET Core SDKs installed:
5.0.100-preview.1.20125.9 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.App 5.0.0-preview.1.20124.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.0-preview.1.20120.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 5.0.0-preview.1.20122.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

  • Have you experienced this same bug with .NET Framework?:
    No

Problem description:

Repro steps:

On the repo machine (could be found at https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1075435)

  1. On CMD, go to C:\Repro\GreenshotTest09
    2)run command "dotnet vstest Greenshot.Tests.dll"

Expected Result:

Tests should pass

Actual Result:

Total tests: 21
Passed: 16
Failed: 5

Findings :

Tests return this exception :

System.MissingMethodException : Method not found: 'Boolean System.Windows.Forms.Application.SetHighDpiMode(System.Windows.Forms.HighDpiMode)'.

When we create/build winforms app with .net core sdk 3.1 and run it against .net core 5.0, we get this issue. It is fine when we run against 3.1.

This issue does not repro if we build the same with code .net core 5.0 SDK.

This line in program.cs causes this issue :

Application.SetHighDpiMode(HighDpiMode.SystemAware);

Expected behavior:
All unites passed.

App Source on GitHub link: https://github.com/greenshot/greenshot

Minimal repro:

  1. create winforms app ===> dotnet new winforms on machine has .NET Core 3.1 SDK installed.
  2. dotnet build
  3. Run the app only have .NET 5 installed.

@dotnet-actwx-bot FYI

Metadata

Metadata

Assignees

Labels

🪲 bugProduct bug (most likely)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions