pr8x / DesktopNotifications

A cross-platform C# library for native desktop "toast" notifications.
MIT License
182 stars 32 forks source link

System.TypeLoadException: 'Could not load type 'Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat' from assembly 'Microsoft.Toolkit.Uwp.Notifications #27

Open sn4k3 opened 7 months ago

sn4k3 commented 7 months ago

Using latest nuget in Avalonia raises:

manager = new WindowsNotificationManager(context);

System.TypeLoadException: 'Could not load type 'Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat' from assembly 'Microsoft.Toolkit.Uwp.Notifications, Version=7.1.0.0, Culture=neutral, PublicKeyToken=4aff67a105548ee2'.'

image

All nuget installed:

image

Using net6.0, when publishing with net6.0 win-x64 does the same result.

FaBjE commented 5 months ago

I had the same issue. Setting the TargetOS to 10.0.17763.0 fixed it for me (.NET8)

Solution based on this issue: https://github.com/pr8x/DesktopNotifications/issues/24

stephannn commented 6 days ago

Hi, I changed my project file like that:

`<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <Nullable>enable</Nullable>
    <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
    <ApplicationManifest>app.manifest</ApplicationManifest>
    <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(OS)' != 'Windows_NT' ">
        <TargetFramework>net8.0</TargetFramework>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
        <TargetFramework>net8.0-windows10.0.17763.0</TargetFramework>
    </PropertyGroup>

  <ItemGroup Condition="'$(OS)' == 'Windows_NT'">
        <Compile Remove="NullImpl_WindowsNotificationManager.cs" />
    </ItemGroup>

  <ItemGroup>
    <Folder Include="Models\" />
    <AvaloniaResource Include="Assets\**" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Avalonia" Version="11.2.1" />
    <PackageReference Include="Avalonia.Controls.DataGrid" Version="11.2.1" />
    <PackageReference Include="Avalonia.Desktop" Version="11.2.1" />
    <PackageReference Include="Avalonia.ReactiveUI" Version="11.2.1" />
    <PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.1" />
    <PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.1" />
    <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
    <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.1" />
    <PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
    <PackageReference Include="System.Management" Version="9.0.0" />
    <PackageReference Include="DesktopNotifications" Version="1.3.1" />
    <PackageReference Include="DesktopNotifications.Windows" Version="1.3.1" />
    <PackageReference Include="DesktopNotifications.FreeDesktop" Version="1.3.1" />
    <PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Condition="'$(TargetFramework)' != 'netstandard2.0'" Version="7.1.3" />
    <PackageReference Include="Microsoft.Windows.SDK.Contracts" Condition="'$(TargetFramework)' == 'netstandard2.0'" Version="10.0.26100.1742" />
    <PackageReference Include="System.Drawing.Common" Version="8.0.10" />
  </ItemGroup>
</Project>
`

but I still get the error on Windows. Linux is working fine. Can someone assist?

Edit: I just copied the complete project from MrDoe (https://github.com/MrDoe/DesktopNotificationsNet8/tree/master) - https://github.com/pr8x/DesktopNotifications/pull/28 and it worked