Исключение: нет нестатического метода «Landroid/net/wifi/ScanResult;.getWifiStandard()I».

#android #xamarin #xamarin.android #android-wifi #wifimanager

Вопрос:

По какой-то неизвестной мне причине приведенный ниже код выдает ошибку.

  class WifiReceiver : BroadcastReceiver {
            LoggingService creator;
            WifiManager wifiManager;

            public WifiReceiver(LoggingService creator, WifiManager wifiManager) {
                this.creator = creator;
                this.wifiManager = wifiManager;
            }

            public override void OnReceive(Context ctx, Intent intent) {
                creator.current_wifi_list = wifiManager.ScanResults.Select(p => new wifiInfo(p.Bssid.ToUpper(), p.Ssid, p.Level, /*Error here:*/(WifiStandard)p.WifiStandard));
            }
        }
 

Приведенный выше код выдает следующую ошибку: no non-static method "Landroid/net/wifi/ScanResu<.getWifiStandard()I" .

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

 at Java.Interop.JniEnvironment InstanceMethods.GetMethodID (Java.Interop.JniObjectReference type, System.String name, System.String signature) [0x0005b] in <84296f001fc94a0bbd7c905f949a4cbf>:0 
  at Java.Interop.JniPeerMembers JniInstanceMethods.GetMethodInfo (System.String encodedMember) <0x7cbd115170   0x000d7> in <84296f001fc94a0bbd7c905f949a4cbf>:0 
  at Java.Interop.JniPeerMembers JniInstanceMethods.InvokeVirtualInt32Method (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0001c] in <84296f001fc94a0bbd7c905f949a4cbf>:0 
  at Android.Net.Wifi.ScanResult.get_WifiStandard () [0x0000a] in <c74914c9312c4903bc6dc0631d9de8de>:0 
  at TestApp1.WifiGrabber WifiReceiver <>c.<OnReceive>b__3_0 (Android.Net.Wifi.ScanResult p) [0x0001d] in <a52f5d35042b44a99a919f7ab31cbba4>:0 
  at System.Linq.Enumerable SelectIListIterator`2[TSource,TResult].MoveNext () [0x00048] in <1f9bdd48b1f7427c83dc455405d489a4>:0 
  at System.Collections.Generic.Dictionary`2[TKey,TValue]..ctor (System.Collections.Generic.IEnumerable`1[T] collection, System.Collections.Generic.IEqualityComparer`1[T] comparer) <0x7cbd653880   0x000fb> in <c550fd7ca72343ab8776e057d3a40452>:0 
  at System.Collections.Generic.Dictionary`2[TKey,TValue]..ctor (System.Collections.Generic.IEnumerable`1[T] collection) <0x7cbd65382c   0x0003b> in <c550fd7ca72343ab8776e057d3a40452>:0 
  at TestApp1.WifiGrabber WifiReceiver.OnReceive (Android.Content.Context ctx, Android.Content.Intent intent) [0x0004a] in <a52f5d35042b44a99a919f7ab31cbba4>:0 
  --- End of managed Java.Lang.LinkageError stack trace ---
java.lang.NoSuchMethodError: no non-static method "Landroid/net/wifi/ScanResu<.getWifiStandard()I"
    at crc64112330f9a3878b86.WifiGrabber_WifiReceiver.n_onReceive(Native Method)
    at crc64112330f9a3878b86.WifiGrabber_WifiReceiver.onReceive(WifiGrabber_WifiReceiver.java:36)
    at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$-android_app_LoadedApk$ReceiverDispatcher$Args_52226(LoadedApk.java:1319)
    at android.app.-$Lambda$FilBqgnXJrN9Mgyks1XHeAxzSTk.$m$0(Unknown Source:4)
    at android.app.-$Lambda$FilBqgnXJrN9Mgyks1XHeAxzSTk.run(Unknown Source:0)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
 

Источник ошибки: mscorlib .

Сам сканер Wi-Fi создается со следующим кодом:

 wifiManager = (WifiManager)Application.Context.GetSystemService(WifiService);
var wifiReceiver = new WifiReceiver(this, wifiManager);
Application.Context.RegisterReceiver(wifiReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction));
 

Все говорит о том, что эта ошибка является ошибкой в xamarin (или mono, или где-то еще со стороны Microsoft). Так ли это?

  • Если нет, как мне исправить ошибку?
  • Если да, то есть ли обходной путь для получения стандарта Wi-Fi?

