This is a C# .NET 4.0 application:
I'm embedding a text file as a resource and then trying to display it in a dialog box:
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "MyProj.Help.txt";
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
string result = reader.ReadToEnd();
System.Windows.Forms.MessageBox.Show(result, "MyProj", MessageBoxButtons.OK);
You can check that the resources are correctly embedded by using
//From the assembly where this code lives! this.GetType().Assembly.GetManifestResourceNames() //or from the entry point to the application - there is a difference! Assembly.GetExecutingAssembly().GetManifestResourceNames()
when debugging. This will list all the (fully qualified names) of all resources embedded in the assembly your code is written in.
Simply copy the relevant name, and use that instead of whatever you have defined in the variable 'resourceName'.
Notes - the resource name is case sensitive, and if you have incorrectly embedded the resource file, it will not show up in the list returned by the call to GetManifestResourceNames(). Also - make sure you are reading the resource from the correct assembly (if multiple assemblies are used) - it's all to easy to get the resources from the currently executing assembly rather than from a referenced assembly.