Xamarin.forms: [Bug] Xamarin.Forms Android application crash on release

Created on 2 May 2019  路  4Comments  路  Source: xamarin/Xamarin.Forms

Description

Android application crashes on release while using a String value inside a ResourceDictionary.xaml file. The same does not happen when testing in Debug (with the String resources) or when testing in Release without the String resources.

Steps to Reproduce

  1. Create a Strings.xaml file, without any bundled .cs file.
  2. Add these lines of code:
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                    xmlns:s="clr-namespace:System;assembly=netstandard">

    <s:String x:Key="S.SignUp">Sign Up</s:String>
    <s:String x:Key="S.SignIn">Sign In</s:String>
</ResourceDictionary>
  1. Add the reference of the ResourceDictionary to the App.xaml file:

<ResourceDictionary Source="Resources/Strings.xaml"/>

  1. Switch to Release mode and start the project.

Expected Behavior

Application should not crash with the String resources.

Actual Behavior

Application crash on splashscreen on release mode with this error message, captured by DeviceMonitor:

android.runtime.JavaProxyThrowable: 
Xamarin.Forms.Xaml.XamlParseException: Position 10:6. Type s:String not found in xmlns clr-namespace:System;assembly=netstandard
at Xamarin.Forms.Xaml.CreateValuesVisitor.Visit (Xamarin.Forms.Xaml.ElementNode node, Xamarin.Forms.Xaml.INode parentNode)
at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode)
at Xamarin.Forms.Xaml.RootNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode)
at Xamarin.Forms.Xaml.XamlLoader.Visit (Xamarin.Forms.Xaml.RootNode rootnode, Xamarin.Forms.Xaml.HydrationContext visitorContext, System.Boolean useDesignProperties)
at Xamarin.Forms.Xaml.XamlLoader.Load (System.Object view, System.String xaml, System.Boolean useDesignProperties)
at Xamarin.Forms.Xaml.XamlLoader.Load (System.Object view, System.String xaml)
at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[TXaml] (TXaml view, System.String xaml)
at Xamarin.Forms.Xaml.ResourcesLoader.CreateFromResource[T] (System.String resourcePath, System.Reflection.Assembly assembly, System.Xml.IXmlLineInfo lineInfo)
at Xamarin.Forms.ResourceDictionary.SetAndLoadSource (System.Uri value, System.String resourcePath, System.Reflection.Assembly assembly, System.Xml.IXmlLineInfo lineInfo)
at ... App initialization code, Activity initialization code.

What I've tried

I tried to add a xml file with the build action called "LinkDescription" the same way as I did with the crash on release caused by EntityFramework, with no luck.

Like this:

<?xml version="1.0" encoding="UTF-8" ?>
<linker>
    <assembly fullname="mscorlib">
        <type fullname="System.DateTime" preserve="methods"/>
        <type fullname="System.String" preserve="methods"/>
    </assembly>
</linker>

And like this:

<?xml version="1.0" encoding="UTF-8" ?>
<linker>
    <assembly fullname="mscorlib">
        <type fullname="System.DateTime" preserve="methods"/>
    </assembly>
    <assembly fullname="netstandard">
        <type fullname="System.String" preserve="methods"/>
    </assembly>
</linker>

Basic Information

  • Version with issue: 3.6.0.264807
  • Last known good version: (?)
  • IDE: Visual Studio 2019 v16.0.3
  • Platform Target Frameworks: Android

    • iOS: n/a

    • Android: 9.0

    • UWP: n/a

  • Android Support Library Version: 28.0.0.1
  • Nuget Packages:

    • DLToolkit.Forms.Controls.FlowLis... (2.0.110) MyApp.Android

    • DLToolkit.Forms.Controls.ImageCr... (1.0.7) MyApp.Android

    • DLToolkit.Forms.Controls.TagEntr... (1.0.5) MyApp.Android

    • Forms.Controls.FlexButton (0.9.1) MyApp.Android

    • Rg.Plugins.Popup (1.1.5.188) MyApp.Android

    • Xam.Plugin.Media (4.0.1.5) MyApp.Android

    • Xamarin.FFImageLoading (2.4.6.929) MyApp.Android

    • Xamarin.FFImageLoading.Forms (2.4.6.929) MyApp.Android

    • Xamarin.FFImageLoading.Transform... (2.4.6.929) MyApp.Android

    • Xamarin.Forms (3.6.0.264807) MyApp.Android

    • Xamarin.Android.Support.Design (28.0.0.1) MyApp.Android

    • Xamarin.Android.Support.v7.AppCo... (28.0.0.1) MyApp.Android

    • Xamarin.Android.Support.v4 (28.0.0.1) MyApp.Android

    • Xamarin.Android.Support.v7.CardView (28.0.0.1) MyApp.Android

    • Xamarin.Android.Support.v7.Media... (28.0.0.1) MyApp.Android

    • Newtonsoft.Json (12.0.2) MyApp.Android

    • Xamarin.Android.Support.Core.Utils (28.0.0.1) MyApp.Android

    • Xamarin.Android.Support.CustomTabs (28.0.0.1) MyApp.Android

    • Xamarin.Essentials (1.1.0) MyApp.Android

    • Rg.Plugins.Popup (1.1.5.188) MyApp

    • Microsoft.EntityFrameworkCore (2.2.4) MyApp

    • Polly (7.1.0) MyApp

    • Microsoft.EntityFrameworkCore.Sq... (2.2.4) MyApp

    • Xamarin.FFImageLoading (2.4.6.929) MyApp

    • NodaTime (2.4.5) MyApp

    • Microsoft.EntityFrameworkCore.De... (2.2.4) MyApp

    • Newtonsoft.Json (12.0.2) MyApp

    • Xamarin.FFImageLoading.Forms (2.4.6.929) MyApp

    • Xamarin.FFImageLoading.Transform... (2.4.6.929) MyApp

    • DLToolkit.Forms.Controls.FlowLis... (2.0.11) MyApp

    • Forms.Controls.FlexButton (0.9.1) MyApp

    • Microsoft.Data.Sqlite.Core (2.2.4) MyApp

    • DLToolkit.Forms.Controls.TagEntr... (1.0.5) MyApp

    • Xam.Plugin.Media (4.0.1.5) MyApp

    • Xamarin.Essentials (1.1.0) MyApp

    • NETStandard.Library (2.0.3) MyApp

    • Refit (4.6.107) MyApp

    • Xamarin.Forms (3.6.0.264807) MyApp

    • DLToolkit.Forms.Controls.ImageCr... (1.0.7) MyApp

  • Affected Devices: I only tested on my Nokia 6.1 Plus
3 Android unverified bug

All 4 comments

Same issue as this forum thread.

Use <x:String> instead.

@jcmanke That's right, it's working now after using <x:String>.
I only used String from NetStandard because that's what was suggested by VS/Resharper.

Should I close this issue ticket?

Thanks everyone! :)

Was this page helpful?
0 / 5 - 0 ratings