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.

Xamarin.Forms: Prevent dark mode on iOS, Android

To enforce light mode on the following platforms use this code

iOS Solution

Open up you info.plist file and add the following key:

<key>UIUserInterfaceStyle</key> 
<string>Light</string>

Android Solution

Put this code into your MainAcitivity.cs

AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;
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: Use converters with binding objects which can have null as value.

You have a converter, which should return a specific value, even if the binded object is null.

Converters does not get executed, when the binded value is null. But here is a solution, how to handle this situations.

Define an example converter

In this case we will use an Int value to bool value converter.

    public class IsIntGreaterThanConverter : IValueConverter, IMarkupExtension
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is int bindedValue && parameter is int targetValue)
            {
                return bindedValue > targetValue;
            }
            else
                return false;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        public object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }
    }

This code returns true, if the binded value is greater than the value provided as a converter parameter.

It can be used with the following code snippet in XAML:

            <Label Text="The value is greater than 0">
                <Label.IsVisible>
                    <Binding Path="Object.IntValue"
                             Converter="{app1:IsIntGreaterThanConverter}">
                        <Binding.ConverterParameter>
                            <x:Int32>0</x:Int32> 
                        </Binding.ConverterParameter>
                    </Binding>
                </Label.IsVisible>
            </Label>

But what happends, when the ‘Object’ is null? Well the converter does not get executed. And since View’s default value of the IsVisible bindable property is true, then the label will be visible, even if the Object is null.

How to handle null scenarios?

Bindings have a property called FallbackValue. Give a value to the fallbackvalue property in order to override the default value, like this:

           <Label Text="The value is greater than 0">
                <Label.IsVisible>
                    <Binding Path="Object.IntValue"

                             FallbackValue="False"

                             Converter="{app1:IsIntGreaterThanConverter}">
                        <Binding.ConverterParameter>
                            <x:Int32>0</x:Int32> 
                        </Binding.ConverterParameter>
                    </Binding>
                </Label.IsVisible>
            </Label>

This should return false even if the binded obejct is null. 🙂

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.