maui icon indicating copy to clipboard operation
maui copied to clipboard

.NET MAUI Set iOS Linker Behavior to "LinkAll" throws XamlParseException: 'Position 9:37. Cannot assign property "Source": Property does not exist.

Open vsfeedback opened this issue 2 years ago • 25 comments

This issue has been moved from a ticket on Developer Community.


[severity:I'm unable to use this version] Create new .NET MAUI app and set the iOS Linker Behavior to "LinkAll", build and run to iOS device or simulator and you will get below exception on app start:

Microsoft.Maui.Controls.Xaml.XamlParseException: 'Position 9:37. Cannot assign property "Source": Property does not exist, or is not assignable, or mismatching type between value and property'.

Help is needed ASAP please.


Original Comments

Feedback Bot on 8/28/2022, 07:35 PM:

(private comment, text removed)

Tamer Irdais on 9/2/2022, 00:49 AM:

(private comment, text removed)


Original Solutions

(no solutions)

vsfeedback avatar Sep 16 '22 17:09 vsfeedback

I'm having the same issue!

cyourch avatar Sep 21 '22 01:09 cyourch

Here's the assignment

Source="Resources/Styles/Colors.xaml"

cyourch avatar Sep 21 '22 02:09 cyourch

Same thing happens for me in existing project. Really looking forward for it to be fixed in nearest update

bodyasakalo avatar Sep 22 '22 13:09 bodyasakalo

Same problem here. After latest Preview VS update [17.4.0 Preview 2.1]. I always use "Link Framework SDKs Only" and it has the same problem. Thought it was because I've upgraded my XCode to 14.1, but that is unusable because the simulator list does not get filled in, so I downgraded back to XCode 13.4.1. So the problem remains. Totally unable to debug any iOS apps!!!!

hbraasch avatar Oct 05 '22 00:10 hbraasch

Still having exactly the same problem @hbraasch described App development is stuck for several weeks now cause this issue

bodyasakalo avatar Oct 05 '22 10:10 bodyasakalo

I now got the sample MAUI app to run under Preview VS update [17.4.0 Preview 2.1] and XCode 13.4.1 by selecting .NET7 as the framework!!!

Now to start converting my old apps to .NET7 to see if that works. Seems it's not as simple as changing the [net6.0-] to [net7.0-] in the .csproj file :-(

Any help with that shall be appreciated.

hbraasch avatar Oct 06 '22 00:10 hbraasch

Old "real" app is now also working after upgrading to .NET7.

hbraasch avatar Oct 06 '22 02:10 hbraasch

@hbraasch says this issue is fixed in .NET7 but is this fix going to make it into .NET6 as well?

TamerIrdais avatar Oct 07 '22 09:10 TamerIrdais

@hbraasch can you open a new issue with why this is not working:

Seems it's not as simple as changing the [net6.0-] to [net7.0-] in the .csproj file :-(

It should work 100% as the API is the same and mostly bug fixes and smaller features.

mattleibow avatar Oct 07 '22 14:10 mattleibow

@StephaneDelcroix could it be that the xamlc is not compiling the xaml that contains the source property?

@cyourch @TamerIrdais @bodyasakalo I am wondering if you can test something and trick the linker into keeping some fields/properties. Somewhere in the app - maybe in the MauiProgram.cs:

class MauiProgram {

#pragma warning disable 0219, 0649
    static bool falseflag = false;
    static MauiProgram ()
    {
        if (falseflag) {
            var rd = new ResourceDictionary { Source = "" };
        }
    }
#pragma warning restore 0219, 0649

    // ...
}

@rolfbjarne @jonathanpeppers do we have docks on how to stop linking particular assemblies?

EDIT

I think this is the docs that shows how you can add a xml file to skip linking on the Microsoft.Maui.Countrols.dll:

https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options?pivots=dotnet-6-0#trimming-settings-for-individual-assemblies

mattleibow avatar Oct 07 '22 14:10 mattleibow

Hi @vsfeedback. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

msftbot[bot] avatar Oct 07 '22 14:10 msftbot[bot]

@mattleibow I tried your code but it didn't work, also I don't know what is it supposed to do because falseflag is always false so new ResourceDictionary is never called so what is this code supposed to do?

TamerIrdais avatar Oct 10 '22 06:10 TamerIrdais

Ah yeah, so it doesn't do anything except trick the linker into keeping that property.

However, if adding it did not stop the linker from causing the error, then something else has gone wrong and @StephaneDelcroix will have to share some expert opinions.

mattleibow avatar Oct 10 '22 07:10 mattleibow

@rolfbjarne unless we taught the linker to be even smarter and it detects this magic code as no op and removes it and keeps on linking?

mattleibow avatar Oct 10 '22 07:10 mattleibow

@mattleibow it wouldn't surprise me if the linker had gotten that smart.

this should ensure the linker doesn't remove it:

static bool falseflag = Environment.GetEnvironmentVariable ("inexistent") == "inexistent";

since the linker will not be able to determine that falseflag will always be false.

rolfbjarne avatar Oct 10 '22 13:10 rolfbjarne

@rolfbjarne I don't know what you guys mean, where should I put this line? and it it supposed to fix this bug? because I tried and it didn't, here is my code inside MauiProgram.cs file and I don't understand how these lines are going to keep the resource files Colors.xaml and Styles.xaml inside App.xaml file from getting stripped out:

public static class MauiProgram
{
#pragma warning disable 0219, 0649
   static bool falseflag = Environment.GetEnvironmentVariable("inexistent") == "inexistent";
   public static MauiApp CreateMauiApp()
   {
      if (falseflag)
      {
         var rd = new ResourceDictionary { Source = new Uri("") };
      }

      var builder = MauiApp.CreateBuilder();
      builder
         .UseMauiApp<App>()
         .ConfigureFonts(fonts =>
         {
            fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
            fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
         });

      return builder.Build();
   }
#pragma warning restore 0219, 0649
}

TamerIrdais avatar Oct 10 '22 13:10 TamerIrdais

I wouldn't recommend using LinkAll, unless you're willing to work through missing types.

You will likely need to preserve things as mentioned here:

https://github.com/dotnet/linker/blob/main/docs/data-formats.md

jonathanpeppers avatar Oct 10 '22 14:10 jonathanpeppers

Thank you @jonathanpeppers but this is still a bug and I need a fix for it, there must be a way to stop linker from trimming Source.xml and Colors.xml files from the default template of the MAUI project right? there has to be.

TamerIrdais avatar Oct 11 '22 06:10 TamerIrdais

@TamerIrdais do you have XamlCompilation turned off?

https://learn.microsoft.com/en-us/dotnet/maui/xaml/xamlc

The linker should see your use of any types in Source.xml and Colors.xml, if XamlC is turned on.

Why is this a blocker? Why do you need LinkAll? That information would be helpful, thanks.

jonathanpeppers avatar Oct 13 '22 17:10 jonathanpeppers

@jonathanpeppers No I didn't turn off XamlCompilation and its ON by default.

I needed LinkAll because it used to give compilation errors on my own frameworks when I don't use that flag and the compilation error goes away when I use LinkAll, now on latest VS 2022 17.3.6 that problem seems to be fixed so I can avoid using LinkAll for now but still this is a bug and should be fixed, right?

Its active on the default MAUI project template after you change the linker to LinkAll for iOS with no other changes to the project, can you guys event reproduce it on your side? its a bug and should be fixed because in Xamarin we were able to use LinkAll with no problems.

TamerIrdais avatar Oct 14 '22 06:10 TamerIrdais

@jonathanpeppers Any update on this issue? I need to correct something, my own frameworks still shows errors if the linker is not set to "Link All" so I can't get around this problem or use any other linker flags, this is urgent and I need at least workaround for the original LinkAll problem I reported please.

TamerIrdais avatar Oct 25 '22 12:10 TamerIrdais

WPF does not even work with trimming enabled, it would be a large project to support this for .NET MAUI. Any framework that uses System.Reflection heavily is in the same boat.

If you still want to use LinkAll, you should follow the linker/trimming documentation here:

  • https://learn.microsoft.com/dotnet/core/deploying/trimming/trimming-options
  • https://github.com/dotnet/linker/blob/main/docs/data-formats.md

As you encounter errors like member XYZ was not found on type ABC, you will need to do the work to make sure these types are preserved.

jonathanpeppers avatar Oct 25 '22 13:10 jonathanpeppers

Hi @vsfeedback. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

msftbot[bot] avatar Nov 03 '22 19:11 msftbot[bot]

So the original bug I reported is not getting solved by you guys, am I correct? There are no frameworks involved with the new MAUI app project and when you set it to LinkAll it crashes on app startup, this is a straight forward bug that should be addressed and I didn't see anyone telling me we will investigate it or even this is not going to be fixed for these reasons.... All am asking for is to solve the XamlParseException: 'Position 9:37. Cannot assign property "Source": Property does not exist which is clearly in the Colors.xml or Style.xml file that comes with the default MAUI app template so clearly this is a bug that should be solved.

If you solved that issue I can handle my problem with my frameworks but I can't even test my app using "LinlAll" now.

TamerIrdais avatar Nov 04 '22 07:11 TamerIrdais