Skip to content

Missing DefaultDllImportSearchPaths attribute in WindowsAppRuntime_EnsureIsLoaded when WindowsAppSDKSelfContained is turned on #4857

@aries-zhang

Description

@aries-zhang

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 in Microsoft.Windows.Foundation.UndockedRegFreeWinRTCS.WindowsAppRuntime_EnsureIsLoaded.

Image

Steps to reproduce the bug

  1. Create a WinUI 3 project (either packaged with single project or with WAP).
  2. Add <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained> in the project file.
  3. Turn on code analysis with the following project properties:
    <AnalysisMode>all</AnalysisMode>
    <AnalysisLevel>latest</AnalysisLevel>
    <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    
  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

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.

Metadata

Metadata

Labels

area-dotnetTopics related to .NET support in Windows App SDKbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions