<p>I am storing a PNG as an embedded resource in an assembly.  From within the same assembly I have some code like this:</p>

<pre><code>Bitmap image = new Bitmap(typeof(MyClass), "Resources.file.png");
</code></pre>

<p>The file, named "file.png" is stored in the "Resources" folder (within Visual Studio), and is marked as an embedded resource.</p>

<p>The code fails with an exception saying:  </p>

<blockquote>
  <p>Resource MyNamespace.Resources.file.png cannot be found in class MyNamespace.MyClass</p>
</blockquote>

<p>I have identical code (in a different assembly, loading a different resource) which works. So I know the technique is sound. My problem is I end up spending a lot of time trying to figure out what the correct path is. If I could simply query (eg. in the debugger) the assembly to find the correct path, that would save me a load of headaches.</p>

[{'answer_id': 27769, 'author': 'Konrad Rudolph', 'author_id': 1968, 'author_profile': 'https://Stackoverflow.com/users/1968', 'pm_score': 4, 'selected': False, 'text': "<p>I'm guessing that your class is in a different namespace. The canonical way to solve this would be to use the resources class and a strongly typed resource:</p>\n\n<pre><code>ProjectNamespace.Properties.Resources.file\n</code></pre>\n\n<p>Use the IDE's resource manager to add resources.</p>\n"}, {'answer_id': 27773, 'author': 'John', 'author_id': 33, 'author_profile': 'https://Stackoverflow.com/users/33', 'pm_score': 9, 'selected': True, 'text': '<p>This will get you a string array of all the resources:</p>\n\n<pre><code>System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();\n</code></pre>\n'}, {'answer_id': 28253, 'author': 'Dylan', 'author_id': 3074, 'author_profile': 'https://Stackoverflow.com/users/3074', 'pm_score': 6, 'selected': False, 'text': '<p>I find myself forgetting how to do this every time as well so I just wrap the two one-liners that I need in a little class:</p>\n\n<pre><code>public class Utility\n{\n    /// &lt;summary&gt;\n    /// Takes the full name of a resource and loads it in to a stream.\n    /// &lt;/summary&gt;\n    /// &lt;param name="resourceName"&gt;Assuming an embedded resource is a file\n    /// called info.png and is located in a folder called Resources, it\n    /// will be compiled in to the assembly with this fully qualified\n    /// name: Full.Assembly.Name.Resources.info.png. That is the string\n    /// that you should pass to this method.&lt;/param&gt;\n    /// &lt;returns&gt;&lt;/returns&gt;\n    public static Stream GetEmbeddedResourceStream(string resourceName)\n    {\n        return Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);\n    }\n\n    /// &lt;summary&gt;\n    /// Get the list of all emdedded resources in the assembly.\n    /// &lt;/summary&gt;\n    /// &lt;returns&gt;An array of fully qualified resource names&lt;/returns&gt;\n    public static string[] GetEmbeddedResourceNames()\n    {\n        return Assembly.GetExecutingAssembly().GetManifestResourceNames();\n    }\n}\n</code></pre>\n'}, {'answer_id': 22045449, 'author': 'user3356450', 'author_id': 3356450, 'author_profile': 'https://Stackoverflow.com/users/3356450', 'pm_score': 2, 'selected': False, 'text': '<p>The name of the resource is the name space plus the "pseudo" name space of the path to the file. The "pseudo" name space is made by the sub folder structure using \\ (backslashes) instead of . (dots).</p>\n\n<pre><code>public static Stream GetResourceFileStream(String nameSpace, String filePath)\n{\n    String pseduoName = filePath.Replace(\'\\\\\', \'.\');\n    Assembly assembly = Assembly.GetExecutingAssembly();\n    return assembly.GetManifestResourceStream(nameSpace + "." + pseduoName);\n}\n</code></pre>\n\n<p>The following call:</p>\n\n<pre><code>GetResourceFileStream("my.namespace", "resources\\\\xml\\\\my.xml")\n</code></pre>\n\n<p>will return the stream of my.xml located in the folder-structure resources\\xml in the name space: my.namespace.</p>\n'}, {'answer_id': 27993476, 'author': 'masterwok', 'author_id': 563509, 'author_profile': 'https://Stackoverflow.com/users/563509', 'pm_score': 3, 'selected': False, 'text': '<p>I use the following method to grab embedded resources:</p>\n<pre><code>protected static Stream GetResourceStream(string resourcePath)\n{\n    Assembly assembly = Assembly.GetExecutingAssembly();\n    List&lt;string&gt; resourceNames = new List&lt;string&gt;(assembly.GetManifestResourceNames());\n\n    resourcePath = resourcePath.Replace(@&quot;/&quot;, &quot;.&quot;);\n    resourcePath = resourceNames.FirstOrDefault(r =&gt; r.Contains(resourcePath));\n\n    if (resourcePath == null)\n        throw new FileNotFoundException(&quot;Resource not found&quot;);\n\n    return assembly.GetManifestResourceStream(resourcePath);\n}\n</code></pre>\n<p>I then call this with the path in the project:</p>\n<pre><code>GetResourceStream(@&quot;DirectoryPathInLibrary/Filename&quot;);\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/27757', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1006/']