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

Type binding Error with .NET 9 Preview 6 #23551

Open
davidortinau opened this issue Jul 10, 2024 · 5 comments
Open

Type binding Error with .NET 9 Preview 6 #23551

davidortinau opened this issue Jul 10, 2024 · 5 comments
Assignees
Labels
area-xaml XAML, CSS, Triggers, Behaviors i/regression This issue described a confirmed regression on a currently supported version platform/android 🤖 platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@davidortinau
Copy link
Contributor

Description

Testing .NET Hot Reload and .NET 9 Preview 6 I'm getting these errors:

Exception has occurred: CLR/System.TypeLoadException
An unhandled exception of type 'System.TypeLoadException' occurred in Mono.Android.Runtime.dll: 'Could not resolve type with token 01000075 from typeref (expected class 'Microsoft.Maui.Controls.Generated.<GeneratedBindableObjectExtensions_g>F340249EF3F4705EB00F29166AE5B0DC4FEF24016399EDCA95F8D25AC35F9B242__GeneratedBindableObjectExtensions' in assembly '')'
   at Android.Runtime.RuntimeNativeMethods.monodroid_debugger_unhandled_exception(Exception e)
   at Android.Runtime.JNINativeWrapper._unhandled_exception(Exception e)
   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz)
   at SharpNine.FirstPage.Build() in /Users/davidortinau/work/SharpNine/FirstPage.cs:line 41
   at SharpNine.FirstPage.<.ctor>b__2_1()
   at Java.Lang.Thread.RunnableImplementor.Run()
   at Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this)
   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz)
Exception has occurred: CLR/System.TypeLoadException
An unhandled exception of type 'System.TypeLoadException' occurred in Microsoft.iOS.dll: 'Could not resolve type with token 01000072 from typeref (expected class 'Microsoft.Maui.Controls.Generated.<GeneratedBindableObjectExtensions_g>F340249EF3F4705EB00F29166AE5B0DC4FEF24016399EDCA95F8D25AC35F9B242__GeneratedBindableObjectExtensions' in assembly '')'
   at ObjCRuntime.Runtime.ThrowException(IntPtr gchandle)
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName)
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)
   at SharpNine.Program.Main(String[] args) in /Users/davidortinau/work/SharpNine/Platforms/iOS/Program.cs:line 14

From changing anything in this method:

void Build()
	{
		Content = new VerticalStackLayout
		{
			Spacing = 20,
			Margin = 20,
			Children = {
				(label = new Label {  
					Text = "Welcome to .NET MAUI!",
					FontSize = 64,
					TextColor = Colors.Blue
				}),
				(entry = new Entry { Placeholder = "Enter your name" }),
			}
		};

		label.SetBinding(Label.TextProperty, static (Entry e) => e.Text, source: entry);
	}

The binding functions as I expect. @simonrozsival I suspect this is related to the compiled bindings work.

Commenting out the binding allows .NET Hot Reload to succeed without error. Returning to a non-compiled binding works as well:

label.SetBinding(Label.TextProperty, new Binding("Text", source: entry));

SharpNine.zip

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

9.0.0-preview.6.24327.7

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, macOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

@davidortinau davidortinau added the t/bug Something isn't working label Jul 10, 2024
Copy link
Contributor

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@simonrozsival
Copy link
Member

/cc @jkurdek

@PureWeen PureWeen added the area-xaml XAML, CSS, Triggers, Behaviors label Jul 10, 2024
@PureWeen PureWeen added this to the 9.0-preview7 milestone Jul 10, 2024
@PureWeen PureWeen added the i/regression This issue described a confirmed regression on a currently supported version label Jul 10, 2024
@Zhanglirong-Winnie Zhanglirong-Winnie added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 11, 2024
@Zhanglirong-Winnie
Copy link

This issue has been verified Visual Studio 17.11.0 Preview 3.0(9.0.0-preview.6.24327.7)& VSM 17.6.12(net9),Can repro on all platforms.

@simonrozsival
Copy link
Member

simonrozsival commented Jul 11, 2024

I wonder if we can do something about this on our end or if this is some limitation of source generators and hot reload. It seems to me that the type name of the source generated class changes with every roslyn compilation:

In one instance, the type name before the update (obtained by listing types in the assembly via reflection) was:

Microsoft.Maui.Controls.Generated.<GeneratedBindableObjectExtensions_g>F8EAA02179AB123506AE8CCA05556D5DDF2EA0B3D7CB088DAB38382B52A1722F6__GeneratedBindableObjectExtensions

And the exception message compained about not being able to find this type:

Microsoft.Maui.Controls.Generated.<GeneratedBindableObjectExtensions_g>F66D27BD33A914CF7D49F79ED8311EF0A6D6053E8F683ECBDAD481FAF1B9ED440__GeneratedBindableObjectExtensions

The UpdateApplicationEvent delegate was called with two types (obj) and none of them was the <GeneratedBindableObjectExtensions_g>XYZ_GeneratedBindableObjectExtensions.

I'm not sure who on the Roslyn team or on the tooling team could help us diagnose this.

@simonrozsival
Copy link
Member

simonrozsival commented Jul 18, 2024

The mangled names were caused by the class being file scoped. We changed it to internal in #23116 so this should be resolved in P7.

@simonrozsival simonrozsival self-assigned this Jul 18, 2024
@PureWeen PureWeen modified the milestones: 9.0-preview7, 9.0-rc1 Jul 29, 2024
@PureWeen PureWeen modified the milestones: 9.0-rc1, 9.0-preview7 Jul 30, 2024
@PureWeen PureWeen reopened this Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-xaml XAML, CSS, Triggers, Behaviors i/regression This issue described a confirmed regression on a currently supported version platform/android 🤖 platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

5 participants