AzureAD / microsoft-authentication-library-for-dotnet

Microsoft Authentication Library (MSAL) for .NET
https://aka.ms/msal-net
MIT License
1.41k stars 345 forks source link

'Link Framework SDKs Only' causes MT2101 can't resolve the reference error #745

Closed vikram-ma closed 5 years ago

vikram-ma commented 5 years ago

Which Version of ADAL are you using ? Microsoft.Identity.Client 2.6.2

Which platform has the issue? Xamarin iOS

Repro Add Microsoft.Identity.Client 2.6.2 package to Xamarin Forms project Set linker behavior to 'Link Framework SDKs only' Compile+Link

Expected behavior There should not be any linker error.

Actual behavior Setting Linker Behavior to 'Link Framework SDKs Only' causes MTouch MT2101 error.

Additional context/ Logs / Screenshots / Users/TestApp/iOS/MTOUCH: Error MT2101: Can't resolve the reference 'System.String System.String::TrimStart(System.Char)', referenced from the method 'Microsoft.Identity.Json.Schema.JsonSchema Microsoft.Identity.Json.Schema.JsonSchemaBuilder::ResolveReferences(Microsoft.Identity.Json.Schema.JsonSchema)' in 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. (MT2101) (TestApp.iOS)

RSBlek commented 5 years ago

I can reproduce this issue with 2.6.1 and Xamarin Forms.

My Android Build fails with 'Link Framework SDKs only' and with 'None' the build runs till the end, but the App crashes during the splash screen.

vikram-ma commented 5 years ago

@chixlol Crash in splash screen is due to MissingMethodException, it is already logged, issue number https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/744

irjudson commented 5 years ago

I am having this issue as well. In fact none of the link options compiles successfully in my Azure DevOps Pipeline -- which is quite discouraging.

Rashun001 commented 5 years ago

Seeing the same issues with DevOps Pipeline. I raised this issue in the Visual Studio for Mac Group, and back channelling through them. But does anyone have a direct connect with the DevOps Team. A simple request, create an Agent that has all version of Tooling and SDK, or Libraries needs Unit Tests for DevOps? Not sure which.

narindermakin commented 5 years ago

***Update to VS Community Build 15.9.4 resolved the linker error.

I can reproduce it with version 2.6.2. The cause seems to be the TrimStart method in JsonSchemaModelBuilder. This method is not present in mscorlib version 4.0.0.0 or in .NET standard (2.0) implementation of String and fails. Could have used TrimStart(new char[] { '#' }) instead of TrimStart('#'). Same issue with String.Split function that takes a char.

bgavrilMS commented 5 years ago

Looking at these 2 issues

bgavrilMS commented 5 years ago

@narindermakin - thanks for digging this up. Indeed I can see that the VSTS Hosted 2017 agent is still using VisualStudio/15.8.7, which would explain why I can see this issue at all (I use the latest 15.9.4).

Will investigate some more and contact the VSTS team to get an update on when the hosted agent image will be updated.

bgavrilMS commented 5 years ago

I logged a bug on the Xamarin folk. Still investigating on Mac.

bgavrilMS commented 5 years ago

It looks like a Mono or Xamarin bug. I can repro it with VS 15.8.7 on Windows.

Please upgrade to latest VS (15.9.*) or VS for Mac.

narindermakin commented 5 years ago

@bgavrilMS thank you for confirming the resolution. One more assistance needed - with upgrade to 2.6.2 version and Visual Studio 15.9.4, iOS throws following linker exception. It works with version 1.12 preview 0008

