Reputation: 23
In my project, I have created a resources file, added an image resource to it and set Build Action to "Embedded Resource" but when I delete the original file, it is also deleted from resources (shows as missing). Also the size of Resources.resx is 7 KB although the image is more than 2 MB which, of course, is impossible with really embedded resource. Who knows how to pack that image into .resx? (Sorry if my question is duplicate but I have searched over the Internet and have not found.)
Upvotes: 0
Views: 32
Reputation: 916
You don't need to deal with .resx at all. When you use the “Build Action” “Embedded Resource”, the build process really embeds your file into the executable module of your assembly.
The most universal and convenient way to directly retrieve your file content is using System.Reflection.Assembly.GetManifestResourceNames
combined with System.Reflection.Assembly.GetManifestResourceStream
.
For further details, please see my recent answers with a source code sample, this and this one. In the first answer, you will also find a reference to a good informative article on the topic, and in the second one — more information on getting access to different assemblies.
Upvotes: 0