Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.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 this issue Sep 16, 2022 · 43 comments
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) linker issues with objects being trimmed inappropriately (sub: perf) platform/iOS 🍎 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@vsfeedback
Copy link

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
Copy link

cyourch commented Sep 21, 2022

I'm having the same issue!

@cyourch
Copy link

cyourch commented Sep 21, 2022

Here's the assignment

Source="Resources/Styles/Colors.xaml"

@bodyasakalo
Copy link

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

@hbraasch
Copy link

hbraasch commented Oct 5, 2022

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
Copy link

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

@hbraasch
Copy link

hbraasch commented Oct 6, 2022

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
Copy link

hbraasch commented Oct 6, 2022

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

@TamerIrdais
Copy link

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

@mattleibow
Copy link
Member

@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
Copy link
Member

mattleibow commented Oct 7, 2022

@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
Copy link

ghost commented Oct 7, 2022

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
Copy link

@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
Copy link
Member

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
Copy link
Member

@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
Copy link
Member

@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
Copy link

TamerIrdais commented Oct 10, 2022

@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
Copy link
Member

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
Copy link

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
Copy link
Member

@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
Copy link

@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
Copy link

@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
Copy link
Member

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
Copy link

ghost commented Nov 3, 2022

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
Copy link

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
Copy link

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

@ajay-mundi
Copy link

ajay-mundi commented Dec 8, 2022

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
Copy link

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

@TamerIrdais
Copy link

@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
Copy link

degenet commented Dec 26, 2022

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

@FBonini22
Copy link

Still experiencing the issue in NET 7.0

@PureWeen
Copy link
Member

Related #12316

@eli191
Copy link

eli191 commented Mar 3, 2023

Related #12316

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

@TamerIrdais
Copy link

@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
Copy link

Same issue on my projects

@nishanthvasu
Copy link

Same Issue for me as well Guys

@lunjio
Copy link

lunjio commented Apr 25, 2023

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
Copy link

How is this still an issue? jeez

@jinxinjuan
Copy link

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

@Bindslev
Copy link

Bindslev commented Aug 4, 2023

Still an issue for me too. Please prioritize

@samhouts samhouts transferred this issue from dotnet/maui Aug 17, 2023
@samhouts samhouts transferred this issue from dotnet/linker Aug 18, 2023
@samhouts samhouts added platform/iOS 🍎 linker issues with objects being trimmed inappropriately (sub: perf) labels Aug 18, 2023
@samhouts samhouts added this to the .NET 8 GA milestone Aug 18, 2023
@jonathanpeppers
Copy link
Member

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.

@jonathanpeppers jonathanpeppers modified the milestones: .NET 8 GA, Backlog Sep 6, 2023
@ghost
Copy link

ghost commented Sep 6, 2023

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.

@Eilon Eilon added the area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) label Nov 9, 2023
@samhouts samhouts added the t/bug Something isn't working label Feb 5, 2024
@jaosnz-rep
Copy link

jaosnz-rep commented Feb 21, 2024

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

@jaosnz-rep jaosnz-rep added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Feb 21, 2024
@svn2208
Copy link

svn2208 commented Jun 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) linker issues with objects being trimmed inappropriately (sub: perf) platform/iOS 🍎 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests