Skip to content

When targetting Android 11, binding a custom IComparator to Java.Util.Collections.Max throws a Couldn't bind to method ''. exception #5251

@lwschan

Description

@lwschan

Steps to Reproduce

Application is working fine when targeting Android 10, when I update the target to Android 11, then this crash happens.

Stack trace

System.ArgumentException: Couldn't bind to method ''.
at System.Delegate.GetCandidateMethod (System.Type type, System.Type target, System.String method, System.Reflection.BindingFlags bflags, System.Boolean ignoreCase, System.Boolean throwOnBindFailure) [0x000e9] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System/Delegate.cs:362   
at System.Delegate.CreateDelegate (System.Type type, System.Type target, System.String method, System.Boolean ignoreCase, System.Boolean throwOnBindFailure) [0x00014] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System/Delegate.cs:375   at System.Delegate.CreateDelegate (System.Type type, System.Type target, System.String method) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System/Delegate.cs:384   at Android.Runtime.AndroidTypeManager.RegisterNativeMembers (Java.Interop.JniType nativeClass, System.Type type, System.String methods) [0x0012e] in <227a96d68a0440cea172be41b1306654>:0   at Android.Runtime.JNIEnv.RegisterJniNatives (System.IntPtr typeName_ptr, System.Int32 typeName_len, System.IntPtr jniClass, System.IntPtr methods_ptr, System.Int32 methods_len) [0x00096] in <227a96d68a0440cea172be41b1306654>:0   at (wrapper managed-to-native) Java.Interop.NativeMethods.java_interop_jnienv_alloc_object(intptr,intptr&,intptr)  
at Java.Interop.JniEnvironment+Object.AllocObject (Java.Interop.JniObjectReference type) [0x00027] in <42748fcc36b74733af2d9940a8f3cc8e>:0   
at Java.Interop.JniType.AllocObject () [0x0000c] in <42748fcc36b74733af2d9940a8f3cc8e>:0   at Java.Interop.JniPeerMembers+JniInstanceMethods.StartCreateInstance (System.String constructorSignature, System.Type declaringType, Java.Interop.JniArgumentValue* parameters) [0x00044] in <42748fcc36b74733af2d9940a8f3cc8e>:0   at Java.Lang.Object..ctor () [0x00034] in <227a96d68a0440cea172be41b1306654>:0   at TimeLog.Mobile.Droid.Utilities.CompareSizesByArea..ctor () <0xad4c31e8 + 0x0002b> in <cc1cae8b0c4c44a9b7046b745060c8d6>:0   at TimeLog.Mobile.Droid.Activities.Expense.ImageSelectionActivity.SetUpCameraOutputs (System.Int32 width, System.Int32 height) [0x0007e] in C:\Users\Lewis\Documents\Projects\TimeLog.Mobility\TimeLog.Mobile\TimeLog.Mobile.Droid\Activities\Expense\ImageSelectionActivity.cs:861   at TimeLog.Mobile.Droid.Activities.Expense.ImageSelectionActivity.OpenCamera (System.Int32 width, System.Int32 height) [0x0004d] in C:\Users\Lewis\Documents\Projects\TimeLog.Mobility\TimeLog.Mobile\TimeLog.Mobile.Droid\Activities\Expense\ImageSelectionActivity.cs:321   
at TimeLog.Mobile.Droid.Listeners.Camera2BasicSurfaceTextureListener.OnSurfaceTextureAvailable (Android.Graphics.SurfaceTexture surface, System.Int32 width, System.Int32 height) [0x00001] in C:\Users\Lewis\Documents\Projects\TimeLog.Mobility\TimeLog.Mobile\TimeLog.Mobile.Droid\Listeners\Camera2BasicSurfaceTextureListener.cs:27   at Android.Views.TextureView+ISurfaceTextureListenerInvoker.n_OnSurfaceTextureAvailable_Landroid_graphics_SurfaceTexture_II (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_surface, System.Int32 width, System.Int32 height) [0x0000f] in <227a96d68a0440cea172be41b1306654>:0   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.100(intptr,intptr,intptr,int,int)

Code that generates the crash

var map = (StreamConfigurationMap)manager.GetCameraCharacteristics(cameraId).Get(CameraCharacteristics.ScalerStreamConfigurationMap);

if (map == null)
{
    continue;
}

// For still image captures, we use the largest available size.
var largest = (Size) Collections.Max(Arrays.AsList(map.GetOutputSizes((int) ImageFormatType.Jpeg)), new CompareSizesByArea());

The code crashes when trying to bind the CompareSizesByArea() as an IComparator for Collections.Max.

Code for CompareSizesByArea:

using Android.Util;
using Java.Lang;
using Java.Util;

namespace TimeLog.Mobile.Droid.Utilities
{
    public class CompareSizesByArea : Object, IComparator
    {
        #region Interface Implementations

