Netcore 3.0 versus 5.0 difference, NullReferenceException with WriteValueWithResultAsync (BLE Lib)

Alexander Ross 21 Reputation points

I'm attempting to segregate functionality from the UWP example for BLE into a separate library for testing.

I was successful in setting it up as a standalone test library (using netcore 3.0)

However, in migrating to my GUI app (Now using netcore 5.0) WinRT can no longer be referenced so I had to remove a reference to Windows contracts.

Now I'm running and able to find my BLE device fine (even the correct read/write characteristics) but now when I write to write to the device characteristic I get a breaking crash with the the NullReferenceException.

All of the variables inside the involved object seem not null except for Device ID in the Gatt Characteristic which hides an Interop COM exception, however, this is also true of my "console app" in 3.0 and it does not have this issue and works fine (even with the same conditions present)

How can I debug this deeper? Is this a security issue?

I am targetting net5.0-windows10.0.19041

  Message=Object reference not set to an instance of an object.
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Library.BleLib.BleComms.<WriteBufferToSelectedCharacteristicAsync>d__21.MoveNext() in C:\Testing\Net\trunk\Externals\BleLib\BleComms.cs:line 200
Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,841 Reputation points

    Hello, Welcome to Micorosoft Q&A,

    You have gotten the expected behavior. Currently, uwp app doesn’t support to reference .net core class library. If you want to reference custom library in uwp app, it is recommended to use .net standard class library. For your case, you could right click the class library then select Edit Project File, change the TargetFramework from .NET Core to .NET Standard. As follows:


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful