xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.64k stars 1.88k forks source link

Renaming App.xaml causes various weird runtime errors #6156

Open mknotzer opened 5 years ago

mknotzer commented 5 years ago

Description

exceptions like XamlParseException are raised ...

Steps to Reproduce

rename App.xaml and App.cs to MyApp.xaml and MyApp.cs change LoadApplication(new App()); to LoadApplication(new MyApp()); compile it and run it

Basic Information

samhouts commented 5 years ago

@mknotzer Have you tried to clean your solution first? Can you please attach a small project that demonstrates this issue? Thanks!

mknotzer commented 5 years ago

I cleaned and rebuild it. Actually for several years I've been using a second file called ThisApp. When I removed recently the original App.* the runtime errors occurs. Renaming App or even changing to ContentView has no impact, only removing it from the project causes trouble like this:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Xamarin.Forms.Xaml.XamlParseException: Position 46:37. Multiple properties with name 'DemoProject.Controls.Video.WidthRequest' found. ---> System.Reflection.AmbiguousMatchException: Ambiguous match found. at System.RuntimeType.GetPropertyImpl (System.String name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Type returnType, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) [0x00057] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.25/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/rttype.cs:3307 at System.Type.GetProperty (System.String name) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.25/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/type.cs:728 at System.Reflection.RuntimeReflectionExtensions.GetRuntimeProperty (System.Type type, System.String name) [0x00006] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.25/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/reflection/RuntimeReflectionExtensions.cs:48 at Xamarin.Forms.Xaml.ApplyPropertiesVisitor+<>c__DisplayClass36_0.b__1 () [0x00000] in D:\a\1\s\Xamarin.Forms.Xaml\ApplyPropertiesVisitor.cs:503 --- End of inner exception stack trace --- at Xamarin.Forms.Xaml.CreateValuesVisitor.Visit (Xamarin.Forms.Xaml.ElementNode node, Xamarin.Forms.Xaml.INode parentNode) [0x00359] in D:\a\1\s\Xamarin.Forms.Xaml\CreateValuesVisitor.cs:103 at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x000ac] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:149 at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00079] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:145 at Xamarin.Forms.Xaml.RootNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00079] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:202 at Xamarin.Forms.Xaml.XamlLoader.Visit (Xamarin.Forms.Xaml.RootNode rootnode, Xamarin.Forms.Xaml.HydrationContext visitorContext, System.Boolean useDesignProperties) [0x00064] in D:\a\1\s\Xamarin.Forms.Xaml\XamlLoader.cs:147 at Xamarin.Forms.Xaml.XamlLoader.Load (System.Object view, System.String xaml, System.Boolean useDesignProperties) [0x00058] in D:\a\1\s\Xamarin.Forms.Xaml\XamlLoader.cs:91 at Xamarin.Forms.Xaml.XamlLoader.Load (System.Object view, System.Type callingType) [0x00028] in D:\a\1\s\Xamarin.Forms.Xaml\XamlLoader.cs:69 at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[TXaml] (TXaml view, System.Type callingType) [0x00000] in D:\a\1\s\Xamarin.Forms.Xaml\ViewExtensions.cs:36 at DemoProject.Pages.MainPage.InitializeComponent () [0x00001] in /Users/mknotzer/Documents/Projects/Black/SourceCode/Black/obj/Debug/netstandard2.0/Pages/Pages/MainPage.xaml.g.cs:27 at DemoProject.Pages.MainPage..ctor () [0x00008] in /Users/mknotzer/Documents/Projects/Black/SourceCode/Black/Pages/Pages/MainPage.xaml.cs:10 at (wrapper managed-to-native) System.Reflection.MonoCMethod.InternalInvoke(System.Reflection.MonoCMethod,object,object[],System.Exception&) at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.25/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/MonoMethod.cs:698 --- End of inner exception stack trace --- at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00015] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.25/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/MonoMethod.cs:704 2019-05-14 09:04:51.257029+0300 Black.iOS[3912:312040] at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic, System.Boolean wrapExceptions) [0x000a8] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.25/src/Xamarin.iOS/mcs/class/corlib/ReferenceSources/RuntimeType.cs:179 at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean wrapExceptions, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00009] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.25/src/Xamarin.iOS/mcs/class/corlib/ReferenceSources/RuntimeType.cs:153 at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Boolean wrapExceptions, System.Threading.StackCrawlMark& stackMark) [0x00027] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.25/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/rttype.cs:5646 at System.Activator.CreateInstance[T] () [0x00029] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.25/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/activator.cs:236

mknotzer commented 5 years ago

adding [assembly: XamlCompilation(XamlCompilationOptions.Compile)] solved it for me attached a small project, please compile and run

Test.zip

kingces95 commented 5 years ago

Oh, so you solved this issue?

mknotzer commented 5 years ago

The issue still exists, setting XamlCompilation is only a temporary solution. Please run my demo project.

samhouts commented 5 years ago

@mknotzer It does seem like a bug that this is happening without XamlC. However, may I ask why enabling XamlC is a temporary solution? We do recommend it for performance and development productivity. Thanks!

mknotzer commented 5 years ago

enabling XamlC is a (pretty good) work around. The option was not enabled in my project due to a compiler bug some time ago. In general enabling XamlC makes sense. It's up to you guys if you want to investigate this bug or not.