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 = Assembl
You need to unload your solution.Then edit project.Afterfind your folder and change like this:
<EmbeddedResource Include="yourpath" />
I had the same problem, thanks to Jay I found it was hyphens in the directory name.
ProjectName.ResourceFolder.Sub-Directory
becomes ProjectName.ResourceFolder.Sub_Directory
when you reference the resource stream.
Here is the cause of my null value.
http://adrianmejia.com/blog/2011/07/18/cs-getmanifestresourcestream-gotcha/
The GetManifestResourceStream
method will always returns NULL
if the resource ‘built action‘ property is not set to ‘embedded resource‘
After setting this property with all the needed files assembly.GetManifestResourceStream
starts returning the correct stream instead of NULL
.
You probably need to specify the path to your txt file in the GetManifestResourceStream
parameter, or you could try sticking the txt file in the same directory as your executable. Hope that helps!
In case it helps anyone else, Make sure Assembly.GetExecutingAssembly()
line is called from same assembly which has embedded resources.
First Unload the project and click on edit the project file.
Inside the project file make sure that the item you are fetching from the assembly is included inside <EmbeddedResource> tag.
Eg:
<ItemGroup>
<EmbeddedResource Include="Template\ForExampleFile.html" />
</ItemGroup>
The files I added into the project were just in Content tag but not in the EmbeddedResource as shown below by default. Hence the stream was returning null.
<ItemGroup>
<Content Include="Template\ForExampleFile.html" />
</ItemGroup>