Showing posts with label WindowsAppSDK. Show all posts
Showing posts with label WindowsAppSDK. Show all posts

Sunday, February 19, 2023

There was no match for the specified key in the index. (0x80070491)

Problem

using Microsoft.Windows.ApplicationModel.DynamicDependency;
using System;

namespace CsConsoleActivation
{
    class Program
    {
        // Windows App SDK version.
        static uint majorMinorVersion = 0x00010000;
        private static string executablePath;
        private static string executablePathAndIconIndex;

        static void Main(string[] args)
        {
            try
            {
                Bootstrap.Initialize(majorMinorVersion);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

This code generates an error, because I've got 
Windows App SDK of version 1.2 on my machine. So, I tried to modify 
majorMinorVersion to 0x00010010 to no avail.

Solution


After several hours of deep diving on the Win. App SDK source code I found out, 
that the field majorMinorVersion is not a binary type, but something different. 
It should have been set to 0x00010002. So, for my 1.2 version of Windows App SDK,
the correct code looks like this: 


using Microsoft.Windows.ApplicationModel.DynamicDependency;
using System;

namespace CsConsoleActivation
{
    class Program
    {
        // Windows App SDK version.
        static uint majorMinorVersion = 0x00010002;
        private static string executablePath;
        private static string executablePathAndIconIndex;

        static void Main(string[] args)
        {
            try
            {
                Bootstrap.Initialize(majorMinorVersion);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}