Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded resource file not present at runtime .Net 4

I have a file I need to access at runtime, I've included it in my project and set it up as embedded resource (it's actually a source file, I changed the extension to .cs.txt to get around VS trying to compile it. That shouldn't matter, but I'm mentioning it anyway just in case). When I try getting the file

var assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream(resourceName);

I get a null. I've made sure I'm using the Namespace.Folder.Filename notation, but that didn't help. It appears the file is actually not there, because when I call

assembly.GetManifestResourceNames();

I get an empty string array. Any idea what could be the case?

like image 573
Shaggydog Avatar asked Sep 16 '25 05:09

Shaggydog


1 Answers

I appreciate this is an old thread but what I found this morning might be useful to others.

I had a resource where the filename had multiple dots in it...

example filename: data.txt.dat

var resources = asm.GetManifestResourceNames(); // None found (empty array)

renamed to data.txt (still just an embedded resource in the project configuration

var resources = asm.GetManifestResourceNames(); // Entry found ("Assembly.Namespace.data.txt")

So maybe there is some limitation around multiple . characters in the name

like image 134
Sam Lad Avatar answered Sep 17 '25 20:09

Sam Lad