/// <summary> /// If you're not using MSIX or sparse packages, you must call this method to register your AUMID with the Compat library and to /// register your COM CLSID and EXE in LocalServer32 registry. Feel free to call this regardless, and we will no-op if running /// under Desktop Bridge. Call this upon application startup, before calling any other APIs. /// </summary> /// <typeparam name="T">Your implementation of NotificationActivator. Must have GUID and ComVisible attributes on class.</typeparam> /// <param name="aumid">An AUMID that uniquely identifies your application.</param> public static void RegisterAumidAndComServer <T>(string aumid) where T : NotificationActivator { if (string.IsNullOrWhiteSpace(aumid)) { throw new ArgumentException("You must provide an AUMID.", nameof(aumid)); } // If running as Desktop Bridge if (DesktopBridgeHelpers.IsRunningAsUwp()) { // Clear the AUMID since Desktop Bridge doesn't use it, and then we're done. // Desktop Bridge apps are registered with platform through their manifest. // Their LocalServer32 key is also registered through their manifest. _aumid = null; _registeredAumidAndComServer = true; return; } _aumid = aumid; string exePath = Process.GetCurrentProcess().MainModule.FileName; RegisterComServer <T>(exePath); _registeredAumidAndComServer = true; }
private static void EnsureRegistered() { // If not registered AUMID yet if (!_registeredAumidAndComServer) { // Check if Desktop Bridge if (DesktopBridgeHelpers.IsRunningAsUwp()) { // Implicitly registered, all good! _registeredAumidAndComServer = true; } else { // Otherwise, incorrect usage throw new Exception("You must call RegisterAumidAndComServer first."); } } // If not registered activator yet if (!_registeredActivator) { // Incorrect usage throw new Exception("You must call RegisterActivator first."); } }