Microsoft-authentication-library-for-dotnet: [Bug] Failed to resolve "AuthenticationServices.ASWebAuthenticationSession" on Xamarin.IOS

Created on 10 Jul 2019  路  30Comments  路  Source: AzureAD/microsoft-authentication-library-for-dotnet

Which Version of MSAL are you using ?
Note that to get help, you need to run the latest version. Preview version are also ok.
For ADAL, please log issues to https://github.com/AzureAD/azure-activedirectory-library-for-dotnet

Microsoft.Identity.Client 4.0.0

Platform

Xamarin.iOS

What authentication flow has the issue?

  • Desktop / Mobile

    • [ ] Interactive

    • [ ] Integrated Windows Auth

    • [X] Username Password

    • [ ] Device code flow (browserless)

  • Web App

    • [ ] Authorization code

    • [ ] OBO

  • Web API

    • [ ] OBO

Other? - please describe;

Is this a new or existing app?

This is a new app or experiment

Repro

Build to Xamarin.iOS project using AzureDevOps Build

Expected behavior

Generate the code, as before use MSAL

Actual behavior

Receive error message MTOUCH : error MT2002: Failed to resolve "AuthenticationServices.ASWebAuthenticationSession" reference from "Xamarin.iOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065" using Hosted Mac Agent ou even using a Custom Agent with XCode and Mono Updated

Possible Solution

I try to Update Mono and XCode on CustomAgents and dont work. Try to downgrade Microsoft.Identity.Client and dont Work. On Hosted Mac OS Agent i use the follow script

echo "Setting mono version to 5_16_0_0"

sudo xcodebuild -showsdks

SYMLINK=5_16_0_0
MONOPREFIX=/Library/Frameworks/Mono.framework/Versions/$SYMLINK
echo "##vso[task.setvariable variable=DYLD_FALLBACK_LIBRARY_PATH;]$MONOPREFIX/lib:/lib:/usr/lib:$DYLD_LIBRARY_FALLBACK_PATH"
echo "##vso[task.setvariable variable=PKG_CONFIG_PATH;]$MONOPREFIX/lib/pkgconfig:$MONOPREFIX/share/pkgconfig:$PKG_CONFIG_PATH"
echo "##vso[task.setvariable variable=PATH;]$MONOPREFIX/bin:$PATH"

sudo $AGENT_HOMEDIRECTORY/scripts/select-xamarin-sdk.sh 5_16_0_0

He pass, but the app icon appear like disabled and the app dont open on device.

Additional context/ Logs / Screenshots

MTOUCH : error MT2002: Failed to resolve "AuthenticationServices.ASWebAuthenticationSession" reference from "Xamarin.iOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065"

Investigate external

Most helpful comment

@trwalke Just in case it can help. I have posted a solution to the issue mentioned above. Enclose below as well

鈥媁e do not use the ADAL/MSAL library but uses the same classes (ASWebAuthenticationSession) and we were facing the same build issue.
From our understanding, it was related to the default XCode version used on the Mac OS agent.

Trying to set the XCode version using a bash script calling xcode-select, we were not able to get it working until today.

The lastest Mac OS image (10.14) is now using XCode 11.1 as default and we were able to get it working by adding the following tasks to our pipeline

  • Add a DotNet installer task to use .Net Core 3.x (needed for Mono 6.x)
  • Add Bash task to set the Mono version to 6.4.0
  • Add Bash task to select the Xamarin SDK

YAML definition

variables:
  netcore.version: '3.0.x'
    mono.version: '6_4_0'

steps:
- task: UseDotNet@2
  displayName: 'Use .Net Core SDK $(netcore.version)'
  inputs:
    version: '$(netcore.version)'
- bash: |
   SYMLINK=$(mono.version)

   MONOPREFIX=/Library/Frameworks/Mono.framework/Versions/$SYMLINK

   echo "##vso[task.setvariable variable=DYLD_FALLBACK_LIBRARY_PATH;]$MONOPREFIX/lib:/lib:/usr/lib:$DYLD_LIBRARY_FALLBACK_PATH"
   echo "##vso[task.setvariable variable=PKG_CONFIG_PATH;]$MONOPREFIX/lib/pkgconfig:$MONOPREFIX/share/pkgconfig:$PKG_CONFIG_PATH"
   echo "##vso[task.setvariable variable=PATH;]$MONOPREFIX/bin:$PATH"
  displayName: 'Set Mono $(mono.version)'
- bash: |
   echo "Setting xamarin sdk version"
   sudo $AGENT_HOMEDIRECTORY/scripts/select-xamarin-sdk.sh $(mono.version)
  displayName: 'Select Xamarin SDK $(mono.version)'

All 30 comments

Hi. I dont think so.

I dont want to downgrade de library to a preview version. It should work in a actual version.

I don't suggest to downgrade. Did you update VS and all the Xamarin components?
See also: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/852

Yes.

The error didnt occur On Visual Studio, but On AzureDevops Build Pipeline. I managed to make it work with Mac OS hosted agent using a console script similar to the existing On link you have passed. But i could not make it work in a custom agent, even with Xcode and mono updated, using the console script or dont.

not sure, this works on our Azure DevOps build pipelines. @bgavrilMS @trwalke thoughts?

Have you tried remote connecting to the custom agent and building from VS manually? If you are able to manually build from VS on the custom hosted agent then azure devops should be ale to build on the same machine.

Hi.

It build On Visual Studio For Mac installed On custom agent.

Hi @mpghelli I have reached out to the xamarin team who owns the "AuthenticationServices.ASWebAuthenticationSession" api to see if they have any ideas on how to resolve this. I will update you with more info soon

Hi @mpghelli The Xamarin team would like to know what version of Xamarin.iOS you are running on the agent.

You can check what version is installed with
"monop -r:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Xamarin.iOS.dll | grep ASWebAuthenticationSession"

Hi @mpghelli, any updates on the xamarin.iOS version? Your logs say "Xamarin.iOS, Version=0.0.0.0" but I don't think that is correct.

closing due to lack of response

Hi. Sorry about non response. I was on vacation. The Xamarin.iOS version is 12.2.1.15

thanks for the update @mpghelli

@mpghelli Can you run the build in diagnostic mode so the full logs are printed and post a text file with the full build log?

I also have this issue with my Azure DevOps pipeline. I'm getting the following errors:

ASWebAuthenticationSessionBrowser .cs(6,7): error CS0246: The type or namespace name 'AuthenticationServices' could not be found (are you missing a using directive or an assembly reference?) [/Users/vsts/agent/2.158.0/work/1/s/AgentConnectMobile/AgentConnectMobile.iOS/AgentConnectMobile.iOS.csproj]
ASWebAuthenticationSessionBrowser .cs(14,9): error CS0246: The type or namespace name 'ASWebAuthenticationSession' could not be found (are you missing a using directive or an assembly reference?) [/Users/vsts/agent/2.158.0/work/1/s/AgentConnectMobile/AgentConnectMobile.iOS/AgentConnectMobile.iOS.csproj]
ASWebAuthenticationSessionBrowser .cs(49,72): error CS0246: The type or namespace name 'IASWebAuthenticationPresentationContextProviding' could not be found (are you missing a using directive or an assembly reference?) [/Users/vsts/agent/2.158.0/work/1/s/AgentConnectMobile/AgentConnectMobile.iOS/AgentConnectMobile.iOS.csproj]
ASWebAuthenticationSessionBrowser .cs(51,51): error CS0246: The type or namespace name 'ASWebAuthenticationSession' could not be found (are you missing a using directive or an assembly reference?) [/Users/vsts/agent/2.158.0/work/1/s/AgentConnectMobile/AgentConnectMobile.iOS/AgentConnectMobile.iOS.csproj]

I came across a script found here that when I use resolves all but one error:

ASWebAuthenticationSessionBrowser.cs(49,72): error CS0246: The type or namespace name 'IASWebAuthenticationPresentationContextProviding' could not be found (are you missing a using directive or an assembly reference?) [/Users/vsts/agent/2.158.0/work/1/s/AgentConnectMobile/AgentConnectMobile.iOS/AgentConnectMobile.iOS.csproj]

The project builds fine in Visual Studio.

My current YAML file looks like the following:

- script: |
    echo "Setting mono version to 5.12.0"
    SYMLINK=5_12_0_XC10_PRE
    MONOPREFIX=/Library/Frameworks/Mono.framework/Versions/$SYMLINK
    echo "##vso[task.setvariable variable=DYLD_FALLBACK_LIBRARY_PATH;]$MONOPREFIX/lib:/lib:/usr/lib:$DYLD_LIBRARY_FALLBACK_PATH"
    echo "##vso[task.setvariable variable=PKG_CONFIG_PATH;]$MONOPREFIX/lib/pkgconfig:$MONOPREFIX/share/pkgconfig:$PKG_CONFIG_PATH"
    echo "##vso[task.setvariable variable=PATH;]$MONOPREFIX/bin:$PATH"
    echo "Appending AppleSdkRoot to Settings.plist"
    mkdir -p /Users/vsts/Library/Preferences/Xamarin
    cd /Users/vsts/Library/Preferences/Xamarin
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"https://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><dict><key>AppleSdkRoot</key><string>/Applications/Xcode_10.app</string></dict></plist>" >> Settings.plist
    echo "Setting Xcode version to 10 for Visual Studio for Mac"
    sudo xcode-select -s /Applications/Xcode_10.app/Contents/Developer
    sudo xcodebuild -showsdks
    sudo $AGENT_HOMEDIRECTORY/scripts/select-xamarin-sdk.sh 5_12_0_XC10_PRE
  displayName: 'Select the Xamarin SDK version'
  enabled: true

- task: XamariniOS@2
  inputs:
    solutionFile: '**/*iOS.csproj'
    configuration: 'Release'
    packageApp: false
    runNugetRestore: true

Here is another link for reference: https://developercommunity.visualstudio.com/content/problem/363357/error-failed-to-resolve-authenticationservicesaswe.html

@trwalke I emailed my diagnostic log to your first.[email protected] account.

This should work now on a windows agent, we run it as well. I believe the Hosted Mac agent hasn't been updated yet. Can you check on a local mac agent, i.e. update XCode to the latest (11.1) ?

@bgavrilMS my Mac machine is updated to the latest XCode (11.1) and my local builds are successful...is that what you are asking?

I'm trying to understand the root cause of the issue. It seems to be that Azure DevOps Hosted Mac image has not been updated to the latest xcode or xamarin sdk. You have a workaround now to use a on-prem build agent at least.

On Azure DevOps, what image do you use? It seems that macos-latest does have xcode 11 but it isn't the default

https://github.com/Microsoft/azure-pipelines-image-generation/blob/master/images/macos/macos-10.14-Readme.md

@bgavrilMS I'm currently using vmImage: 'macos-latest'. When I try to specify vmImage: 'macOS-11.1' I get an warning/error: An image label with the label macOS-11.1 does not exist.

Edit: which makes sense because that is specifying the macOS, not Xcode. I also tried specifying vmImage: 'macOS-10.14' and I still get the type or namespace name could not be found error.

Is there a way to specify the XCode version in the XamariniOS@2 task or is the XCode version tied to the vmImage?

@ryanbuening can you try running this script to see if it works?
some people online have reported this working for them

- script: |
    echo "Setting mono version to 5.12.0"
    SYMLINK=5_12_0_XC10_PRE
    MONOPREFIX=/Library/Frameworks/Mono.framework/Versions/$SYMLINK
    echo "##vso[task.setvariable variable=DYLD_FALLBACK_LIBRARY_PATH;]$MONOPREFIX/lib:/lib:/usr/lib:$DYLD_LIBRARY_FALLBACK_PATH"
    echo "##vso[task.setvariable variable=PKG_CONFIG_PATH;]$MONOPREFIX/lib/pkgconfig:$MONOPREFIX/share/pkgconfig:$PKG_CONFIG_PATH"
    echo "##vso[task.setvariable variable=PATH;]$MONOPREFIX/bin:$PATH"
    echo "Appending AppleSdkRoot to Settings.plist"
    mkdir -p /Users/vsts/Library/Preferences/Xamarin
    cd /Users/vsts/Library/Preferences/Xamarin
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"https://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><dict><key>AppleSdkRoot</key><string>/Applications/Xcode_10.app</string></dict></plist>" >> Settings.plist
    echo "Setting Xcode version to 10 for Visual Studio for Mac"
    sudo xcode-select -s /Applications/Xcode_10.app/Contents/Developer
    sudo xcodebuild -showsdks
    sudo $AGENT_HOMEDIRECTORY/scripts/select-xamarin-sdk.sh 5_12_0_XC10_PRE
  displayName: 'Select the Xamarin SDK version'
  enabled: true

