Calls to GetManifestResourceStream Always Return NULL

I was trying to load some text from a DLL where the text was saved into text files, included in the project and marked to be compiled as an Embedded Resource. I was using the below approach from the MSDN documentation:

    _assembly = Assembly.GetExecutingAssembly(); 
    _textStreamReader = new StreamReader(_assembly.GetManifestResourceStream("MyNamespace.MyTextFile.txt"));

I was building the namespace dynamically from the type, and I had the files in a Resources directory in my project. You can load the namespace from your type. When you put an embedded resource in a folder, you’re supposed to prefix the filename with “Folder.”  I thought I was all set.

Yet, this wasn’t working, so I eventually tried to eliminate any of the extra variables, inserting the namespace statically (the default namespace from my project) and moving the file into the root of my project.  Still no love.

I built my DLL and opened it up in ILDASM.  Guess what? No resources were being exported!  Lamesauce!


What what?!

So I went back into my project, tried removing and adding the files back again. I double- and triple-checked that my files were marked to be embedded resources.


Sanity check. I added a new text file to my project, called TextFile1.txt, the default in Visual Studio, set the Build Action to “Embedded Resource” and went back to my DLL.


Sweet jalapeño peppers! What was different!?

…oh.  Right. I am using the pattern “DomainNames.en.txt”, not “DomainNames.txt”. Notice I had the culture in there? That can’t possible make a difference, can it?  I renamed all my txt files, rebuilt and…



So Remember!

If you are trying to load resources that are compiled into your assembly as Embedded Resources, it appears you can’t use extra “dotting” in your naming convention or the compilers won’t properly add your file to the manifest, at which point all calls to GetManifestResourceStream will return null.