{Microsoft.Identity.Client.MsalClientException: Failed to invoke SFSafariViewController ---> ObjCRuntime.RuntimeException: BlockLiteral.SetupBlock is not supported when the dynamic registrar has been linked away. at ObjCRuntime.BlockLiteral.SetupBlock (System.Delegate trampoline, System.Delegate userDelegate, System.Boolean safe) [0x00002] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.12/src/Xamarin.iOS/ObjCRuntime/Blocks.cs:94 at ObjCRuntime.BlockLiteral.SetupBlockUnsafe (System.Delegate trampoline, System.Delegate userDelegate) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.12/src/Xamarin.iOS/ObjCRuntime/Blocks.cs:162 at AuthenticationServices.ASWebAuthenticationSession..ctor (Foundation.NSUrl url, System.String callbackUrlScheme, AuthenticationServices.ASWebAuthenticationSessionCompletionHandler completionHandler) [0x00040] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.12/src/Xamarin.iOS/AuthenticationServices/ASWebAuthenticationSession.g.cs:81 at Microsoft.Identity.Client.Platforms.iOS.SystemWebview.SystemWebUI.Authenticate (System.Uri authorizationUri, System.Uri redirectUri, Microsoft.Identity.Client.Core.RequestContext requestContext) [0x00021] in <5ec94b08a95e4da5b60d34ec75f131dd>:0 --- End of inner exception stack trace --- at Microsoft.Identity.Client.Platforms.iOS.SystemWebview.SystemWebUI.Authenticate (System.Uri authorizationUri, System.Uri redirectUri, Microsoft.Identity.Client.Core.RequestContext requestContext) [0x000dd] in <5ec94b08a95e4da5b60d34ec75f131dd>:0 at Microsoft.Identity.Client.Platforms.iOS.SystemWebview.SystemWebUI+d4.MoveNext () [0x0004a] in <5ec94b08a95e4da5b60d34ec75f131dd>:0 --- End of stack trace from previous location where exception was thrown --- at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest+d10.MoveNext () [0x000de] in <5ec94b08a95e4da5b60d34ec75f131dd>:0 --- End of stack trace from previous location where exception was thrown --- at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest+d9.MoveNext () [0x000e9] in <5ec94b08a95e4da5b60d34ec75f131dd>:0 --- End of stack trace from previous location where exception was thrown --- at Microsoft.Identity.Client.Internal.Requests.RequestBase+d16.MoveNext () [0x00165] in <5ec94b08a95e4da5b60d34ec75f131dd>:0 --- End of stack trace from previous location where exception was thrown --- at Microsoft.Identity.Client.PublicClientApplication+d26.MoveNext () [0x000d7] in <5ec94b08a95e4da5b60d34ec75f131dd>:0 --- End of stack trace from previous location where exception was thrown --- at Microsoft.Identity.Client.PublicClientApplication+d17.MoveNext () [0x000ac] in <5ec94b08a95e4da5b60d34ec75f131dd>:0 --- End of stack trace from previous location where exception was thrown --- at LitMemMobApp.MainPage+d__6.MoveNext () [0x0004c] in --------------\MainPage.xaml.cs:143 ErrorCode: authentication_ui_failed}

irjudson commented 5 years ago

I am using the latest version of VS for mac; still have the problem with Azure Devops...

irjudson commented 5 years ago

It looks like a Mono or Xamarin bug. I can repro it with VS 15.8.7 on Windows.

Please upgrade to latest VS (15.9.*) or VS for Mac.

see above

bgavrilMS commented 5 years ago

@irjudson - what agent are you using on VSTS? I just checked and all the hosted Mac agents use VS for Mac 7.7.1 or earlier.

@narindermakin - when do you get that exception? It looks like a runtime exception - please provide more details. Are you just performing normal interactive auth in iOS in a Xamarin XForms app? I will try our Xamarin sample on iOS and report back.

bgavrilMS commented 5 years ago

@narindermakin - I can't repro that exception. I tried with our sample https://github.com/Azure-Samples/active-directory-xamarin-native-v2 but also with an upgraded version (same code, but added to a brand new XForms project, using the latest xforms.dll)

Rashun001 commented 5 years ago

@narindermakin - I can't repro that exception. I tried with our sample https://github.com/Azure-Samples/active-directory-xamarin-native-v2 but also with an upgraded version (same code, but added to a brand new XForms project, using the latest xforms.dll)

Which version of XForms are you using latest v.Next 4.0 or 3.x.

Also are you seeing this via Azure DevOps, or are you only running a local agent?

bgavrilMS commented 5 years ago

I am using latest stable 3.x. I have seen this running on my local machine. It should not matter if it is local machine or Azure DevOps, it's the Visual Studio version that matters.

narindermakin commented 5 years ago

I am using 3.4.0.1008975 last stable version of Xamarin.Forms with VS 15.9.4 on Windows paired with a Mac (cleared cache on mac also). The exception comes in the call App.PCA.AcquireTokenAsync(scopes, account, App.UiParent). I have monotouch extra args as --optimize=-blockliteral-setupblock. Removing these extra args get's past the acquiretokensync call. However, the token is not cached.

Note that App.PCA.AcquireTokenSilentAsync(scopes, account, authority, false) works as expected and returns below, (since account is null)

