WinUI app' store version crashes after System.Text.Json.JsonSerializer is used

Hong 1,661 Reputation points
2026-09-28T18:06:13.33+00:00

A WinUI app works fine with both the debug version launched from VS and the installed packaged store version.

As soon I added a few lines of code to use System.Text.Json.JsonSerializer, the packaed store version crashes upon start while the debug version still works flawlessly. The store version generates three entries in the event log:

1.
Application: MyApp.exe CoreCLR Version: 10.0.1226.42308 .NET Version: 10.0.12 Description: The process was terminated due to an unhandled exception. Exception Info: System.TypeLoadException: Could not load type 'ComInterfaceEntry' from assembly 'System.Runtime.InteropServices, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. at WinRT.MyApprGenericHelpers.GlobalVtableLookup.InitializeGlobalVtableLookup() at WinRT.MyAppGenericHelpers.GlobalVtableLookup.InitializeGlobalVtableLookup() at .cctor()

2.

AppName MyApp.exe

AppVersion 1.0.0.0

AppTimeStamp 6a890000

ModuleName KERNELBASE.dll

ModuleVersion 10.0.26100.9444

ModuleTimeStamp 28606b21

ExceptionCode e0434352

FaultingOffset 00000000000c41ca

ProcessId 0x9174

ProcessCreationTime 0x1dd4f71ccf0423c

AppPath C:\Program Files\WindowsApps\MyApp_4.0.16.0_x64__8yz90bzcvqd9e\MyApp\MyApp.exe

ModulePath C:\WINDOWS\System32\KERNELBASE.dll

IntegratorReportId 71dc73fd-e6da-454d-b66b-0336581fdb85

PackageFullName MyApp_4.0.16.0_x64__8yz90bzcvqd9e

PackageRelativeAppId App

3.

Bucket 2023465443946148661

BucketType 5

EventName MoAppCrash

Response Not available

CabId 0

P1 MyApp_4.0.16.0_x64__8yz90bzcvqd9e

P2 praid:App

P3 1.0.0.0

P4 6a890000

P5 KERNELBASE.dll

P6 10.0.26100.9444

P7 28606b21

P8 e0434352

P9 00000000000c41ca

P10

AttachedFiles \?\C:\ProgramData\Microsoft\Windows\WER\Temp\WER.0754f1a4-52e3-4402-b45d-5b7c5b4851ac.tmp.mdmp \?\C:\ProgramData\Microsoft\Windows\WER\Temp\WER.939dc956-0f92-46f0-a78b-b11afa5cd01f.tmp.WERInternalMetadata.xml WPR_initiated_DiagTrackMiniLogger_OneTrace_User_Logger_20260925_1_EC_0_inject.etl \?\C:\ProgramData\Microsoft\Windows\WER\Temp\WER.233f500f-d623-4081-b0ab-35151178bed4.tmp.etl WPR_initiated_DiagTrackMiniLogger_WPR System Collector_inject.etl \?\C:\ProgramData\Microsoft\Windows\WER\Temp\WER.ee35e1da-250a-43bd-867b-a64f3b04eaa2.tmp.etl \?\C:\ProgramData\Microsoft\Windows\WER\Temp\WER.7033b8c1-62de-4a24-9e09-d39f83a8e9aa.tmp.csv \?\C:\ProgramData\Microsoft\Windows\WER\Temp\WER.a47ca3fa-b033-49cc-9f72-3dc63db939bc.tmp.txt \?\C:\ProgramData\Microsoft\Windows\WER\Temp\WER.90bc579e-f6a3-4412-8c56-0c2706318475.tmp.xml

StorePath \?\C:\ProgramData\Microsoft\Windows\WER\ReportArchive\AppCrash_MyApp_df6692b2a91dda32f41ad9fd41af91eeed6e59d_5cb88f5e_0b0e065e-fc2f-460c-abed-8c797e4fe7ca

AnalysisSymbol

Rechecking 0

ReportId 71dc73fd-e6da-454d-b66b-0336581fdb85

ReportStatus 268435456

HashedBucket a66bf4790a7c831d2c14cb19b9b03335

Crash dump:

the assembly instruction at KERNELBASE!RaiseException in C:\Windows\System32\KERNELBASE.dll from Microsoft Corporation has caused a CLR Exception on thread 0 with the following error information:

Type:   System.TypeInitializationException 

Message:   The type initializer for '<Module>' threw an exception. 
This exception originated from ntdll!RcConsolidateFrames. 

This exception contains Inner Exceptions  
  
the assembly instruction at KERNELBASE!RaiseException in C:\Windows\System32\KERNELBASE.dll from Microsoft Corporation has caused a CLR Exception on thread 0 with the following error information:

yaml
Type:   System.TypeInitializationException 

Message:   The type initializer for '<Module>' threw an exception. 
This exception originated from ntdll!RcConsolidateFrames. 

This exception contains Inner Exceptions

 Exception 1 (0x1a7880a1ab0)

Type: System.TypeLoadException

Exception Message: Could not load type 'ComInterfaceEntry' from assembly 'System.Runtime.InteropServices, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

StackTrace:

WinRT.MyAppGenericHelpers.GlobalVtableLookup.InitializeGlobalVtableLookup()

WinRT.MyAppGenericHelpers.GlobalVtableLookup.InitializeGlobalVtableLookup()

<Module>..cctor()

Could anyone shed some light on this?




[Update]

To verify my point, I removed using System.Text.Json and related code, and the store version started working again.

