Xamarin.Forms: ‘MSBuild:UpdateDesignTimeXaml’ code generator crashed solution

If you are facing an issue after updating the Xamarin.Forms version in your project, with the following error:

SOMEXAMLFILE.xaml: Error: The 'MSBuild:UpdateDesignTimeXaml' code generator crashed: Not connected
  at MonoDevelop.Core.Execution.RemoteProcessConnection.PostMessage (MonoDevelop.Core.Execution.BinaryMessage message, System.Threading.Tasks.TaskCompletionSource`1[TResult] cs, System.Boolean checkInitialized) [0x000c3] in /Users/builder/azdo/_work/2/s/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/RemoteProcessConnection.cs:438 
  at MonoDevelop.Core.Execution.RemoteProcessConnection.SendMessage (MonoDevelop.Core.Execution.BinaryMessage message) [0x00031] in /Users/builder/azdo/_work/2/s/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/RemoteProcessConnection.cs:385 
  at MonoDevelop.Projects.MSBuild.RemoteBuildEngineManager+<>c__DisplayClass20_0.<GetBuildEngine>b__5 () [0x00252] in /Users/builder/azdo/_work/2/s/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/RemoteBuildEngineManager.cs:323 
  at MonoDevelop.Projects.MSBuild.RemoteBuildEngineManager.GetBuildEngine (MonoDevelop.Core.Assemblies.TargetRuntime runtime, System.String minToolsVersion, System.String solutionFile, System.String group, System.Object buildSessionId, System.Boolean setBusy, System.Boolean allowBusy) [0x0036f] in /Users/builder/azdo/_work/2/s/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/RemoteBuildEngineManager.cs:273 
  at MonoDevelop.Projects.MSBuild.RemoteBuildEngineManager.GetRemoteProjectBuilder (System.String projectFile, System.String solutionFile, MonoDevelop.Core.Assemblies.TargetRuntime runtime, System.String minToolsVersion, System.Object buildSessionId, System.Boolean setBusy, System.Boolean allowBusy) [0x000df] in /Users/builder/azdo/_work/2/s/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/RemoteBuildEngineManager.cs:176 [...]

Then clean your solution, and restart Visual Studio for Mac.

This content has 2 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Xamarin.UWP deployment failure: 0x80073D1F

Registering the application to run from layout...
DEP0700: Registration of the app failed. [0x80073D1F] 
	DeploymentSucceeded = False
	DeploymentError = Err_Deploy_Register
	DeploymentUserError = False
	DeploymentHRESULT = 2147958047
	HasSharedCode = False
	Target.Id = 512
	ProjectGuid = {5894aed2-9bb1-434b-8b49-3b86572709b7}
	Project.TargetPlatformVersion = 10.0.19041.0
	Project.TargetPlatformMinVersion = 10.0.17763.0
Deleting file "vs.appxrecipe" from layout...
DeployAsync: END (Failure, 0:00:01.499)
Deploy: END (Failure, 0:00:01.5)

Solution

Remove your application source code from shared folder
or
You are being signed in with my Microsoft account in windows instead of the local user account
or
Visual Studio is not able to delete the application data in your local packages folder, go to C:\Users\<YOURNAME>\AppData\Local\Packages\ folder, and delete your applications folder manually.
or
browse more solution at here
🙂

This content has 2 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Upgrading Xamarin.Forms projects to .NET MAUI with upgrade assistant

MAUI is still in preview state, so the production apps are not recommended to upgrade to .NET MAUI. But it is important to be open to new technology, so take some time to review the update.

It’s possible that by the time you read this post, you’ll be able to convert a MAUI projects from UI, but it’s not currently an available feature for me.

What you will need

  • Windows machine
  • Visual Studio 2022 installed

Install required tools for MAUI

Open a command prompt and give out the following command:

dotnet workload install maui

If you have installed maui already, then you wont need to run this command again.

Install upgrade-assistant

There is a tool developed by Microsoft, not originally for MAUI, but because it is based on a fully extensible model, it has been made available for MAUI projects. Xamarin.Forms projects can be translated to the new version of the projects with this app:
https://dotnet.microsoft.com/en-us/platform/upgrade-assistant

dotnet tool install --global upgrade-assistant

Use the upgrade assistant

It is important to note that this application cannot independently translate Xamarin.Forms apps to MAUI. It only helps us in the upgrade process.

That’s why the app asks for constant instructions, so we can’t leave the machine running while we make coffee 🙂

Let’s change the directory of your command prompt to the directory where you store the .sln file

upgrade-assistant upgrade SolutionName.sln

Watch out for the output of the console. If everything goes well, your solution can be transformed to maui without issues.

In the header section of the console output, you will see what steps are required (or suggested) in order to complete the migration. You can decide what to do with the next step: Apply, skip, or do something else with it. If everything goes well, you will only need to press apply.

The output of the upgrade-assistant

Once you have finished the upgrade assistant process, you can see the changes. Mostly in source codes and project files.

Namespace changes

This content has 2 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Xamarin UWP: Use multilanguage resource files properly

IIf you are experiencing the oddity that the UWP version of your application can’t find the correct language version of your ‘resx’ files, then you have probably fallen into the same error I did.

The language management of UWP apps works differently to its Android and iOS counterparts.

Reade more about it at: https://docs.microsoft.com/en-us/windows/apps/design/globalizing/manage-language-and-region

How the UWP deals with multilingualism in brief

Only the union can be set as UI language

Two different lists are considered as the list of languages supported by the application. One is the list of languages supported by windows (language pack installed), and the other is the list of languages supported by the application (resx files created for them). The intersection of these can only be handled by the language switching code.

Where to define all of the supported languages by the app

Easily, without mainting it you can define them in only one line making a change in ‘Package.appxmanifest‘ file.

  <Resources>
    <Resource Language="x-generate" />
  </Resources>

The x-generate value will collect all of the available languages on compile time.

Otherwise, you will need to list all of them one by one:

  <Resources>
    <Resource Language="EN-US" />
    <Resource Language="JA-JP" />
    <Resource Language="FR-FR" />
  </Resources>

Best practice?

Perhaps, if the application is running on UWP platform, you should make an if statement for the runtime platform and filter out languages that are not supported by windows.

// Get all of the supported language by windows in BCP-47 language tag (i.e. "en-US")
IReadOnlyList<string> userLanguages = Windows.System.UserProfile.GlobalizationPreferences.Languages;
This content has 2 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Xamarin.Forms: Clear cookies in WebViews

If you are authenticating through WebView, and acquire a token on successful login, you may have experienced that on re-login scenarios the authentication details is not requested again, because the browser is storing the previously logged in user. You may have to clear the browser’s cookies section to get rid of the useless previous user’s details.

Go ahead and create a dependency service, because we will write some platform specific code! 🙂

Xamarin.Forms code

Define an interface like this

	public interface IDeviceSpecificService
	{
		void ClearCookies();
	}

And use the code like this

DependencyService.Get<IDeviceSpecificService>().ClearCookies();

Xamarin.Android implementation

[assembly: Dependency(typeof(DeviceSpecificService))]
namespace AnAwesomeCompany.AGreatProject.Presentation.Droid.Implementations
{
	public class DeviceSpecificService : IDeviceSpecificService
	{
		public void ClearCookies()
		{
			Android.Webkit.CookieManager.Instance.RemoveAllCookie();
		}
	}
}

Xamarin.IOS implementation

[assembly: Dependency(typeof(DeviceSpecificService))]
namespace AnAwesomeCompany.AGreatProject.Presentation.IOS.Implementations
{
    public class DeviceSpecificService : IDeviceSpecificService
	{
		public void ClearCookies()
		{
              NSHttpCookieStorage CookieStorage = NSHttpCookieStorage.SharedStorage;
              foreach (var cookie in CookieStorage.Cookies)
                      CookieStorage.DeleteCookie(cookie);
		}
	}
}
This content has 2 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.