maui
maui copied to clipboard
Getting AccessViolationException while adding custom resource dictionary in App.Xaml file
Description
I have created a Maui library project file to add a custom resource dictionary for theme support. Then, I included it in the application file and added the custom resource dictionary to the merged dictionaries like below. I'm getting AccessViolationException when I run the application in release mode only. And the example deployed successfully with debug mode. I have attached the runnable example with the library project.
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:CustomThemeTesting"
xmlns:theme="clr-namespace:ThemeLibrary;assembly=ThemeLibrary"
x:Class="CustomThemeTesting.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
<theme:CustomThemeResourceDictionary VisualTheme="LightDefault"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Error message:
Steps to Reproduce
- Download and extract the attached example.
- Run the CustomThemeTesting project with release mode. You will get the access violation exception.
Link to public reproduction project repository
No response
Version with bug
8.0.3
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, Windows, macOS
Affected platform versions
No response
Did you find any workaround?
No response
Relevant log output
No response
@naveenkumar-sanjeevirayan are you seeing this on all 4 platforms? Just want to make sure you made an accurate selection there.
Hi @naveenkumar-sanjeevirayan. 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.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.
Hi, @PureWeen I'm facing this on Windows and Android platforms. I didn't check in Mac and Ios. So, Please ensure from your side for Mac and iOS platforms.
@naveenkumar-sanjeevirayan are you seeing this on all 4 platforms? Just want to make sure you made an accurate selection there.
Hi - I actually reported this to SyncFusion, and they opened the bug.
It failed on iOS, Windows, and Android. I don't use it in MacCatalyst, so I don't know about that one.
If you simply download and run the sample you can see it though.
This works fine in .NET7.0 and issue occurring in .NET8.0
@PureWeen Can you check on this
Any update on this?... Please resolve this as soon as possible or any workaround available ? @PureWeen
trying to reproduce... do you have a call stack ? what happens if you disable Xaml Compilation on App.xaml ?
We found that the IL generated for your custom themes inheriting from CustomeThemeDictionary is wrong. you can disable Xaml compilation on those (by attributing the code behind class with the [XamlCompilation(XamlCompilationOptions.Skip)] attribute as a workaround
I was unable to get the AccessViolationException, but there was indeed a NullRefException (that might have caused the AccessViolation one). there's a fix for it in #20463
@StephaneDelcroix, We tested the nightly build 8.0.7 but still we face the reported issue. Also, we further checked the test case you have added in your fix PR, and we found that the scenario is different compared to others. We have explained that in the below picture.
We have even simplified the replicating sample with the above scenario. In the attached sample We have created a class CustomThemeDictionary : ResourceDictionary. Then another class as LightThemeColors : CustomThemeDictionary. Keys in the LightThemeColors causes the crash whereas if the keys defined directly in CustomThemeDictionary works. Also below is the error screenshot for reference.
Note: Issue occurs only in Release mode.
Regarding the suggested workaround, it works for us skipping the XamlCompilation.
Sample link: CustomThemeTesting 1.zip
@Choza-rajan what you're describing is exactly what the PR is for. Investigating if the PR is in the nightly you tested or not...
@Choza-rajan in order to debug or get a stack trace, you could force XamlCompilation on DEBUG builds by setting MauiXamlCValidateOnly to false in your csproj. By doing that, you won't get the tooling you usually get (hot reload, etc, ...
the fix isn't available in 8.0.7, but should be in 8.0.10-nightly.10044