Can't find embeded resources image in .Net5 Wpf application

Shawn Song 41 Reputation points
2021-04-19T14:48:26.627+00:00

I created one dll Library to put image resources files in .
and I use"/{namespace;component/Resources/{filesname}}"in xaml to get this file.
this works good in net framework,but seems not well in .net core and .net5
what should I do now.

Developer technologies Windows Presentation Foundation
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. DaisyTian-1203 11,646 Reputation points
    2021-04-20T02:54:59.997+00:00

    I use /{namespace;component/Resources/{filesname}} in xaml to show in .Net5 Wpf application with below steps:

    Dll part:
    Create a WPF .NET Application named MyDll, its target platform is .NET 5
    Add a file named Resources and include a image 969.jpg in it.
    Choose Resource for Build Action and Copy always for Copy to Output Directory .
    Make it to dll refer to steps in : How to Convert a WPF Windows Application to dll

    WPF Project part:
    Create a WPF .NET Application named EmbededResourcesImage, its target platform is .NET 5.
    Add MyDll.dll to its Dependencies.
    Use the image like <Image Source="/MyDll;component/Resources/969.jpg"></Image> in xaml

    Build Action Instructions (Refer to doc)
    Resource (WPF only): Embeds the file in a shared (by all files in the assembly with similar setting) assembly manifest resource named AppName.g.resources.
    Embedded resource: Embeds the file in an exclusive assembly manifest resource.

    If I misunderstand your question, please point out.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Mario del Valle Matos 1 Reputation point
    2021-04-22T08:52:45.16+00:00

    I had exactly the same problem and those files are automatically removed when changed to "Resource". In my case I changed the project from raw Class library to UserControl Class library:

    <PropertyGroup>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
    <Version>1.0.9</Version>
    </PropertyGroup>

    Done. Images are not removed any more

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.