OneSignal/OneSignal-DotNet-SDK

OneSignal fails with an exceptionusing MAUI and a device of Windows desktop:

pmoran1947 opened this issue · 2 comments

What happened?

In the application App.xaml.cs, I get an exception with the statement
OneSignal.Debug.LogLevel = LogLevel.VERBOSE;

I am using Visual Studio 17.9 and OneSignalSDK.DotN1et 5.1.1

Steps to reproduce?

1. Create the default MAUI app using the VS templates
2. Add OneSignalSDK.DotNet package
3. Add the using statements
using OneSignalSDK.DotNet;
using OneSignalSDK.DotNet.Core;
using OneSignalSDK.DotNet.Core.Debug;
4. After calling InitializeComponent(), add the statement
           OneSignal.Debug.LogLevel = LogLevel.VERBOSE;
5. run the debug version with a target of Windows Machine

What did you expect to happen?

I expect the app to run but it fails with an exception
The type initializer for 'OneSignalSDK.DotNet.OneSignal' threw an exception.

Relevant log output

'MauiApp1.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.2\netstandard.dll'. 
'MauiApp1.exe' (CoreCLR: clrhost): Loaded 'D:\Development\MauiApp1\MauiApp1\bin\Debug\net8.0-windows10.0.19041.0\win10-x64\AppX\OneSignalSDK.DotNet.Core.dll'. 
'MauiApp1.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.2\System.Runtime.Loader.dll'. 
'MauiApp1.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.2\System.ComponentModel.TypeConverter.dll'. 
Exception thrown: 'System.NotImplementedException' in OneSignalSDK.DotNet.dll
Exception thrown: 'System.TypeInitializationException' in OneSignalSDK.DotNet.dll
'MauiApp1.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\PrivateAssemblies\Runtime\Microsoft.VisualStudio.Debugger.Runtime.NetCoreApp.dll'.

Code of Conduct

  • I agree to follow this project's Code of Conduct

@pmoran1947 Thanks for reaching out have you been able to get this to work or are you still running into this issue? How did you add the OneSignalSDK.DotNet package?

@pmoran1947 Thanks for reporting, this is because this SDK doesn't support Windows.

The key part of the error message is:

Exception thrown: 'System.NotImplementedException' in OneSignalSDK.DotNet.dll

Sorry we didn't have this documented well but I would recommend creating a class to route OneSignal calls through, omit calling OneSignal on your Windows builds.

If you are interested in Windows support OneSignal supports it but there isn't an SDK, it requires using Microsoft's APIs and making REST API calls to OneSignal. See OneSignal's Windows App Setup doc for more details.

  • If SDK support is something you need let us know, we will consider it based on interest.

Related issues: