Microsoft-authentication-library-for-dotnet: dll reference for Xamarin Forms Android error

Created on 29 Jun 2017  路  15Comments  路  Source: AzureAD/microsoft-authentication-library-for-dotnet

When you create a new Xamarin Forms Application solution in either Visual Studio 2017 (win) or Visual Studio for Mac the Droid project gets the wrong dll referenced.

The nuget installer installs the dll from "/packages/Microsoft.Identity.Client.1.1.0-preview/lib/netstandard1.3/Microsoft.Identity.Client.dll" into the Android project. The PCL and iOS projects gets correct dll's

If you manually remove the referenced netstandard1.3 dll and add dll from monoandroid70 directory the code works again.

All 15 comments

I think this is the same issue that I'm having. I'm not sure I understand what your solution was in this case. Did you uninstall the NuGet package for the Android project, and manually add the .dll as a reference?

Leaving the PCL NuGet package as-is? When I try to add the .dll directly it fails because it's already referenced by the build-system, despite my not having the NuGet package added for the Android project. I'm assuming because it's transitively being referenced from the PCL (using NetStandard1.4).

image

Even if we are using Android targets, NuGet resolution tries to pull .NET standard 1.3.
@AlexanderViken , @scionwest : does it still happen in recent versions of VS?

@scionwest I managed to add a reference directly, by first uninstalling the package from the shared project and the android project. Then I manually added the monoandroid70 dll to the android project. Finally I added the NuGet package back to the shared project.
But I get a lot of errors because I downgraded Xamarin Forms to 2.3.4.224 as in the example project.
I'll try upgrading now.... I am very confused by the contradictive instructions. It seems anyone can post anything on the internet ;)

@scionwest @AlexanderViken @jhvanderven What version of Xamarin Android is your app targeting - 7 or 8?

We compile our library against both netstandard1.3 and Xamarin Android 8 (MonoAndroid8), however monoandroid should be automatically picked up from a xamarind project.

I am also hitting same issue, with latest version of nugets and VS 2017 updates. I am targeting Android 8.1.

@pankajisgarg - thx for reporting. I am unable to repro this, here's what I tried:

  1. Create a new Xamarin XAML (Xamarin.Forms) OR Android Class Library (Xamarin) OR Android App Single Page. All target MonoAndroid 8.1 (this is not the same as Android version - right click on the Mono.Android reference in Solution Explorer and inspect the path to find the version).
  2. Add a NuGet reference to MSAL latest version (1.1.14-preview) using Visual Studio 15.7.4 (latest version at time of writing).
  3. Inspect the reference to the MSAL (e.g. by looking at the project.assets.json file or by newing up AuthenticationAgentContinuationHelper, which is only available in Android)

Actual: MonoAdroid81 version of MSAL is used
Expected: MonoAndroid8.1 version of MSAL is used

Note that if you target a version of MonoAndroid lower than 8.1 then NuGet will pick netstandard 1.3 - this is expected, have a look at this NuGet tool that simulates choosing a target framework.

For a workaround, could you try https://stackoverflow.com/questions/48526219/is-there-a-way-to-force-a-project-reference-to-net-standard-project-to-a-specif

We believe this issue has been fixed. Feel free to re-open if this is still an issue for you.

I just created a completely new Xamarin app (3.6), added MSAL 3.0.4-preview and I can't get a reference to AuthenticationContinuationHelper like in the official sample: https://github.com/Azure-Samples/active-directory-xamarin-native-v2. I can only imagine because of this issue. Here's an excerpt from project.assets.json:

{
"version": 3,
"targets": {
"MonoAndroid,Version=v8.1": {
    "Microsoft.CSharp/4.5.0": {
    "type": "package",
    "frameworkAssemblies": [
        "Microsoft.CSharp"
    ],
    "compile": {
        "ref/MonoAndroid10/_._": {}
    },
    "runtime": {
        "lib/MonoAndroid10/_._": {}
    }
    },
    "Microsoft.Identity.Client/3.0.4-preview": {
    "type": "package",
    [...]
    },
    "compile": {
        "ref/netstandard1.3/Microsoft.Identity.Client.dll": {}
    },
    "runtime": {
        "lib/netstandard1.3/Microsoft.Identity.Client.dll": {}
    }
},

Am I missing something? The sample is using a rather old Xamarin version, so perhaps that's the difference.

Visual Studio 2017 (15.9.11)

@Aculeo You will need to update to MonoAndroid 9.0 and then check that the file path for MSAL in the Android csproj is under \MonoAndroid90\ and not \netstandard1.3\. Then you should be good to go. If not, please tag me here.

Thanks, that did the trick. Works perfectly.

Aculeo and Jennyf19, could you give more details on how to:
update to MonoAndroid 9.0 and then check that the file path for MSAL in the Android csproj is under \MonoAndroid90\ and not \netstandard1.3\

@HectorMeneses333 right click on the Android project -> Properties, there is a dropdown for selecting the target Android version. Change it to Android 9.0 (Pie). This doesn't change the minimum supported Android version, that's a different setting.

grafik

The project.assets.json you can find in the Android project, under the obj folder.

Thanks @Aculeo

@HectorMeneses333 you might also have to manually change the csproj file on Android to the \monoandroid90\ file path.

Thanks a lot for your help! @Aculeo, @jennyf19 :)
I updated Target Framework to Android 9.0 (Pie) under Application
Also updated Target Android version to Android 9.0 ( API Level 28 - Pie ) under Android Manifest

I didn't have to modify the project.assets.json file.

And finally I had to Enable Multi-Dex under Android Options because I was getting an error "java.exe exited with code 2" at compile time.

@HectorMeneses333 thanks for the update.

Was this page helpful?
0 / 5 - 0 ratings