Skip to content

Cannot create a custom AndroidClientHandler that derives from AndroidClientHandler #6526

@emorell96

Description

@emorell96

Steps to Reproduce

  1. Create a MAUI project in Visual Studio Preview
  2. Create a class that derives from AndroidClientHandler in Xamarin.Android.Net
  3. Instantiate this class and pass it to an HttpClient.
  4. The construction of the derived class will fail when it calls base() since it cannot find the _nativeHandler field in AndroidClientHandler.

I don't see this happening in a Xamarin project, I guess because it builds with mono android 10?

public class DerivedHandler : AndroidClientHandler
    {
        public DerivedHandler() : base()
        {

        }
    }

Using the class above fails in MAUI. Interestingly enough doing:

public class DerivedHandler2 : DerivedHandler 
    {
        public DerivedHandler() : base()
        {

        }
    }

Gives you an error but this time it complains that DerivedHandler and not AndroidClientHandler doesn't have the _nativeHandler field. I am guessing it's this line of AndroidClientHandler.cs#L318, that creates the issue since it tries to find the _nativeHandler in the base clase which is different if I've inherited the class.

Expected Behavior

Be able to call the base constructor from the derived class without issues.

Actual Behavior

Base constructor fails in AndroidClientHandler Line 70 when it tries to call the GetUnderlyingHandler method.

Version Information

Microsoft Visual Studio Community 2022
Version 17.1.0 Preview 1.0
VisualStudio.17.Preview/17.1.0-pre.1.0+31903.286
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Community

Visual C++ 2022 00482-90000-00000-AA766
Microsoft Visual C++ 2022

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 17.1.125.8155
ASP.NET and Web Tools 2019

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

Azure App Service Tools v3.0.0 17.1.125.8155
Azure App Service Tools v3.0.0

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

Azure Functions and Web Jobs Tools 17.1.125.8155
Azure Functions and Web Jobs Tools

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

C# Tools 4.1.0-1.21551.6+e4419d6f6792da7011c8589ba118f59d830ca72f
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.

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

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

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

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

Microsoft Azure Tools for Visual Studio 2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager 2.1.134+45632ee938.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 & 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 17.1.4 (dc2a48c)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 6.1.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

Razor (ASP.NET Core) 17.0.0.2152601+724154d925d7d9d26ebf8a73a66d5219aa320400
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.0.62110.20190
Microsoft SQL Server Data Tools

ToolWindowHostedEditor 1.0
Hosting json editor into a tool window

TypeScript Tools 17.0.1029.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.1.0-1.21551.6+e4419d6f6792da7011c8589ba118f59d830ca72f
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 17.1.0-beta.21525.2+46af4a248255f4af2284883f48983fe7dd07a760
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 IntelliCode 2.2
AI-assisted development for Visual Studio.

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 17.1.0.163 (d17-1-p1@42933de)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.1.0.43 (remotes/origin/main@931878527)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 17.1.8 (590388a)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 12.1.99.56 (main/43243b4)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: c633fe9
Java.Interop: xamarin/java.interop/main@79744f61
ProGuard: Guardsquare/proguard@912d149
SQLite: xamarin/sqlite@a575761
Xamarin.Android Tools: xamarin/xamarin-android-tools/main@a5194e9

Xamarin.iOS and Xamarin.Mac SDK 15.3.0.41 (7b786db64)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Metadata

Metadata

Assignees

Labels

Area: Mono.AndroidIssues with the Android API binding (Mono.Android.dll).

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions