JesseRedfield / NotificationTrayIconSharp

Cross Platform C# Wrapper around Native System tray icons.
MIT License
22 stars 1 forks source link

SEHException on Avalonia Project #11

Open AlizerUncaged opened 1 year ago

AlizerUncaged commented 1 year ago

I get the following exception when running the NotificationManager.Initialize() command

System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
   at NotificationIconSharp.Native.WinInterop.Toast_Initialize(String appId, String displayName, String iconPath)
   at NotificationIconSharp.Native.WinInterop.ToastInitialize(String appId, String displayName, String iconPath)
   at NotificationIconSharp.Native.Interop.ToastInitialize(String appId, String displayName, String iconPath)
   at NotificationIconSharp.NotificationManager.Initialize(String appId, String displayName, String iconPath)
   at AI_Helper.Components.TaskbarIconHandler.CreateTaskbarIcon() in E:\Projects\AI Helper\AI Helper\Components\TaskbarIconHandler.cs:line 34

the following code is in the function

    public void CreateTaskbarIcon()
    {
        try
        {
            var iconPath = "Resources/PlatformSpecific/ameq0-ibmwr-001.ico"; // Windows, ICON
            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                iconPath = "Resources/PlatformSpecific/Riku-Flavicon-bg.png"; // Mac, PNG

            NotificationManager.Initialize("com.app.test", "App Test", iconPath);

            NotificationManager.SendNotification("AI", "Text helper is running!", "com.app.test", iconPath);

            NotificationManager.NotificationIconSelectedEvent += NotificationManagerOnNotificationIconSelectedEvent;
        }
        catch (SEHException s)
        {
            ;
        }
    }

I also checked the .csproject file and copied the same settings from the Demo project and I still get the same error

JesseRedfield commented 1 year ago

I have one question:

1) Are you using the Nuget Package or did you clone thee repository and kind of copy/paste/piecemeal your solution together. In your own solution I highly recommend adding the Nuget Package NotificationIconSharp to your project.

Right Click Project -> Manage Nuget Packages -> Browse Tab -> Search "NotificationIconSharp" and install it.

You can also use the dotnet command line:

dotnet add package NotificationIconSharp --version 1.0.1

Then you can delete everything you tried to do in the .csproj file as it is not needed, the nuget package takes care of everything.

This error tends to come up when a native C/C++ dll dependency doesn't load, it either is not in the correct location in the project output or it has an invalid format for the CPU architecture you are running on. Nuget handles this, the package contains both x86 and x64 dlls of the native code, so when you target "Any CPU" the dotnet runtime figures out exactly which dll it needs to load from the nuget package at runtime.

Otherwise, if you wouldn't mind sharing more of your project maybe reducing it to the point of it being just the tray icon code and a broken build I would be more than happy to take a look.

StagPoint commented 11 months ago

I'm getting the same exception, also in an Avalonia project, and I'm using the Nuget package.