Base solution for your next web application
Open Closed

Xamarin iOS issue xct:eventtocommandbehavior not found in xmlns #11628


User avatar
0
omkarchoudhari created

Hello,

I am using MVC Jquery Template (Version 12.0.0) with .Net (version 7) and Xamarin for Android & iOS. This is a single Tenant application - only with Default Tenant.

My query is,

  1. In iOS real device(iPhone 14 and Iphone13) when I am trying to run my application in debug mode (in release mode as well), I am getting the following error;

"InnerException {Xamarin.Forms.Xaml.XamlParseException: Position 162:10. Type xct:EventToCommandBehavior not found in xmlns http://xamarin.com/schemas/2020/toolkit at Xamarin.Forms.Xaml.CreateValuesVisitor.Visit (Xamarin.Forms.Xaml.ElementNode node, Xamarin.Forms.Xaml.INode …} Xamarin.Forms.Xaml.XamlParseException"

But it is working in an iOS emulator, the only problem is with a real device. Is there any solution for the same? I need the help ASAP.

**Notes: **

  1. Added device UDID in Developer Account and uploaded Provision Certificate in iOS project
  2. Xamarin.Forms -5.0.0.2578
  3. Xamarin.Essentials-1.7.6
  4. Xamarin.CommunityToolkit - 2.0.6