        public int Compare(Object lhs, Object rhs)
        {
            var lhsSize = (Size) lhs;
            var rhsSize = (Size) rhs;

            // We cast here to ensure the multiplications won't overflow
            return Long.Signum((long) lhsSize.Width * lhsSize.Height - (long) rhsSize.Width * rhsSize.Height);
        }

        #endregion
    }
}

Expected Behavior

Application does not crash

Actual Behavior

Application crashes with System.ArgumentException: Couldn't bind to method ''.

Version Information

Microsoft Visual Studio Community 2019
Version 16.7.7
VisualStudio.16.Release/16.7.7+30621.155
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Community

Visual C++ 2019   00435-60000-00000-AA287
Microsoft Visual C++ 2019

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASA Service Provider   1.0

ASP.NET and Web Tools 2019   16.7.532.28833
ASP.NET and Web Tools 2019

ASP.NET Core Razor Language Services   16.1.0.2035807+72d099b977d3a85e65fa3b0614ca8cfc803fef02
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2012   16.7.532.28833
For additional information, visit https://www.asp.net/

ASP.NET Web Frameworks and Tools 2019   16.7.532.28833
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   16.7.532.28833
Azure App Service Tools v3.0.0

Azure Data Lake Node   1.0
This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio   2.6.2000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   16.7.532.28833
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.6.2000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   3.7.0-6.20514.1+600c0dadd199296df3ed07dfabdc014563a77f7c
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Color Theme Designer   1.0
Designer for creating new color themes

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter   16.7.20248.6
Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Dotfuscator Community Edition   5.42.0.9514-e0e25f754
PreEmptive Protection - Dotfuscator CE

Extensibility Message Bus   1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Fabric.DiagnosticEvents   1.0
Fabric Diagnostic Events

GitHub.VisualStudio   2.11.106.19330
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

JavaScript Prettier   2.1.47
Prettier is an opinionated JavaScript formatter inspired by refmt with advanced support for language features from ES2017, JSX, and Flow. It removes all original styling and ensures that all outputted JavaScript conforms to a consistent style.

JetBrains ReSharper 2020.2.4   Build 202.0.20200925.65451
JetBrains ReSharper package for Microsoft Visual Studio. For more information about ReSharper, visit http://www.jetbrains.com/resharper. Copyright © 2020 JetBrains, Inc.

Microsoft Azure HDInsight Azure Node   2.6.2000.0
HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service   2.6.2000.0
Language service for Hive query

Microsoft Azure Service Fabric Tools for Visual Studio   16.0
Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service   2.6.2000.0
Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node   1.0
Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.30701.1

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.79+ge3567815aa.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.1
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 & 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.7.5 (112c7bc)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   5.7.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.7.20248.6
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Python - Conda support   16.7.20248.6
Conda support for Python projects.

Python - Django support   16.7.20248.6
Provides templates and integration for the Django web framework.

Python - IronPython support   16.7.20248.6
Provides templates and integration for IronPython-based projects.

Python - Profiling support   16.7.20248.6
Profiling support for Python projects.

Python - VC Project Support   16.1.19129.1
Provides support for launching C++ projects with Python debugging enabled.

ResXManager   1.48.3862.0
Manage localization of all ResX-Based resources in one place. Shows all resources of a solution and let's you edit the strings and their localizations in a well-arranged data grid.

SQL Server Data Tools   16.0.62008.03130
Microsoft SQL Server Data Tools

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   16.0.20702.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.7.0-6.20514.1+600c0dadd199296df3ed07dfabdc014563a77f7c
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.10.0.0 for F# 4.7   16.7.0-beta.20361.3+3ef6f0b514198c0bfa6c2c09fefe41a740b024d5
Microsoft Visual F# Tools 10.10.0.0 for F# 4.7

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Color Theme Editor   1.0
Allows users to create and edit Visual Studio themes. Themes can customize colors used for menus, toolbars, tabs, titlebars, the text editor, and other environment colors.

Visual Studio Container Tools Extensions (Preview)   1.0
View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

Visual Studio Tools for Kubernetes   1.0
Visual Studio Tools for Kubernetes

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   16.7.000.463 (d16-7@5209782)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.7.0.495 (remotes/origin/d16-7@79c0c522c)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.7.85 (1bcbbdf)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   11.0.2.0 (d16-7/025fde9)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: 83105ba
    Java.Interop: xamarin/java.interop/d16-7@1f3388a
    ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000
    SQLite: xamarin/sqlite/3.32.1@1a3276b
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-7@017078f


Xamarin.iOS and Xamarin.Mac SDK   14.2.0.12 (e0ce49680)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Metadata

Metadata

Assignees

Labels

bugComponent does not function as intended.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions