dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.17k stars 1.74k forks source link

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

Open vsfeedback opened 2 years ago

vsfeedback commented 2 years ago

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)

cyourch commented 2 years ago

I'm having the same issue!

cyourch commented 2 years ago

Here's the assignment

Source="Resources/Styles/Colors.xaml"

bodyasakalo commented 2 years ago

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

hbraasch commented 2 years ago

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!!!!

bodyasakalo commented 2 years ago

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

hbraasch commented 2 years ago

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 commented 2 years ago

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

TamerIrdais commented 2 years ago

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

mattleibow commented 2 years ago

@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 commented 2 years ago

@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

ghost commented 2 years ago

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.

TamerIrdais commented 2 years ago

@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?

mattleibow commented 2 years ago

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 commented 2 years ago

@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?

rolfbjarne commented 2 years ago

@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.

TamerIrdais commented 2 years ago

@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
}
jonathanpeppers commented 2 years ago

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

TamerIrdais commented 2 years ago

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.

jonathanpeppers commented 2 years ago

@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.

TamerIrdais commented 2 years ago

@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 commented 2 years ago

@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.

jonathanpeppers commented 2 years ago

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:

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.

ghost commented 1 year ago

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.

TamerIrdais commented 1 year ago

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 commented 1 year ago

Any update on this issue? I need this fixed ASAP please.

ajay-mundi commented 1 year ago

Still getting this issue in IOS on .NET 7.

Tried setting linker settings to "Don't link" then cleaned and rebuilt project. Still getting the same error and a notification for Visual Studio for mac to set my linker settings to "Don't link" though I believe I have already done that.

Using visual studio for mac 17.5 preview build 437

ajay-mundi commented 1 year ago

@TamerIrdais did you end up finding a workaround for this?

TamerIrdais commented 1 year ago

@ajay-mundi no I got no where with it and as you can see no one from Microsoft side is even saying we will investigate it or when it will be fixed. We need to up vote this ticket guys maybe they will give it some priority, its been months now and I cant run my apps on iOS or Mac for MAUI because of this issue, this is just frustrating.

degenet commented 1 year ago

I can confirm we are experiencing the same issue on Net7.

FBonini22 commented 1 year ago

Still experiencing the issue in NET 7.0

PureWeen commented 1 year ago

Related https://github.com/dotnet/maui/issues/12316

eli191 commented 1 year ago

Related dotnet/maui#12316

@PureWeen
Sorry, my issue dotnet/maui#12316 is not the same as the linker set to None also makes the app crash in Release.

TamerIrdais commented 1 year ago

@PureWeen I have reported this bug over 6 months ago and still got no fix, can you please when is this going to be fixed?

tiago-carneiro commented 1 year ago

Same issue on my projects

nishanthvasu commented 1 year ago

Same Issue for me as well Guys

lunjio commented 1 year ago

The same issue is here. I use "Link Framework SDKs Only" during release process, and have a problem with a properties that uses binding. Microsoft.Maui.Controls text is displayed instead of source value. .Net 7.0.

gustinsam2 commented 1 year ago

How is this still an issue? jeez

jinxinjuan commented 1 year ago

Verified this issue with Visual Studio Enterprise 17.7.0 Preview 2.0. Can repro on iOS platform with .NET MAUI template project.

Bindslev commented 1 year ago

Still an issue for me too. Please prioritize

jonathanpeppers commented 1 year ago

We've discussing with the .NET team that owns the trimmer, and it does not appear this is feasible in the .NET 8 timeframe.

We have other issues filed to try to solve all trimmer warnings on the Android side, for example:

^^ So, we'd ideally have completed this one first before looking at .NET MAUI.

Moving this to the backlog for now, but it may become more important in the future as we try to support other runtimes like NativeAOT.

For now, I would not recommend using LinkAll unless you are willing to wade through trimming warnings and preserve C# types and members yourself. This feels like a very advanced scenario, and you will need to really know what you are doing.

ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

jaosnz-rep commented 8 months ago

Verified this issue on .NET 8 iOS platform with Visual Studio Enterprise 17.10.0 Preview 1, set iOS linker behavior to "LinkAll", an exception is thrown after debugging, and the exception information is updated as follows: System.TypeLoadException: 'VTable setup of type Microsoft.Maui.Controls.Editor failed' image

svn2208 commented 4 months ago

I face the same issue. I tried downgrade of -net8 till .100; downgrade maui down to 8.0.8. I have no idea how to get rid of this :( It didnt run in VS Code and VS both on OSX. 1 2 3