azure-sdk-for-net: [BUG] Xamarin linking issues when using this library
Describe the bug After updating the Microsoft.Azure.ServiceBus package from 3.4.0 to 4.1.1 our release builds don’t work properly anymore. This is in a Xamarin.Android application. Linking is necessary to keep our application size small, in previous versions of the library this worked without problem.
I’ve linked two separate stacktraces here. One for normal usage where only sdk assemblies are linked away, this is the standard setting for new Xamarin projects.
The second one is happening in our usecase. We have a more complex setup where some libraries are referenced which aren’t linkersafe and need to be excluded from linking. Simply ignoring some libraries during the link fase starts failing the build as well.
Exception or Stack Trace (Link SDK Assemblies only) /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: The “LinkAssemblies” task failed unexpectedly. /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: Mono.Linker.MarkException: Error processing method: ‘System.Void Microsoft.Azure.Services.AppAuthentication.AdalAuthenticationContext/<AcquireTokenAsync>d__0::MoveNext()’ in assembly: ‘Microsoft.Azure.Services.AppAuthentication.dll’ —> Mono.Cecil.ResolutionException: Failed to resolve System.Threading.Tasks.Task`1<Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult> Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContextIntegratedAuthExtensions::AcquireTokenAsync(Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext,System.String,System.String,Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential) /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod (Mono.Cecil.MethodReference reference) [0x00013] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.MarkMethod (Mono.Cecil.MethodReference reference) [0x0004a] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.MarkInstruction (Mono.Cecil.Cil.Instruction instruction) [0x00040] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.MarkMethodBody (Mono.Cecil.Cil.MethodBody body) [0x000c2] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessMethod (Mono.Cecil.MethodDefinition method) [0x00186] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessQueue () [0x0001b] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: — End of inner exception stack trace — /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessQueue () [0x00047] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue () [0x0000a] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.Process () [0x00102] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.Process (Mono.Linker.LinkContext context) [0x0000d] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at MonoDroid.Tuner.MonoDroidMarkStep.Process (Mono.Linker.LinkContext context) [0x0000b] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Pipeline.ProcessStep (Mono.Linker.LinkContext context, Mono.Linker.Steps.IStep step) [0x0000d] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x0000f] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at MonoDroid.Tuner.Linker.Run (Mono.Linker.Pipeline pipeline, Mono.Linker.LinkContext context) [0x00000] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at MonoDroid.Tuner.Linker.Process (MonoDroid.Tuner.LinkerOptions options, Mono.Linker.ILogger logger, Mono.Linker.LinkContext& context) [0x00071] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Xamarin.Android.Tasks.LinkAssemblies.Execute (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver res) [0x002d4] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Xamarin.Android.Tasks.LinkAssemblies.Execute () [0x0001b] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs:574 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask (Microsoft.Build.BackEnd.ITaskExecutionHost taskExecutionHost, Microsoft.Build.BackEnd.Logging.TaskLoggingContext taskLoggingContext, Microsoft.Build.BackEnd.TaskHost taskHost, Microsoft.Build.BackEnd.ItemBucket bucket, Microsoft.Build.BackEnd.TaskExecutionMode howToExecuteTask) [0x002a9] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs:805
Exception or Stack Trace (Link all assemblies) /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: The “LinkAssemblies” task failed unexpectedly. /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: Mono.Linker.MarkException: Error processing method: ‘System.Void Microsoft.Azure.Services.AppAuthentication.ClientCertificateAzureServiceTokenProvider/<GetTokenAsync>d__8::MoveNext()’ in assembly: ‘Microsoft.Azure.Services.AppAuthentication.dll’ —> Mono.Cecil.ResolutionException: Failed to resolve Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.HandleUnresolvedType (Mono.Cecil.TypeReference reference) [0x00013] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.MarkType (Mono.Cecil.TypeReference reference) [0x0002c] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at MonoDroid.Tuner.MonoDroidMarkStep.MarkType (Mono.Cecil.TypeReference reference) [0x00000] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.MarkMethodBody (Mono.Cecil.Cil.MethodBody body) [0x00047] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessMethod (Mono.Cecil.MethodDefinition method) [0x00186] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessQueue () [0x0001b] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: — End of inner exception stack trace — /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessQueue () [0x00047] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue () [0x0000a] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.Process () [0x00102] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Steps.MarkStep.Process (Mono.Linker.LinkContext context) [0x0000d] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at MonoDroid.Tuner.MonoDroidMarkStep.Process (Mono.Linker.LinkContext context) [0x0000b] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Pipeline.ProcessStep (Mono.Linker.LinkContext context, Mono.Linker.Steps.IStep step) [0x0000d] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x0000f] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at MonoDroid.Tuner.Linker.Run (Mono.Linker.Pipeline pipeline, Mono.Linker.LinkContext context) [0x00000] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at MonoDroid.Tuner.Linker.Process (MonoDroid.Tuner.LinkerOptions options, Mono.Linker.ILogger logger, Mono.Linker.LinkContext& context) [0x00071] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Xamarin.Android.Tasks.LinkAssemblies.Execute (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver res) [0x002d4] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Xamarin.Android.Tasks.LinkAssemblies.Execute () [0x0001b] in <610526b6785240868e600b8f8b229a30>:0 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs:574 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask (Microsoft.Build.BackEnd.ITaskExecutionHost taskExecutionHost, Microsoft.Build.BackEnd.Logging.TaskLoggingContext taskLoggingContext, Microsoft.Build.BackEnd.TaskHost taskHost, Microsoft.Build.BackEnd.ItemBucket bucket, Microsoft.Build.BackEnd.TaskExecutionMode howToExecuteTask) [0x002a9] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs:805
To Reproduce Stacktrace 1: (link sdk assemblies only)
- create a new Xamarin.Android project
- add Microsoft.Azure.ServiceBus nuget package
- add some code which uses it - simply instantiating a subscriptionclient seems to be enough
- build the project in release mode (default settings)
- build fails on a linking issue
Stacktrace 2: (full sdk link)
- start from repro stacktrace 1
- change linking settings to ‘link all’
- ignore Microsoft.Azure.Amqp from being linked either through LinkConfig or project settings
- build the project in release mode
- build fails on another linking issue
The sample project can be found here: https://github.com/msioen/ServicebusLinkingIssue
Expected behavior Default mono linking options should not fail the build.
Setup (please complete the following information):
- OS: target: Android
- IDE : VS4Mac
- Version of the Library used: 4.1.1
Additional context Note that in the second repro I ignored the Microsoft.Azure.Amqp assembly from being linked by mono. The linking settings in our actual project are somewhat different but it fails with the same exact stacktrace so as a minimal reproduction this seems viable.
Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- [ x] Bug Description Added
- [ x] Repro Steps Added
- [ x] Setup information Added
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 24 (7 by maintainers)
@serkantkaraca Skipping the Microsoft.Azure.Services.AppAuthentication during linking results in the same stack trace as mentioned in the initial report.
The issue is caused by the fact that Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate is not available for Xamarin due to multi targeting of the Microsoft.IdentityModel.Clients.ActiveDirectory library. As can be seen in here, CertificateAssertion is not included for both MonoAndroid and Xamarin.iOS10. https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/blob/68d7dea3643e075be85abbca1ab88ba614465541/src/Microsoft.IdentityModel.Clients.ActiveDirectory/Microsoft.IdentityModel.Clients.ActiveDirectory.csproj
In the servicebus library seems (at least for us) to originate from Microsoft.Azure.ServiceBus.ServiceBusConnection.InitializeConnection(ServiceBusConnectionStringBuilder builder) due to presence of the ManagedIdentityTokenProvider. Thus even though we do not use the ManagedIdentity path in the code, the linker detects it as a possible pathway.