System.ArgumentNullException when awaiting IObservable

Eric

I am trying to await an Observable and I Get a

System.ArgumentNullException

Value cannot be null.
Parameter name: Source

The stack trace:

System.ArgumentNullException: Value cannot be null.
Parameter name: source
  at System.Reactive.Linq.Observable.GetAwaiter[TSource] (System.IObservable`1[T] source) [0x00003] in <370f6a6bb34048878534065376a195cb>:0
  at Lynkd.Models.Peripherals.RPHPeripheral+<readMacAddress>d__13.MoveNext () [0x00012] in /Users/ericbowman/Documents/Development/Mobile/LYNKD/Lynkd/Models/Peripherals/RPHPeripheral.cs:24
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113
  at Lynkd.Models.Peripherals.RPHGunbox+<InitializeAsync>d__1.MoveNext () [0x00020] in /Users/ericbowman/Documents/Development/Mobile/LYNKD/Lynkd/Models/Peripherals/RPHGunbox.cs:12
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018
  at UIKit.UIKitSynchronizationContext+<>c__DisplayClass1_0.<Post>b__0 () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/UIKit/UIKitSynchronizationContext.cs:24
  at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/Foundation/NSAction.cs:125
  at at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/UIKit/UIApplication.cs:79
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/UIKit/UIApplication.cs:63
  at Lynkd.iOS.Application.Main (System.String[] args) [0x00001] in /Users/ericbowman/Documents/Development/Mobile/LYNKD/Lynkd.iOS/Main.cs:17

Here is my source:

protected async Task readMacAddress()
{
    await (Device.ReadCharacteristic(BleService.DeviceInformation, BleCharacteristic.MacAddress).Subscribe(
        onNext: Result =>
        {
            MacAddress = BitConverter.ToString(Result.Data).Replace("-", string.Empty);
        },
        onError: Error =>
        {
            throw new BleException("Cannot Retrive MAC Address, Error Reading MAC Address");
        },
        onCompleted: () =>
        {
            return;

    }) as IObservable<CharacteristicGattResult>);
}

Any ideas?

Eric

It turns out I was WAY overthinking the use of RX. You can simply await the original function call like so:

protected async Task readMacAddress()
{
    var macResult = await Device.ReadCharacteristic(BleService.DeviceInformation, BleCharacteristic.MacAddress);
    MacAddress = BitConverter.ToString(macResult.Data).Replace("-", string.Empty);
}

Big thanks to Allan Ritchie for steering me in the right direction. (the author of the handy Xamarin BLE library I'm using) https://github.com/aritchie/bluetoothle

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

System.ArgumentNullException when creating a GUID

System.ArgumentNullException when GetDbContext in constructor

How to understand this `System.ArgumentNullException` when trying to use `Concat` with `as`

System.ArgumentNullException when creating a call expression on Xname.Get

TaskCanceledException when not awaiting

WPF Designer : System.ArgumentNullException

Scaffold-DbContext returns System.ArgumentNullException: Parameter name: proposedIdentifier in EFCore 2.0 when trying to pluralize

Value in property from WCF service is getting System.ArgumentNullException saying it is null, when it isn't

When will awaiting a method exit the program?

ArgumentNullException when invoking RenderComponent with Action

IdentityServer4 System.ArgumentNullException: Value cannot be null. Parameter name: type when trying to refresh token

Blazor MatAutocompletelist throwing System.ArgumentNullException

Entity-framework System.ArgumentNullException

UserManager Keeps throwing a System.ArgumentNullException

System.ArgumentNullException using botframework vision api

System.ArgumentNullException with NetMQ.Msg.Put()

Generated Code Behind Throws System.ArgumentNullException

System.ArgumentNullException' occurred in PresentationFramework.dll

System.ArgumentNullException: 'Value cannot be null error

No typescript warning when awaiting non Promise function

Async/Await not awaiting when SQL server unavailable

Automatic awaiting on coroutines when actual values are needed?

ArgumentNullException occurring when trying to request authentication token

How do I turn a polling system into an Rx.Net IObservable?

Cannot await system.IObservable.*** error in Rx of C#

When awaiting Task.Run for a compute bound operation, is the awaiting using a IOCP?

Unhandled Exception: System.ArgumentNullException: Value cannot be null

System.ArgumentNullException: 'Value cannot be null. (Parameter 'connectionString')'

Winform: System.ArgumentNullException: 'Value cannot be null. (Parameter 'stream')'

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive