Skip to content

Getting AccessViolationException while adding custom resource dictionary in App.Xaml file in Release builds #19535

@naveenkumar-sanjeevirayan

Description

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:
AccessViolationException

Steps to Reproduce

  1. Download and extract the attached example.
  2. Run the CustomThemeTesting project with release mode. You will get the access violation exception.

Maui_Theme_Issue.zip

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

Metadata

Metadata

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions