question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

XamlParseException when using an Int32 value for a RadioButton

See original GitHub issue

Description

I’m trying to bind some RadioButton views using System.Int32 values and separate display labels. I’m using <RadioButton.Value> in the XAML with the appropriate values.

On Android and Windows, this works fine. On iOS, it crashes with a XamlParseException.

Steps to Reproduce

  1. Create a new MAUI app
  2. Edit MainPage.xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             x:Class="ReproInt32Combo.MainPage">

    <ScrollView>
        <VerticalStackLayout>
            <RadioButton Content="First">
                <RadioButton.Value>
                    <sys:Int32>1</sys:Int32>
                </RadioButton.Value>
            </RadioButton>
            <RadioButton Content="Second">
                <RadioButton.Value>
                    <sys:Int32>2</sys:Int32>
                </RadioButton.Value>
            </RadioButton>
        </VerticalStackLayout>
    </ScrollView>

</ContentPage>
  1. Delete the C# code in MainPage.xaml.cs (except for the constructor)
  2. Run on Windows or Android - no issues
  3. Run on iOS and observe the exception below
  4. Try x:Int32 instead of sys:Int32 and observe the same behavior

Exception:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> Microsoft.Maui.Controls.Xaml.XamlParseException: Position 11:22. Type sys:Int32 not found in xmlns clr-namespace:System;assembly=mscorlib
   at Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.Visit(ElementNode node, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Visit(RootNode rootnode, HydrationContext visitorContext, Boolean useDesignProperties)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Assembly rootAssembly, Boolean useDesignProperties)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Boolean useDesignProperties)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, Type callingType)
   at Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml[MainPage](MainPage view, Type callingType)
   at ReproInt32Combo.MainPage.InitializeComponent() in C:\Users\jon\Issues\AtYourService\MauiIpad\ReproInt32Combo\Microsoft.Maui.Controls.SourceGen\Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator\MainPage.xaml.sg.cs:line 22
   at ReproInt32Combo.MainPage..ctor() in C:\Users\jon\Issues\AtYourService\MauiIpad\ReproInt32Combo\MainPage.xaml.cs:line 7
   at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object , Object[] , Boolean )
   --- End of inner exception stack trace ---
   at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object , Object[] , Boolean )
   at System.RuntimeType.CreateInstanceMono(Boolean , Boolean )
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean , Boolean )
   at System.Activator.CreateInstance(Type , Boolean , Boolean )
   at System.Activator.CreateInstance(Type , Boolean )
   at System.Activator.CreateInstance(Type )
   at Microsoft.Maui.Controls.ShellContent.<>c__DisplayClass19_0.<Microsoft.Maui.Controls.IShellContentController.GetOrCreateContent>b__0()
   at Microsoft.Maui.Controls.ElementTemplate.CreateContent()
   at Microsoft.Maui.Controls.Internals.DataTemplateExtensions.CreateContent(DataTemplate self, Object item, BindableObject container)
   at Microsoft.Maui.Controls.ShellContent.Microsoft.Maui.Controls.IShellContentController.GetOrCreateContent()
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.LoadRenderers()
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.ViewDidLoad()
   at UIKit.UIApplication.Main(String[] , Type , Type )
   at ReproInt32Combo.Program.Main(String[] args) in [...]

With x:Int32, the exception contains ---> Microsoft.Maui.Controls.Xaml.XamlParseException: Position 11:22. Type x:Int32 not found in xmlns http://schemas.microsoft.com/winfx/2009/xaml instead.

I’ve tried with the linker disabled, but the debugger didn’t even start then. (That could be an environmental issue.) I wouldn’t expect System.Int32 to be stripped anyway though… it’s a pretty fundamental type!

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 15.6

Did you find any workaround?

No.

Relevant log output

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jskeetcommented, Oct 19, 2022

@StephaneDelcroix: I’m afraid I can’t easily check at the moment. But I suspect given my earlier comment of “Bizarrely, I’ve just run this not in the debugger, and in Release mode, and it doesn’t crash” that it was then working in the simulator. Basically I think it’s “debug=boom, release=fine” regardless of simulator vs device.

1reaction
Greg-Bates-Trimblecommented, Aug 24, 2022

We have the same issue, but with a custom control. Means that our iOS app is unrunnable. If this could be top priority to fix please.

The outputted log: 2022-08-25 10:56:27.406805+1200 TMM[49043:1756968] Unhandled managed exception: Position 9:8. Type pages:InvertBooleanConverter not found in xmlns clr-namespace:<ProjectName>.Pages (Microsoft.Maui.Controls.Xaml.XamlParseException) at Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.Visit(ElementNode , INode ) at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor , INode ) at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor , INode ) at Microsoft.Maui.Controls.Xaml.RootNode.Accept(IXamlNodeVisitor , INode ) at Microsoft.Maui.Controls.Xaml.XamlLoader.Visit(RootNode , HydrationContext , Boolean ) at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object , String , Assembly , Boolean ) at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object , String , Boolean ) at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object , Type ) at Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml[App](App , Type ) at TMM.App.InitializeComponent() in C:\Users\Documents\developmen t\Microsoft.Maui.Controls.SourceGen\Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator\App.xaml.sg.cs:line 22 at TMM.App..ctor() in C:\Users\Documents\development\App.xaml.cs:line 16 at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object , Object[] , Boolean ) at System.Reflection.RuntimeConstructorInfo.DoInvoke(Object , BindingFlags , Binder , Object[] , CultureInfo ) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags , Binder , Object[] , CultureInfo ) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite , RuntimeResolverContext ) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, Pu blicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite , RuntimeResolverContext ) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite , RuntimeResolverContext ) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite , RuntimeResolverContext ) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite , ServiceProviderEngineScope ) at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type ) at System.Collections.Concurrent.ConcurrentDictionary2[[System.Type, System.Private.CoreLib, Version=6.0.0.0, Culture=n eutral, PublicKeyToken=7cec85d7bea7798e],[System.Func2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope, Microsoft.Extensions.DependencyInjection, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetOrAdd(Type , Func2 ) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type , ServiceProviderEngineScope ) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type ) at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type ) at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type ) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider , Type ) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRe quiredServiceIApplication at Microsoft.Maui.MauiUIApplicationDelegate.FinishedLaunching(UIApplication , NSDictionary ) at UIKit.UIApplication.Main(String[] , Type , Type ) at <ProjectName>.Program.Main(String[] ) in C:\Users\Documents\development\Platforms\iOS\Program.cs:line 13`

Read more comments on GitHub >

github_iconTop Results From Across the Web

Xaml radio button checked with specific int value
1 Answer 1 · On your Viewmodel add a command to update value of your property X · Bind the command to your...
Read more >
RadioButtons.SelectedIndex Property - Windows
Gets or sets the index of the selected radio button. ... Setting SelectedIndex to any value outside the range of the Items collection...
Read more >
RadioButton - .NET MAUI
Each RadioButton object has a Value property, of type object , which defines an optional unique value to associate with the radio button....
Read more >
How to insert Radio Button Values in Database - YouTube
C# Database Programming: How to insert Radio Buttons Values in ... First we will insert a single Radio button value into database using...
Read more >
<input type="radio"> - HTML: HyperText Markup Language
When the above form is submitted with a radio button selected, the form's data includes an entry in the form contact=value . For...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found