I added the only two lines of System. Text. Json-related code back:

JsonSerializer.Deserialize<List<ImageProfile>>(json);
string json = JsonSerializer.Serialize(listProfiles);

and did some cleaning by deleting bin and obj folders. The stopped crashing, but I got the following:
Could not load file or assembly 'System.Text.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Type: System.IO.FileNotFoundException

I installed NuGet package System.Text.Json, and the above exception was gone.

Is installing System.Text.Json package a must if System.Text.Json is used? If so, how come the debug version does not need this NuGet package?

Windows development | WinUI
0 comments No comments

Answer accepted by question author
Gatlin Le (WICLOUD CORPORATION) 805 Reputation points Microsoft External Staff Moderator
2026-09-29T02:59:21.17+00:00

Hi @Hong ,

Thank you for isolating the behavior to the two JSON calls and sharing how the exception changed after cleaning the build output.

A separate System.Text.Json NuGet reference is not normally required for an app targeting .NET 10. Microsoft documents that the library is included in the shared framework from .NET Core 3.0 onward. A framework-dependent app uses an installed .NET runtime; a self-contained publish includes the runtime with the application. These deployment modes explain how the library can be available without an explicit package reference.

Adding the NuGet reference resolved the missing-assembly exception in your test. However, that result does not establish why the previous package could not resolve the assembly or which copy Debug was loading. I would keep the reference in place for now rather than remove it or manually copy framework DLLs.

Regarding the startup crash in your initial log, the ComInterfaceEntry exception occurs in GlobalVtableLookup.InitializeGlobalVtableLookup() during module initialization. It is different from the System.Text.Json missing-assembly exception reported in your update. Neither exception by itself proves that JSON reflection or trimming caused the failure.

For the next package test, please generate a fresh Release x64 package with the current references and deployment settings unchanged. Install it locally and test both saving and loading profiles, not only startup. This checks the packaged behavior without requiring another Store submission. If both operations now work, you can stop here; there is no need to change additional settings just to remove the explicit JSON reference.

If serialization still fails, inspect the Release configuration before changing the JSON code. Check PublishTrimmed, SelfContained, WindowsAppSDKSelfContained, and whether JsonSerializerIsReflectionEnabledByDefault is explicitly configured. Please check the effective values used by the build, including any publish-profile overrides, rather than relying on a single declaration in the project file. Leave these settings unchanged during this check.

Actual trimming during publish and the JSON reflection setting need to be distinguished. Microsoft documents that PublishTrimmed also affects features during build, and that enabling it disables default reflection-based JSON serialization unless explicitly overridden. Deployment mode alone does not establish whether reflection is enabled. Also, the .NET and Windows App SDK self-contained settings control separate dependencies.

For the JSON calls, source generation is the supported alternative if reflection-based serialization is disabled or you intend to keep trimming enabled. The documented reflection-disabled exception is InvalidOperationException, not either loader exception you posted. The code below addresses serialization; it is not a demonstrated fix for the ComInterfaceEntry or missing-assembly failure. If a loader exception is still preventing startup, please share the details requested at the end rather than making this code change to try to repair it.

To use it, add a context class in the same namespace as your existing ImageProfile model, with these imports. Keep your existing model rather than replacing it with a sample model:

using System.Collections.Generic;
using System.Text.Json.Serialization;

[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Metadata)]
[JsonSerializable(typeof(List<ImageProfile>), TypeInfoPropertyName = "ImageProfiles")]
internal partial class ProfileJsonContext : JsonSerializerContext
{
}

This example uses metadata generation to support both serialization and deserialization.

At the existing save location, replace the serialization call with:

string json = System.Text.Json.JsonSerializer.Serialize(
    listProfiles, ProfileJsonContext.Default.ImageProfiles);

At the existing load location, replace the deserialization call with:

List<ImageProfile>? loadedProfiles = System.Text.Json.JsonSerializer.Deserialize(
    json, ProfileJsonContext.Default.ImageProfiles);

Keep your existing handling for a null result or invalid JSON. If ImageProfile uses polymorphism, object-typed values, custom converters, or non-public members, review its serialization contract before applying this unchanged. These requirements apply wherever the generated context is used, including Debug. Microsoft's source-generation guide describes the configuration requirements.

A standalone check using .NET SDK 10.0.401 and runtime 10.0.12, without a System.Text.Json package reference, passed a two-profile round trip using this context pattern in both untrimmed and trimmed self-contained Release builds. The trimmed reflection-based control produced the expected InvalidOperationException. This validates the JSON pattern with a simple model, not your WinUI package or the ComInterfaceEntry failure.

If you make this JSON change, keep the deployment settings and package versions unchanged, clean the affected projects' bin and obj build output, then create and locally install a fresh package. Test both save and load in Debug and in the installed Release package, not only startup.

If a loader exception remains, please share the current exception and stack, along with the relevant project and publish-profile sections with sensitive information removed. Please include TargetFramework, the System.Text.Json and Microsoft.WindowsAppSDK package versions, the version of any explicit Microsoft.Windows.CsWinRT reference, and the Release settings discussed above together with PublishAot. Those details will help focus the next check on runtime deployment and dependency resolution rather than assuming the serialization change will fix the loader failure.

Please try the applicable steps and let me know how they go. If you run into any difficulties, leave a comment with the step you tried and the resulting behavior or error, with sensitive information removed. I will do my best to help you work through the next steps.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

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