In the .csproj
file of your WinUI 3 application, add:
<PropertyGroup>
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>
Open your project in VS 2022
and right click project in solution explorer:
Properties > Build > Publish > Uncheck Publish trimmed
.
The trimming optimization feature of VS 2022 (which only runs in release mode) trims necessary methods in the MongoDB.Driver dll file which causes the connection to the database to fail.