Skip to content

Commit 311b41e

Browse files
authored
[Xamarin.Android.Build.Tasks] Add XA1031 error (dotnet#7448)
Fixes: dotnet#7326 Commit d3e8767 added a requirement that, under .NET 6+, the `$(AndroidHttpClientHandlerType)` MUST inherit from [`System.Net.Http.HttpMessageHandler`][0]. This was unfortunately a change from Classic, which allowed/required that [`System.Net.Http.HttpClientHandler`][1] be the base class. Allowing `HttpClientHandler` to be in the inheritance hierarchy for `$(AndroidHttpClientHandlerType)` would result in a `NullReferenceException` at runtime under .NET 6. Commit d3e8767 contained a TODO: > TODO: [Emit a build-time warning][2] if > `$(AndroidHttpClientHandlerType)` is set to an invalid value Implement this TODO: add a build-time check that verifies that `$(AndroidHttpClientHandlerType)` is a valid type for the target, e.g. is an `HttpMessageHandler` subclass on .NET 6. If `$(AndroidHttpClientHandlerType)` is not a valid type, then an XA1031 error is raised: error XA1031: The 'AndroidHttpClientHandlerType' has an invalid value of '{0}' please check your project settings. Additionally, if `$(AndroidHttpClientHandlerType)` is `System.Net.Http.SocketsHttpHandler, System.Net.Http`, *and* `$(UseNativeHttpHandler)` isn't set, then set `$(UseNativeHttpHandler)` to false. This is necessary to ensure that `SocketsHttpHandler` is preserved by the linker. [0]: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpmessagehandler?view=net-6.0 [1]: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclienthandler?view=net-6.0 [2]: dotnet#7326
1 parent e8f1f48 commit 311b41e

File tree

14 files changed

+494
-166
lines changed

14 files changed

+494
-166
lines changed

Documentation/guides/messages/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ or 'Help->Report a Problem' in Visual Studio for Mac.
130130
+ [XA1027](xa1027.md): The 'EnableProguard' MSBuild property is set to 'true' and the 'AndroidLinkTool' MSBuild property is empty, so 'AndroidLinkTool' will default to 'proguard'.
131131
+ [XA1028](xa1028.md): The 'AndroidEnableProguard' MSBuild property is set to 'true' and the 'AndroidLinkTool' MSBuild property is empty, so 'AndroidLinkTool' will default to 'proguard'.
132132
+ [XA1029](xa1029.md): The 'AotAssemblies' MSBuild property is deprecated. Edit the project file in a text editor to remove this property, and use the 'RunAOTCompilation' MSBuild property instead.
133+
+ [XA1031](xa1031.md): The 'AndroidHttpClientHandlerType' has an invalid value.
134+
+ [XA1032](xa1032.md):Failed to resolve '{0}' from '{1}'. Please check your `AndroidHttpClientHandlerType` setting.
135+
+ [XA1033](xa1033.md): Could not resolve '{0}'. Please check your `AndroidHttpClientHandlerType` setting.
133136

134137
## XA2xxx: Linker
135138

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Xamarin.Android error XA1031
3+
description: XA1031 error code
4+
ms.date: 10/10/2022
5+
---
6+
# Xamarin.Android error XA1031
7+
8+
## Example messages
9+
10+
```
11+
The 'AndroidHttpClientHandlerType' property value 'Foo.Bar.HttpHander, MyApp' must derive from 'System.Net.Http.HttpMessageHandler'.
12+
Please change the value to an assembly-qualifed type name which inherits from '{1}' or remove the property completely.
13+
```
14+
15+
## Solution
16+
17+
Edit your csproj directly and change the 'AndroidHttpClientHandlerType' to
18+
a valid value.
19+
20+
Valid values can be found at `~/android/deploy-test/building-apps/build-properties.md#AndroidHttpClientHandlerType`.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Xamarin.Android error XA1032
3+
description: XA1032 error code
4+
ms.date: 10/10/2022
5+
---
6+
# Xamarin.Android error XA1032
7+
8+
## Example messages
9+
10+
```
11+
Failed to resolve '{0}' from '{1}'. Please check your `AndroidHttpClientHandlerType` setting.
12+
```
13+
14+
## Solution
15+
16+
Edit your csproj directly and change the 'AndroidHttpClientHandlerType' to
17+
a valid value.
18+
19+
Valid values can be found at `~/android/deploy-test/building-apps/build-properties.md#AndroidHttpClientHandlerType`.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Xamarin.Android error XA1033
3+
description: XA1033 error code
4+
ms.date: 10/10/2022
5+
---
6+
# Xamarin.Android error XA1033
7+
8+
## Example messages
9+
10+
```
11+
Could not resolve '{0}'. Please check your `AndroidHttpClientHandlerType` setting.
12+
```
13+
14+
## Solution
15+
16+
Edit your csproj directly and change the 'AndroidHttpClientHandlerType' to
17+
a valid value.
18+
19+
Valid values can be found at `~/android/deploy-test/building-apps/build-properties.md#AndroidHttpClientHandlerType`.

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.BuildOrder.targets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ projects, these properties are set in Xamarin.Android.Legacy.targets.
135135
_IncludeLayoutBindingSources;
136136
AddLibraryJarsToBind;
137137
$(CompileDependsOn);
138+
_CheckAndroidHttpClientHandlerType;
138139
</CompileDependsOn>
139140
<CoreCompileDependsOn>
140141
UpdateGeneratedFiles;
141-
$(CoreCompileDependsOn)
142+
$(CoreCompileDependsOn);
142143
</CoreCompileDependsOn>
143144
<DeferredBuildDependsOn>
144145
$(DeferredBuildDependsOn);

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<HttpActivityPropagationSupport Condition="'$(HttpActivityPropagationSupport)' == ''">false</HttpActivityPropagationSupport>
9696
<InvariantGlobalization Condition="'$(InvariantGlobalization)' == ''">false</InvariantGlobalization>
9797
<StartupHookSupport Condition="'$(StartupHookSupport)' == ''">false</StartupHookSupport>
98+
<UseNativeHttpHandler Condition=" $(AndroidHttpClientHandlerType.Contains ('System.Net.Http.SocketsHttpHandler')) And '$(UseNativeHttpHandler)' == '' ">false</UseNativeHttpHandler>
9899
<UseNativeHttpHandler Condition="'$(UseNativeHttpHandler)' == ''">true</UseNativeHttpHandler>
99100
<_AggressiveAttributeTrimming Condition="'$(_AggressiveAttributeTrimming)' == ''">true</_AggressiveAttributeTrimming>
100101
<NullabilityInfoContextSupport Condition="'$(NullabilityInfoContextSupport)' == ''">false</NullabilityInfoContextSupport>

0 commit comments

Comments
 (0)