Code Snippets:

  1. In LoginView.Xaml <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Name="LoginPage" xmlns:xct="http://xamarin.com/schemas/2020/toolkit" x:Class="IMS.Views.LoginView" BackgroundColor="{StaticResource LoginBackgroundColor}" base:ViewManager.AutoWireViewModel="true" Title="{extensions:Translate LogIn}"> . . . . <ContentPage.Behaviors> <xct:EventToCommandBehavior EventName="Appearing" Command="{Binding PageAppearingCommand}" /> </ContentPage.Behaviors> </contentPage>

  2. In LoginViewModel:

    public class LoginViewModel : XamarinViewModel { Default code of ASPNET Zero . . .

    //My Code public ICommand RegisterUserCommand => HttpRequestCommand.Create(Method for Register); public ICommand RegisterGoogleCommand => HttpRequestCommand.Create(Method for Google); public ICommand RegisterMicrosoftCommand => HttpRequestCommand.Create(Method for Microsoft);

    Default code of ASPNET Zero . . .

     private readonly IPublicClientApplication PCA;
     private readonly IGoogleClientManager _googleClientManager;
     public string Token { get; set; }
    

    Default code of ASPNET Zero . . .

     public LoginViewModel(
         IAccountAppService accountAppService,
         IApplicationContext applicationContext,
         IAccountService accountService,
         IDataStorageService dataStorageService)
     {
     .
     .
     .
    
         _googleClientManager = CrossGoogleClient.Current;
         var myUri = new Uri(ApplicationSetting.TenantUrl, UriKind.Absolute);
         PCA = PublicClientApplicationBuilder.Create(ApplicationSetting.ClientID)
                 .WithIosKeychainSecurityGroup(ApplicationSetting.ApplicationId)
                 .WithAuthority(myUri)
                 .WithRedirectUri(ApplicationSetting.RedirectUrl)
                 .Build();
     }
    

    Default code of ASPNET Zero . .

     private async Task PageAppearingAsync()
     {
         PopulateLoginInfoFromStorage();
         await Task.CompletedTask;
     }
    

    Default code of ASPNET Zero . . .

     //My Code
     //#1. Microsoft Login
     public async Task MicrosoftRegistrationCallerAsync()
     {
         try
         {
         	try
         	{
             	var authResult = await PCA.AcquireTokenInteractive(ApplicationSetting.Scopes)
                     	        .WithParentActivityOrWindow(App.ParentWindow)
                             	.WithUseEmbeddedWebView(true)
                             	.ExecuteAsync();
    
             	//#1. External Authentication Model
             	_accountService.CustomExternalAuthenticateModel.ProviderKey = authResult.UniqueId;
             	_accountService.CustomExternalAuthenticateModel.ProviderAccessCode = authResult.AccessToken;
             	_accountService.CustomExternalAuthenticateModel.AuthProvider = "Microsoft";
    
             	await SetBusyAsync(async () =>
             	{
                 		await _accountService.LoginUserExternalAsync();
             	});
         	}
         	catch (Exception ex)
         	{
             	await Application.Current.MainPage.DisplayAlert("Alert", "Invalid Login Credentials, please try again.", "Ok");
             	Console.WriteLine(ex.Message);
         	}
     }
    
     //#1. Google Login
     private async Task RegisterGoogleAsync()
     {
         _googleClientManager.OnLogin += OnLoginCompleted;
         try
         {
             await _googleClientManager.LoginAsync();
         }
         catch (Exception ex)
         {
             await App.Current.MainPage.DisplayAlert("Error", ex.Message, "OK");
         }
     }
    
     //#2. Google Login
     private void OnLoginCompleted(object sender, GoogleClientResultEventArgs&lt;GoogleUser&gt; loginEventArgs)
     {
         if (loginEventArgs.Data != null)
         {
             GoogleUser googleUser = loginEventArgs.Data;
             Token = CrossGoogleClient.Current.AccessToken;
    
             //#1. External Authentication Model
             _accountService.CustomExternalAuthenticateModel.ProviderKey = googleUser.Id.ToString();
             _accountService.CustomExternalAuthenticateModel.ProviderAccessCode = Token;
             _accountService.CustomExternalAuthenticateModel.AuthProvider = "Google";
    
             SetBusyAsync(async () =>
             {
                 await _accountService.LoginUserExternalAsync();
             });
         }
         else
         {
             App.Current.MainPage.DisplayAlert("Error", loginEventArgs.Message, "OK");
         }
    
         _googleClientManager.OnLogin -= OnLoginCompleted;
    
     }
    
     //#3. Google Logout
     public void Logout()
     {
         _googleClientManager.OnLogout += OnLogoutCompleted;
         _googleClientManager.Logout();
     }
    
     //#4. Google Logout
     private void OnLogoutCompleted(object sender, EventArgs loginEventArgs)
     {
         _googleClientManager.OnLogout -= OnLogoutCompleted;
     }
    

Thank you in advance !


5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @omkarchoudhari

    Does this happen if you run a not modified ASP.NET Zero Xamarin app on a real IOS device ?

  • User Avatar
    0
    omkarchoudhari created

    @ismcagdas,

    Sorry for the late response, but requesting you to treat this as URGENT :)

    Yes, we have tested it on the nonmodified template as well. it is giving me the same error.

    Could one of the following reasons be the possibility of this error?

    1. Behaviours folder missing from Mobile.Shared (we are using MVC Core, Jquery but to check, we checked what folder we see in the shared folder of documentation).

    2. Template is using "using MvvmHelpers".

    (Maybe try to use "using Xamarin.CommunityToolkit.ObjectModel" instead of "using MvvmHelpers") as the error is related to community toolkit.

    Thanks

  • User Avatar
    0
    omkarchoudhari created

    @ismcagdas,

    Sorry for the late response, but requesting you to treat this as URGENT :)

    Yes, we have tested it on the nonmodified template as well. it is giving me the same error.

    Could one of the following reasons be the possibility of this error?

    1. Behaviours folder missing from Mobile.Shared (we are using MVC Core, Jquery but to check, we checked what folder we see in the shared folder of documentation).

    2. Template is using "using MvvmHelpers".

    (Maybe try to use "using Xamarin.CommunityToolkit.ObjectModel" instead of "using MvvmHelpers") as the error is related to community toolkit.

    Thanks

    @ismcagdas Any update on this ?

  • User Avatar
    0
    omkarchoudhari created

    @ismcagdas,

    Any update on this? We are chasing a completion here and it depends on resolving this issue.

  • User Avatar
    0
    omkarchoudhari created

    Hello, Is there any update on this Please ?