How to fix Access violation exception thrown from inside winrt/base.h when trying to access CsWinRTComponent from c++/winrt WinUI3 project?

Zahid Hasan 0 Reputation points
2025-07-03T13:55:50.8533333+00:00

We are working on a large commercial project which used to run on UWP platform (using both c# and c++/CX).
Currently, we are migrating to c++/Winrt WinUI3.

For some specific reasons, we can't migrate all the modules of our app at one go.

If we try to provide a simplified view of our current planned architecture to support our app using WinUI3 partially, the components will look like this:

  1. WinUI3 c++/winrt project
  2. WinUI3 c# class library as CsWinrt component
  3. Dummy UWP c# project (It will be used to host UWP appservice)
  4. Application Packaging Project (To package both UWP and WinUI3 executables)

Case-1: When we use 1, 3 and 4 altogether, there is no issue. We can work with our desired items properly.

Case-2: When we use 1, 2 and 4 altogether, this still works.

Case-3 (Problematic): When we add UWP project along with Case-2, we get following error during trying to access API of 2 (CsWinRT Component)

Exception thrown at 0x00007FFF4F1C6CBE (ntdll.dll) in WinUIDemo.exe: 0xC0000005: Access violation reading location 0x0000000000000010.

In all 3 cases, our startup project was set to 4. (Application Packaging Project).

First of all, we don't understand, why the error occurs when we add UWP project as reference in the packaging project. As the API call is related with 1. and 2. only, adding UWP project should have no impact.

So, we need the experts help to fix this problem.

Secondly, we need solution of another problem - if we check the AppX folder of the packaging project, we can see that, folder structure is not maintained. All files from different folders of separate projects are copied in the root directory. How can we keep the source folder structure intact?

Sample project to demonstrate this problem is attached here:

https://1drv.ms/f/c/08c787c588be23d1/EtEjvojFh8cggAhxAAAAAAABt2pjdHgnHnmK6o6ZWGKbJQ?e=WwrdqH

Windows development | Windows App SDK
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.