System.ArgumentNullException при ожидании IObservable - PullRequest
0 голосов
/ 01 октября 2018

Я пытаюсь дождаться Наблюдения и получаю

System.ArgumentNullException

Значение не может быть нулевым.
Имя параметра: Source

Трассировка стека:

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

Вот мой источник:

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>);
}

Есть идеи?

Ответы [ 2 ]

0 голосов
/ 02 октября 2018

Оказывается, я ОЧЕНЬ обдумывал использование RX.Вы можете просто ждать первоначального вызова функции следующим образом:

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

Большое спасибо Аллану Ричи за то, что он направил меня в правильном направлении.(автор удобной библиотеки Xamarin BLE, которую я использую) https://github.com/aritchie/bluetoothle

0 голосов
/ 02 октября 2018

Я не знаю API, но я рискну предположить, что тип значений не CharacteristicGattResult.

Может ли это быть BluetoothGattCharacteristic`?

...