Моя системная информация:

 Microsoft Visual Studio Enterprise 2019
Version 16.11.1
VisualStudio.16.Release/16.11.1 31613.86
Microsoft .NET Framework
Version 4.8.04084
Microsoft Visual C   2019
ASP.NET and Web Tools 2019   16.11.75.64347
ASP.NET and Web Tools 2019
Azure App Service Tools v3.0.0   16.11.75.64347
Azure App Service Tools v3.0.0
C# Tools   3.11.0-4.21403.6 ae1fff344d46976624e68ae17164e0607ab68b10
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
Cookiecutter   16.11.21196.2
Provides tools for finding, instantiating and customizing templates in cookiecutter format.
Extensibility Message Bus   1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.
IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info
Linux Core Dump Debugging   1.0.9.31613
Enables debugging of Linux core dumps.
Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.
Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
Microsoft Library Manager   2.1.113 g422d40002e.RR
Install client-side libraries easily to any web project
Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers
Microsoft Visual C   Wizards   1.0
Microsoft Visual C   Wizards
Microsoft Visual Studio Tools for Containers   1.2
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL   F5 to edit amp; refresh your app without having to rebuild the container.
Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package
Mono Debugging for Visual Studio   16.10.15 (552afdf)
Support for debugging Mono processes with Visual Studio.
NuGet Package Manager   5.11.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/
ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info
Python   16.11.21196.2
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.
Python - Profiling support   16.11.21196.2
Profiling support for Python projects.
Razor (ASP.NET Core)   16.1.0.2122504 13c05c96ea6bdbe550bd88b0bf6cdddf8cde1725
Provides languages services for ASP.NET Core Razor.
SQL Server Data Tools   16.0.62107.28140
Microsoft SQL Server Data Tools
Test Adapter for Boost.Test   1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test.  The use terms and Third Party Notices are available in the extension installation directory.
Test Adapter for Google Test   1.0
Enables Visual Studio's testing tools with unit tests written for Google Test.  The use terms and Third Party Notices are available in the extension installation directory.
TypeScript Tools   16.0.30526.2002
TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools   3.11.0-4.21403.6 ae1fff344d46976624e68ae17164e0607ab68b10
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual C   for Cross Platform Mobile Development (Android)   16.0.31506.176
Visual C   for Cross Platform Mobile Development (Android)
Visual C   for Linux Development   1.0.9.31613
Visual C   for Linux Development
Visual F# Tools   16.11.0-beta.21322.6 488cc578cafcd261d90d748d8aaa7b8b091232dc
Microsoft Visual F# Tools
Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio
Visual Studio Container Tools Extensions   1.0
View, manage, and diagnose containers within Visual Studio.
Visual Studio Tools for CMake   1.0
Visual Studio Tools for CMake
Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers
VisualStudio.DeviceLog   1.0
Information about my package
VisualStudio.Foo   1.0
Information about my package
VisualStudio.Mac   1.0
Mac Extension for Visual Studio
Xamarin   16.11.000.174 (d16-11@e8f56f1)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin Designer   16.11.0.17 (remotes/origin/11e0001f0b17269345e80b58fb3adf1ba4efe2cd@11e0001f0)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
Xamarin Templates   16.10.5 (355b57a)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   11.4.0.5 (d16-11/7776c9f)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: c633fe9
    Java.Interop: xamarin/java.interop/d16-11@48766c0
    ProGuard: Guardsquare/proguard/v7.0.1@912d149
    SQLite: xamarin/sqlite/3.35.4@85460d3
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-11@683f375
Xamarin.iOS and Xamarin.Mac SDK   14.20.0.25 (3b53e529b)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
 

UPD1: Тест приложения был проведен на реальном устройстве Android 8.0: Samsung Galaxy S7.

Комментарии:

1. этот метод был добавлен в Android 11/API 30. На какой версии вы тестируете?

2. Приложение @Jason было протестировано на устройстве Android 8.0. Должен сказать, что я указал 5.0 в минимальной версии SDK, поэтому у xamarin должно быть достаточно информации, чтобы правильно связать свойство с желаемыми методами в SDK. Но если xamarin не может этого сделать, возможно, есть обходной путь?

3. этот метод не существует на устройстве, с которым вы проводите тестирование. Вы несете ответственность за определение того, соответствует ли устройство уровню Android для использования данного API