ex = {Microsoft.Identity.Client.MsalUiRequiredException: Null account was passed in AcquiretokenSilent API. Pass in an account object or call acquireToken to authenticate. at Microsoft.Identity.Client.ClientApplicationBase+d__45....

<------App.PCA.AcquireTokenAsync(scopes, account, App.UiParent) where account is null ----> 2019-01-03 17:25:37.117 LitMemMobApp.iOS[5574:581218] Failed to invoke SFSafariViewController at Microsoft.Identity.Client.Platforms.iOS.SystemWebview.SystemWebUI.Authenticate (System.Uri authorizationUri, System.Uri redirectUri, Microsoft.Identity.Client.Core.RequestContext requestContext) [0x000dd] in <5ec94b08a95e4da5b60d34ec75f131dd>:0 at Microsoft.Identity.Client.Platforms.iOS.SystemWebview.SystemWebUI+d4.MoveNext () [0x0004a] in <5ec94b08a95e4da5b60d34ec75f131dd>:0 --- End of stack trace from previous location where exception was thrown --- at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest+d10.MoveNext () [0x000de] in <5ec94b08a95e4da5b60d34ec75f131dd>:0 --- End of stack trace from previous location where exception was thrown --- at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest+d9.MoveNext () [0x000e9] in <5ec94b08a95e4da5b60d34ec75f131dd>:0 --- End of stack trace from previous location where exception was thrown --- at Microsoft.Identity.Client.Internal.Requests.RequestBase+d16.MoveNext () [0x00165] in <5ec94b08a95e4da5b60d34ec75f131dd>:0 --- End of stack trace from previous location where exception was thrown --- at Microsoft.Identity.Client.PublicClientApplication+d26.MoveNext () [0x000d7] in <5ec94b08a95e4da5b60d34ec75f131dd>:0 --- End of stack trace from previous location where exception was thrown --- at Microsoft.Identity.Client.PublicClientApplication+d17.MoveNext () [0x000ac] in <5ec94b08a95e4da5b60d34ec75f131dd>:0 --- End of stack trace from previous location where exception was thrown --- at LitMemMobApp.MainPage+d__6.MoveNext () [0x000d5] in ................ 2019-01-03 17:25:47.884 LitMemMobApp.iOS[5574:581218] iOS Language:en-US 2019-01-03 17:25:47.884 LitMemMobApp.iOS[5574:581218] .NET Language/Locale:en-US The app has been terminated.

--- inner exception --- BlockLiteral.SetupBlock is not supported when the dynamic registrar has been linked away.

(ObjCRuntime.RuntimeException) at ObjCRuntime.BlockLiteral.SetupBlock (System.Delegate trampoline, System.Delegate userDelegate, System.Boolean safe) [0x00002] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.12/src/Xamarin.iOS/ObjCRuntime/Blocks.cs:94 at ObjCRuntime.BlockLiteral.SetupBlockUnsafe (System.Delegate trampoline, System.Delegate userDelegate) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.12/src/Xamarin.iOS/ObjCRuntime/Blocks.cs:162 at UIKit.UIAlertActio n.Create (System.String title, UIKit.UIAlertActionStyle style, System.Action`1[T] handler) [0x0002e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.12/src/Xamarin.iOS/UIKit/UIAlertAction.g.cs:106 at Xamarin.Forms.Platform.iOS.Platform.CreateActionWithWindowHide (System.String text, UIKit.UIAlertActionStyle style, System.Action setResult, UIKit.UIWindow window) [0x00015] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:311 at Xamarin.Forms.Platform.iOS.Platform.PresentAlert (Xamarin.Forms.Internals.AlertArguments arguments) [0x00098] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:329 at Xamarin.Forms.Platform.iOS.Platform.<.ctor>b__7_1 (Xamarin.Forms.Page sender, Xamarin.Forms.Internals.AlertArguments arguments) [0x0000a] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:50 at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, System. Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0003b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.12/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/MonoMethod.cs:305 2

bgavrilMS commented 5 years ago

Closing, I will update this thread when I hear back from the VSTS people about them updating the Hosted build images.

minaairsupport commented 5 years ago

I think Appcenter face the same issue

CSC : error CS1705: Assembly 'AgentWay' with identity 'AgentWay, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'Microsoft.Identity.Client, Version=2.6.2.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae' which has a higher version than referenced assembly 'Microsoft.Identity.Client' with identity 'Microsoft.Identity.Client, Version=2.1.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'

maybe that regarding to visual studio version installed

https://docs.microsoft.com/en-us/appcenter/build/software#visual-studio-for-mac

bgavrilMS commented 5 years ago

Yes, App Center will have the same problem.

The VSTS (Azure DevOps) team have a tentative deadline of end of January for updating the Hosted agents build. It seems to take longer because the new image is very large.

stezma commented 5 years ago

Any update related to this issue. Azure Devops build is failing from last few months @bgavrilMS : It is not failing in App Center. I verified, it is only failing in Azure Devops

bgavrilMS commented 5 years ago

@stezma - I am sorry I do not have any update. I will ping the DevOps guys again.

bgavrilMS commented 5 years ago

Possible workaround for VSTS https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/852#issuecomment-461318277

kgbuddhima commented 5 years ago

I also have this issue in iOS VSTS build. MTOUCH : error MT2101: Can't resolve the reference 'System.String System.String::Trim(System.Char)', referenced from the method 'System.Threading.Tasks.Task`1 FFImageLoading.DataResolvers.BundleDataResolver::ResolveFromBundlesAsync(System.String,System.String,FFImageLoading.Work.TaskParameter,System.Threading.CancellationToken)' in 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.

is there any solution for this ?

bgavrilMS commented 5 years ago

@kgbuddhima - yes, update Visual Studio

MouthOfMadness commented 5 years ago

Is there a workaround, I just started getting this bug in devops.

(default target) (1) -> (_CompileToNative target) -> MTOUCH : error MT2101: Can't resolve the reference 'System.String System.String::Trim(System.Char)', referenced from the method 'System.Threading.Tasks.Task`1 FFImageLoading.DataResolvers.BundleDataResolver::ResolveFromBundlesAsync(System.String,System.String,FFImageLoading.Work.TaskParameter,System.Threading.CancellationToken)' in 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. [/Users/vsts/agent/2.153.2/work/1/s/Mobile/****.iOS.csproj]

markrobert194 commented 3 years ago

Did anyone find a fix for this?