microsoft / microsoft/WindowsAppSDK

Missing DefaultDllImportSearchPaths attribute in WindowsAppRuntime_EnsureIsLoaded when WindowsAppSDKSelfContained is turned on

Open
#4,857 10 comments 1 reaction 2 assignees Claimed by @MuyuanMS View on GitHub
area-dotnet bug
Dominant language
C++
Stars
4.7k
Forks
471
Avg merge
3d 13h
Merged PRs (30d)
28

Description

### Describe the bug

When both `WindowsAppSDKSelfContained` and code analysis are turned on for a WinUI 3 project, it fails to build due to
[CA5392: Use DefaultDllImportSearchPaths attribute for P/Invokes](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca5392) in `Microsoft.Windows.Foundation.UndockedRegFreeWinRTCS.WindowsAppRuntime_EnsureIsLoaded`.

![Image](https://github.com/user-attachments/assets/567f198f-a399-4858-abe7-f666022eeba0)

### Steps to reproduce the bug

1. Create a WinUI 3 project (either packaged with single project or with WAP).
2. Add `true` in the project file.
3. Turn on code analysis with the following project properties:
``` true
all
latest
true
true
```
4. Build the project.

See example code repo here: https://github.com/[aries-zhang/WinUI3-Publish-SelfContained](https://github.com/aries-zhang/WinUI3-Publish-SelfContained)

### Expected behavior

1. Build should be successful.
2. No potential DLL hijacking risks should present.

### Screenshots

![Image](https://github.com/user-attachments/assets/567f198f-a399-4858-abe7-f666022eeba0)

### NuGet package version

WinUI 3 - Windows App SDK 1.6.1: 1.6.240923002

### Windows version

Windows 11 (24H2): Build 22621

### Additional context

Since this is generated code (or included from Nuget?), it makes it hard to suppress the error individually if not a global suppression rule.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.