Home > Software design >  Why get resource not found exception when try to consume assembly resources in .NET MAUI?
Why get resource not found exception when try to consume assembly resources in .NET MAUI?

Time:08-19

I have created a .NET MAUI Class Library and a ResourceDictionary containing colors inside of it. When I reference it in the local assembly (Class library) it recognizes the color and IntelliSense autocompletes.

However, when trying to reference it in another assembly (class library imported as NuGet package), I can't reference any of the colors inside the dictionary. In the below code, the "ColorsDictionary" line is autocompleted by VS IntelliSense, so the Dictionary is 100% referenced correctly.

 <?xml version = "1.0" encoding = "UTF-8" ?>
    <Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:vewcore="clr-namespace:VewTech.Core.Themes.Colors;assembly=VewTech.Core"
                 x:Class="MauiApp3.App">
        <Application.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <vewcore:ColorsDictionary/>
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Application.Resources>
    </Application>

When trying to consume resources via DynamicResource or StaticResource from the local project, colors are not autocompleted by VS IntelliSense, and if manually writing them, it throws an exception (resource not found).

Any ideas about what is wrong with my code?

CodePudding user response:

It is working now, after reinstalling VS, creating a new project, and importing the package into the new project.

Don't really know why this was happening, I guess it was because of the update (I was using VS2022 Preview and updated to the new release, and this error happened afterward).

  • Related