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.

[iOS] Attempting to JIT compile method InitializeComponent while running in aot-only mode.

See original GitHub issue

Description

Hi,

I keep getting this exception and crash when I run the app in a physical device in Release mode (I turned on debug in release to catch this exception that only happens in Release).

Attempting to JIT compile method 'void OpenStockApp.Pages.Alerts.NotificationsPageIos:InitializeComponent ()' while running in aot-only mode.

I only get it when I use a CollectionView inside a ContentPage created by Shell.

I am trying to make a smaller reproduction repo from my main project where I found this issue: https://github.com/StockDrops/OpenStockApp/blob/rc3-ios-publish/OpenStockApp/Pages/MobileShell.xaml

I have my mobile shell pointing to a page which is defined here:

https://github.com/StockDrops/OpenStockApp/blob/rc3-ios-publish/OpenStockApp/Pages/Notifications/NotificationsPageIos.xaml

And when I leave the collectionview in it, and I run it on device in release mode I get the above error.

If I comment it out, I can run it fine, until I navigate to another page with a collectionview in it, and it crashes again with the same exception.

This is the stack trace of the error: image

The exception:

image

This is the page that gets loaded by the Shell on startup:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:vm="clr-namespace:OpenStockApp.ViewModels"
             xmlns:notifications="clr-namespace:OpenStockApp.ViewModels.Notifications"
             xmlns:viewcore="clr-namespace:OpenStockApp.Core.Maui.Views;assembly=OpenStockApp.Core.Maui"
             xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             xmlns:mct2="clr-namespace:CommunityToolkit.Maui;assembly=CommunityToolkit.Maui"
             xmlns:modelsapi="clr-namespace:OpenStockApi.Core.Models.Searches;assembly=OpenStockApi.Core"
             xmlns:views="clr-namespace:OpenStockApp.Views"
             xmlns:main="clr-namespace:OpenStockApp"
             x:DataType="notifications:NotificationsPageViewModel"
             x:Class="OpenStockApp.Pages.Alerts.NotificationsPageIos"
             x:Name="page"
             Title="Notifications Hub"
             >
    <ContentPage.Resources>
        <ResourceDictionary>
            <mct:IsStringNotNullOrEmptyConverter x:Key="IsNotNullOrEmptyConverter"/>
            <mct:BoolToObjectConverter x:Key="BoolToZIndexConverter" TrueObject="1" FalseObject="100" />
            <mct:BoolToObjectConverter x:Key="BoolToObjectConverter" TrueObject="Busy... Please wait..." FalseObject="Refresh List From Server" />
            <mct:InvertedBoolConverter x:Key="InvertedBoolConverter" />
        </ResourceDictionary>
    </ContentPage.Resources>
    <!--<ContentPage.Behaviors>
        <mct:EventToCommandBehavior EventName="NavigatedTo"
                                    Command="{Binding LoadPreviousResults}"/>
    RemainingItemsThreshold="4"
                                RemainingItemsThresholdReachedCommand="{Binding LoadMoreCommand}"
    </ContentPage.Behaviors>-->
    <Grid Margin="0">
        
        <CollectionView ItemsSource="{Binding Results}"
                    ItemsUpdatingScrollMode="{OnPlatform Default='KeepItemsInView', iOS='KeepItemsInView'}"
                    SelectionMode="None"
                    Margin="5,5,5,10"
                    ZIndex="50"
                    x:Name="collectionView">
        <CollectionView.Header>
                <Grid HeightRequest="195"
                  Margin="0,0,10,0">
                    <StackLayout IsVisible="{Binding IsLoggedIn}"
                                 HorizontalOptions="CenterAndExpand">
                    <main:ConnectionIndicatorView IsConnected="{Binding IsConnected}"
                                                      ConnectCommand="{Binding ConnectCommand}"
                                                      HorizontalOptions="Center"/>
                    <Button Grid.Row="0"
                            Grid.Column="1"
                            VerticalOptions="Start"
                            HorizontalOptions="Center"
                            Text="Send Test Notification" 
                            FontAutoScalingEnabled="True"
                            LineBreakMode="WordWrap"
                            Command="{Binding TestNotificationCommand}"
                            IsVisible="{Binding IsLoggedIn}"
                            Margin="0,5,0,5"/>
                    <Frame CornerRadius="5"
                           HeightRequest="110"                     
                           Margin="{OnPlatform Default=4, iOS=15}"                           
                           BackgroundColor="{AppThemeBinding Dark={StaticResource SecondaryColor}, Light={StaticResource BackgroundColor}}"
                           IsVisible="{Binding IsLoggedIn}">
                        <StackLayout Grid.Row="1" Orientation="Horizontal">
                            <StackLayout Orientation="Vertical">
                                <Label Text="Enable alert settings" 
                                           VerticalOptions="Center"
                                           Margin="{OnPlatform Default='10,0,10,0', Android='0,0,0,0', iOS='0,0,0,10'} "/>
                                <Switch IsToggled="{Binding HasToApplyFilterSettings}"
                                                VerticalOptions="Center"
                                                HorizontalOptions="Center">
                                    <Switch.Behaviors>
                                        <mct:EventToCommandBehavior EventName="Toggled"
                                                                    Command="{Binding ApplyFilterSettings}"/>
                                    </Switch.Behaviors>
                                </Switch>
                                <views:SocialButtons VerticalOptions="Center" Margin="10,0,10,0" IsVisible="{OnPlatform Default='False', Android='True'}"  />
                                <views:SocialButtons VerticalOptions="Center" Margin="10,0,10,0" IsVisible="{OnPlatform Default='True', Android='False'}"  />
                            </StackLayout>
                            <StackLayout>
                                <views:SocialButtons VerticalOptions="Center" Margin="5,0,20,0" IsVisible="{OnPlatform Default='False', Android='True', iOS='True'}"  />
                            </StackLayout>
                        </StackLayout>
                    </Frame>
                </StackLayout>

            </Grid>
        </CollectionView.Header>
        <CollectionView.ItemsLayout>
            <GridItemsLayout Orientation="Vertical"
                                     Span="{OnPlatform Android=1, iOS=1, Default=1}"
                                     VerticalItemSpacing="10"
                                     />
        </CollectionView.ItemsLayout>
        <CollectionView.ItemTemplate>
            <DataTemplate x:DataType="modelsapi:Result">

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="100"/>
                        <RowDefinition Height="160"/>
                        <RowDefinition Height="100"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="3*"/>
                        <ColumnDefinition Width="1*" />
                    </Grid.ColumnDefinitions>
                    <StackLayout Grid.Column="0" Grid.Row="0" Margin="25">
                        <Label Text="{Binding Sku.Model.Name}" 
                                           MaximumWidthRequest="80"
                                   Style="{StaticResource ListTitleStyle}" 
                                       VerticalOptions="Center"
                                   LineBreakMode="WordWrap"
                                   TextTransform="Uppercase"/>
                        <Label Text="{Binding Sku.Retailer.Name}" Margin="0,4,0,4" />
                        <Label Text="{Binding Price}" />
                        <Label Text="{Binding DateTimeFound, StringFormat='{0:g}'}"/>

                    </StackLayout>
                    <StackLayout Grid.Column="1" Grid.Row="0"  Margin="{OnPlatform Default='10', UWP=25}">

                        <Image Source="{Binding ThumbnailUrl}" 
                                           HeightRequest="{OnPlatform Default=80, Android=50, iOS=50}"
                                           Aspect="AspectFit"  IsVisible="{Binding ThumbnailUrl, Converter={StaticResource IsNotNullOrEmptyConverter}}" Margin="0"  />
                        <Label Text="{Binding Id, StringFormat='Id: {0}'}"
                                       VerticalOptions="Start"
                                           Margin="{OnPlatform Default='0,1,0,1', UWP='0,10,0,10', iOS='0,1,0,1'}"/>

                    </StackLayout>
                    <StackLayout Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="20">
                        <Image Source="{Binding ImageUrl}"
                               IsVisible="{OnPlatform iOS={Binding ImageLicensed}, Default='True', MacCatalyst={Binding ImageLicensed}}"
                               HeightRequest="120"
                                Aspect="AspectFit" Margin="0,10,0,10">
                            <Image.Clip>
                                    <RoundRectangleGeometry CornerRadius="10" Rect="10,10,120,120" />
                            </Image.Clip>
                        </Image>

                    </StackLayout>
                    <StackLayout Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="20">

                        <views:HyperlinkButton Text="Product Url" Url="{Binding ProductUrl}" Margin="2" />
                        <views:HyperlinkButton Url="{Binding AtcUrl}" Text="Add To Cart Url" IsVisible="{Binding AtcUrl, Converter={StaticResource IsNotNullOrEmptyConverter}}" Margin="2"/>
                    </StackLayout>
                </Grid>

            </DataTemplate>
        </CollectionView.ItemTemplate>
        <CollectionView.Footer>
            <Grid IsVisible="{Binding IsLoggedIn}">
                <Button Margin="0,2,0,2"
                            ZIndex="50"
                            Text="Load More?"
                            MinimumWidthRequest="{OnPlatform Android=100, iOS=100, UWP=300}"
                            HorizontalOptions="Center"
                            FontSize="Medium"
                            FontAttributes="Bold"
                            IsVisible="{Binding EndReached, Converter={StaticResource InvertedBoolConverter}}"
                            Command="{Binding LoadMoreCommand}"/>
                <Button Margin="0,2,0,2"
                            MinimumWidthRequest="{OnPlatform Android=100, iOS=100, UWP=300}"
                            HorizontalOptions="Center"
                            FontSize="Medium"
                            FontAttributes="Bold"
                            IsEnabled="False"
                            Text="End Reached"
                            IsVisible="{Binding EndReached}"/>
            </Grid>
        </CollectionView.Footer>
    </CollectionView>
        <!--<views:LogInView IsLoggedIn="{Binding IsLoggedIn}"
                            LogInCommand="{Binding LogIn}"
                            Grid.Row="0"
                            ZIndex="{Binding IsLoggedIn, Converter={StaticResource BoolToZIndexConverter}}"/>-->
    </Grid>
</ContentPage>

I haven’t been able to know exactly what in the XAML causes the InitializeMethod to try to JIT compile something.

Steps to Reproduce

  1. Not sure yet.

Version with bug

Release Candidate 3 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

ios 15

Did you find any workaround?

None yet

Relevant log output

**System.ExecutionEngineException:** 'Loading...'

Thread finished: <Thread Pool> #8
Thread finished: <Thread Pool> #6
The thread 0x8 has exited with code 0 (0x0).
The thread 0x6 has exited with code 0 (0x0).
Thread started: <Thread Pool> #9

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
svaldeterocommented, Aug 19, 2022

I have been getting this error message in numerous spots in my MAUI app in Release on iPhone. Mine all seem to be related to using LINQ. The most infuriating thing is it doesn’t happen when debugging on a device which should be AOT’d also. I only discover it when pushing out a build to users and it crashes.

  1. Is there a way to debug and and trigger this issue to I can catch it sooner?
  2. Why is LINQ having so much trouble in AOT?
0reactions
yunusefendi52commented, Oct 23, 2022

@StephaneDelcroix setting MauiXamlCValidateOnly not working for me, log:

Set Property: _MauiXamlCValidateOnly=False
Set Property: _MauiXamlCValidateOnly=True

other logs

ValidateOnly=True. Skipping writing assembly.

But looking at the source, it’s working when settings it to -p:MauiXamlCValidateOnly=False -p:_MauiForceXamlCForDebug=True

Set Property: _MauiXamlCValidateOnly=False
Read more comments on GitHub >

github_iconTop Results From Across the Web

Xamarin "Attempting to JIT compile method error"
Attempting to JIT compile method 'MyApplication.App:InitializeComponent ()' while running in aot-only mode. See https://developer.xamarin.com/ ...
Read more >
Error: Attempting to JIT compile method
I'm running a piece of code that opens a db, then fires up the sync engine. On the iOS simulator it works, on...
Read more >
Attempting to JIT compile method error
Attempting to JIT compile method 'MyApplication.App:InitializeComponent ()' while running in aot-only mode. See https://developer.xamarin.com/guides/ios/ ...
Read more >
Got a abrt while executing native code- Xamarin Forms/iOS
Hi! I´m working with VS 2019 16.6.2, but when i deploy to my iphone sometimes i got the next exception (after app crash)...
Read more >
MAUI EF Core 6 crash on IOS - Microsoft Q&A
Getting immediate crash during saving data into sqlite. using following ... ExecutionEngineException: Attempting to JIT compile method ...
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