question

ShawnSong-3285 avatar image
0 Votes"
ShawnSong-3285 asked DaisyTian-1203 commented

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

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.

windows-wpf
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DaisyTian-1203 avatar image
0 Votes"
DaisyTian-1203 answered DaisyTian-1203 commented

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.

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

But when I choose Resource for Build Action,this Resources file or image file would be removed from project...what's wrong with this? thank u please

0 Votes 0 ·

@ShawnSong-3285
What does your Resources file or image file would be removed from project mean? Could you give me more explaination about it?

0 Votes 0 ·

89300-image.png


this file would be removed like this,and reports "can't find the resource" error when it running

0 Votes 0 ·
image.png (38.3 KiB)
Show more comments
MariodelValleMatos-0348 avatar image
0 Votes"
MariodelValleMatos-0348 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.