Share via

WinUI app store version errors

Hong 1,526 Reputation points
2026-01-18T05:10:52.53+00:00

I ported a very simple UWP app to WinUI. When the app is launched from VS2026, it works flawlessly for both the debug version and the release version. However, its Microsoft Store version has all kinds of problems.

Let me show one of them here:

System.NullReferenceException: Object reference not set to an instance of an object.
 Stack Trace:
   at WinRT.TypeExtensions.GetAbiToProjectionVftblPtr(Type helperType)
   at WinRT.ComWrappersSupport.<GetInterfaceTableEntries>g__AddInterfaceToVtable|16_2(Type iface, List`1 entries, Boolean& hasUserImplementedIMarshalInterface, Boolean& hasUserImplementedICustomPropertyProviderInterface)
   at WinRT.ComWrappersSupport.<GetInterfaceTableEntries>g__GetInterfaceTableEntriesForJitEnvironment|16_3(Type type, List`1 entries, Boolean& hasUserImplementedIMarshalInterface, Boolean& hasUserImplementedICustomPropertyProviderInterface)
   at WinRT.ComWrappersSupport.GetInterfaceTableEntries(Type type)
   at WinRT.DefaultComWrappers.<>c.<ComputeVtables>b__7_0(Type type)
   at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValue(TKey key, CreateValueCallback createValueCallback)
   at WinRT.DefaultComWrappers.ComputeVtables(Object obj, CreateComInterfaceFlags flags, Int32& count)
   at System.Runtime.InteropServices.ComWrappers.CreateManagedObjectWrapper(Object instance, CreateComInterfaceFlags flags)
   at System.Runtime.InteropServices.ComWrappers.<>c.<GetOrCreateComInterfaceForObject>b__58_0(Object c, <>f__AnonymousType0`2 state)
   at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetOrAdd[TArg](TKey key, Func`3 valueFactory, TArg factoryArgument)
   at System.Runtime.InteropServices.ComWrappers.GetOrCreateComInterfaceForObject(Object instance, CreateComInterfaceFlags flags)
   at WinRT.ComWrappersSupport.CreateCCWForObjectForABI(Object obj, Guid iid)
   at WinRT.MarshalInspectable`1.CreateMarshaler2(T o, Guid iid, Boolean unwrapObject)
   at ABI.Microsoft.UI.Xaml.Data.ICustomProperty.Do_Abi_GetValue_2(IntPtr thisPtr, IntPtr target, IntPtr* result)
--- End of stack trace from previous location ---
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|38_0(Int32 hr)
   at ABI.System.ComponentModel.PropertyChangedEventHandler.NativeDelegateWrapper.Invoke(Object sender, PropertyChangedEventArgs e)

It is thrown by

Folders = new ObservableCollection<FolderViewModel>();

where

 ObservableCollection<FolderViewModel> _Folders = new ObservableCollection<FolderViewModel>();
        public ObservableCollection<FolderViewModel> Folders
        {
            get { return _Folders; }
            set
            {
                _Folders = value;
                NotifyPropertyChanged();
            }
        }
 public class FolderViewModel : ViewModelBase
   {
       #region Properties
       private int _id = 0;
       public int Id
       {
           get
           { return _id; }
           set
           {
               if (_id == value)
               { return; }
               _id = value;
               NotifyPropertyChanged("Id");
           }
       }
       private string _sFolderPath = string.Empty; 
       public string sFolderPath
       {
           get
           { return _sFolderPath; }
           set
           {
               if (_sFolderPath == value)
               { return; }
               _sFolderPath = value;
               NotifyPropertyChanged();
           }
       }
       private bool _bSubfolder = false;
       public bool bSubfolder
       {
           get
           { return _bSubfolder; }
           set
           {
               if (_bSubfolder == value)
               { return; }
               _bSubfolder = value;
               NotifyPropertyChanged("bSubfolder");
           }
       }
       public string sSubfolder
       {
           get
           { return _bSubfolder ? XRUtils.GetString("including_sub_folders") : XRUtils.GetString("not_including_sub_folders"); }
       }
       private uint _uiKeepDays = 60;
       public uint uiKeepDays
       {
           get
           { return _uiKeepDays; }
           set
           {
               if (_uiKeepDays == value)
               { return; }
               _uiKeepDays = value;
               NotifyPropertyChanged("uiKeepDays");
           }
       }
       private bool _bActive = true;
       public bool bActive
       {
           get
           { return _bActive; }
           set
           {
               if (_bActive == value)
               { return; }
               _bActive = value;
               NotifyPropertyChanged("bActive");
           }
       }
       public string sActive
       {
           get
           { return _bActive ? XRUtils.GetString("active") : XRUtils.GetString("not_active"); }
       }
       public string sToken { get; set; }
       bool _bPermanent = false;
       public bool bPermanent
       {
           get { return _bPermanent; }
           set
           {
               if (_bPermanent != value)
               {
                   _bPermanent = value;
                   NotifyPropertyChanged();
               }
           }
       }
       bool _bDefault = true;
       public bool bDefault
       {
           get { return _bDefault; }
           set
           {
               if (_bDefault != value)
               {
                   _bDefault = value;
                   NotifyPropertyChanged();
               }
           }
       }
       #endregion
  }


This makes the debugging a major nuisance.

Could anyone offer a tipfor its remedy?

Windows development | WinUI
0 comments No comments

2 answers

Sort by: Most helpful
  1. Michael Le (WICLOUD CORPORATION) 11,330 Reputation points Microsoft External Staff Moderator
    2026-01-19T07:59:55.0566667+00:00

    Hello @Hong ,

    .NET Native compilation (used for Store packages) might strip away reflection metadata that WinRT needs to create COM wrappers for your custom types.

    You should look into adding a runtime directives file (rd.xml) to your project to preserve the necessary metadata for your types.

    For example, you can add something like this to your rd.xml:

    <Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
      <Application>
        <!--
          Assembly entries instruct the runtime to preserve metadata for types
          in the specified assembly.
        -->
    
        <!-- Preserve all types in your main application assembly -->
        <Assembly Name="YourAppName" Dynamic="Required All" />
    
        <!-- Specifically preserve ViewModel types for WinRT interop -->
        <Type Name="YourNamespace.FolderViewModel" Dynamic="Required All" Serialize="Required All" DataContractSerializer="Required All" />
        <Type Name="YourNamespace.ViewModelBase" Dynamic="Required All" Serialize="Required All" />
    
        <!-- Preserve ObservableCollection and related types -->
        <Type Name="System.Collections.ObjectModel.ObservableCollection`1" Dynamic="Required All">
          <TypeInstantiation Name="YourNamespace.FolderViewModel" Dynamic="Required All" />
        </Type>
    
        <!-- Preserve INotifyPropertyChanged infrastructure -->
        <Namespace Name="System.ComponentModel" Dynamic="Required All" />
    
        <!-- Preserve WinRT property system -->
        <Namespace Name="Microsoft.UI.Xaml.Data" Dynamic="Required All" />
      </Application>
    </Directives>
    

    And add the reference to the rd.xml file in your project file:

    <ItemGroup>
      <RdXmlFile Include="Properties\Default.rd.xml" />
    </ItemGroup>
    

    I hope this helps.

    Was this answer helpful?

    1 person found this answer helpful.

  2. AI answer

    2026-01-18T05:11:06.1+00:00

    The System.NullReferenceException you are encountering in your WinUI app when it is launched from the Microsoft Store may be due to the way the ObservableCollection<FolderViewModel> is being initialized or used. Here are a few tips to help you troubleshoot and resolve the issue:

    1. Check Initialization: Ensure that the Folders property is being initialized properly before it is accessed. If Folders is accessed before it is set to a new instance of ObservableCollection<FolderViewModel>, it will throw a NullReferenceException.
    2. Debugging in Store Version: Since the app works fine in the debug and release versions from Visual Studio but fails in the Store version, consider adding logging to track the state of your application when it runs in the Store. This can help identify if the Folders property is being accessed prematurely.
    3. Check for Missing Resources: The issue could also be related to missing resources or dependencies that are available in the development environment but not in the Store version. Make sure all necessary resources are included in the app package.
    4. Review the Stack Trace: The stack trace indicates that the error occurs when trying to create a wrapper for a COM object. Ensure that all COM interfaces and types used in your app are correctly registered and accessible in the Store environment.
    5. Use Try-Catch Blocks: Implement try-catch blocks around the code that initializes or accesses Folders to gracefully handle exceptions and log detailed error messages. This can provide more context about what is going wrong.
    6. Check for Threading Issues: Ensure that any UI updates or accesses to Folders are done on the UI thread. If the collection is being modified from a background thread, it could lead to unexpected behavior.

    By following these tips, you should be able to identify and resolve the issues causing the NullReferenceException in your WinUI app when running from the Microsoft Store.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer 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.