Home > database >  Preserving ICommand during Linking
Preserving ICommand during Linking

Time:03-23

In my Xamarin.Forms code I use ICommand several times for creating hyperlinks.

The code works fine during debugging, but the command gets removed during release by the linker.

I created an XML file in the root of my Android project with its Build Action set to LinkDescription, that has the following code:

<?xml version="1.0" encoding="utf-8" ?>
<linker>
    <assembly fullname="System">
        <type fullname="System.Windows.Input.ICommand"></type>
    </assembly>
</linker>

I expected that would preserve the command, but no; the links again don't work during release. Am I doing something wrong?

CodePudding user response:

I don't know why the XML solution did not work, but here is what worked in my case:

Using the [Preserve] attribute before each ICommand had the desired effect during Release!

CodePudding user response:

You've got the wrong assembly. The easiest way to figure out the right assembly is to CTRL Click the symbol ICommand in a Xamarin project, which will open a decompiler window with the assembly in a #region at the top of the file.

#region Assembly netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
// C:\Program Files\dotnet\sdk\NuGetFallbackFolder\netstandard.library\2.0.3\build\netstandard2.0\ref\netstandard.dll
#endregion

Now change the XML to:

<?xml version="1.0" encoding="utf-8" ?>
<linker>
    <assembly fullname="netstandard">
        <type fullname="System.Windows.Input.ICommand" />
    </assembly>
</linker>
  • Related