microsoft / microsoft/WindowsAppSDK

Using a C++WinRT component in C# project error CS0400: The type or namespace name could not be found in the global namespace (are you missing an assembly reference?)

Open
#5,071 15 comments 0 reactions 0 assignees View on GitHub
area-Projections
Dominant language
C++
Stars
4.7k
Forks
471
Avg merge
3d 13h
Merged PRs (30d)
28

Description

### Describe the bug

After 5+ yrs of tooling development, it still does not work out of the box. This is kind of epic. (And UWP project using the same step **does work out of the box**, without needing to add the nuget)

What I did:
- Ensure the C# project `csproj` file has windows sdk version in `` ✅
- Add a `CsWinRT` nuget ✅

### Steps to reproduce the bug

1. Create a C++WinRT runtime component project (using the WinUI3 runtime component project template)
2. Create a C# WinUI3 project, adding a reference to the C++WinRT component project
3. Add nuget package C# WinRT
4. Build and see the error.

### Expected behavior

_No response_

### Screenshots

_No response_

### NuGet package version

Windows App SDK 1.6.3: 1.6.250108002

### Packaging type

Packaged (MSIX)

### Windows version

Windows 11 version 24H2 (22621, October 2024 Update)

### IDE

Visual Studio 2022

### Additional context

[Repro](https://github.com/HO-COOH/WinUIComponentTest)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked Repro project and reproduce the build using a C++WinRT runtime component, a C# WinUI3 project, Windows App SDK 1.6.3, and the stated CsWinRT package and TargetFramework settings. Inspect the project reference and build output around CS0400; done means the C# project builds successfully and can resolve the C++WinRT component.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, csharp
Domain
build-system, desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.