https://developercommunity.visualstudio.com/content/problem/363357/error-failed-to-resolve-authenticationservicesaswe.html

@trwalke I ran that script and I'm left with one error as I explained a few posts up above

The error that remains after using that script is:

ASWebAuthenticationSessionBrowser.cs(49,72): error CS0246: The type or namespace name 'IASWebAuthenticationPresentationContextProviding' could not be found (are you missing a using directive or an assembly reference?) [/Users/vsts/agent/2.158.0/work/1/s/AgentConnectMobile/AgentConnectMobile.iOS/AgentConnectMobile.iOS.csproj]

@trwalke I ran that script and I'm left with one error as I explained a few posts up above

The error that remains after using that script is:

ASWebAuthenticationSessionBrowser.cs(49,72): error CS0246: The type or namespace name 'IASWebAuthenticationPresentationContextProviding' could not be found (are you missing a using directive or an assembly reference?) [/Users/vsts/agent/2.158.0/work/1/s/AgentConnectMobile/AgentConnectMobile.iOS/AgentConnectMobile.iOS.csproj]

@ryanbuening ah ok, I missed that link.

I have reached out to the xamarin team to see if they can help us resolve this. Ill update you when I hear back from them

@trwalke any updates from the Xamarin team?

yes, here is the response from the xamarin team

The build machine should be configured to use a matching Xamarin.iOS to match the Xcode you are using. Our latest "stable" Xamarin.iOS, and the one I'd suggest using is 13.4.0.2 if you are using Xcode 11 or 11.1

13.2 is also 8.3 based, and would likely be fine, but anything from the 12.x series may have issues.
We wrote up some details on this use case here: https://docs.microsoft.com/en-us/xamarin/ios/troubleshooting/questions/old-version-xcode

You may have to look at documentation or contact the Azure DevOps folks if you have questions on how to configure their service to use a particular Xamarin.iOS SDK.

I have already contacted azure DevOps support about this to see if they can provide any additional details

@trwalke Just in case it can help. I have posted a solution to the issue mentioned above. Enclose below as well

鈥媁e do not use the ADAL/MSAL library but uses the same classes (ASWebAuthenticationSession) and we were facing the same build issue.
From our understanding, it was related to the default XCode version used on the Mac OS agent.

Trying to set the XCode version using a bash script calling xcode-select, we were not able to get it working until today.

The lastest Mac OS image (10.14) is now using XCode 11.1 as default and we were able to get it working by adding the following tasks to our pipeline

  • Add a DotNet installer task to use .Net Core 3.x (needed for Mono 6.x)
  • Add Bash task to set the Mono version to 6.4.0
  • Add Bash task to select the Xamarin SDK

YAML definition

variables:
  netcore.version: '3.0.x'
    mono.version: '6_4_0'

steps:
- task: UseDotNet@2
  displayName: 'Use .Net Core SDK $(netcore.version)'
  inputs:
    version: '$(netcore.version)'
- bash: |
   SYMLINK=$(mono.version)

   MONOPREFIX=/Library/Frameworks/Mono.framework/Versions/$SYMLINK

   echo "##vso[task.setvariable variable=DYLD_FALLBACK_LIBRARY_PATH;]$MONOPREFIX/lib:/lib:/usr/lib:$DYLD_LIBRARY_FALLBACK_PATH"
   echo "##vso[task.setvariable variable=PKG_CONFIG_PATH;]$MONOPREFIX/lib/pkgconfig:$MONOPREFIX/share/pkgconfig:$PKG_CONFIG_PATH"
   echo "##vso[task.setvariable variable=PATH;]$MONOPREFIX/bin:$PATH"
  displayName: 'Set Mono $(mono.version)'
- bash: |
   echo "Setting xamarin sdk version"
   sudo $AGENT_HOMEDIRECTORY/scripts/select-xamarin-sdk.sh $(mono.version)
  displayName: 'Select Xamarin SDK $(mono.version)'

Thank you so much @superjulius !

Was this page helpful?
0 / 5 - 0 ratings