GetManifestResourceStream returns NULL

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.

See Assembly.GetManifestResourceNames() on MSDN.

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 too easy to get the resources from the currently executing assembly rather than from a referenced assembly.

EDIT – .NET Core
Please see this SO post for details on how to embed using .NET Core.

Retrieving the manifest info looks to be similar – just use this.GetType().GetTypeInfo().Assembly.GetManifestResourceNames() to get the a manifest from the assembly where the code is executing.

I haven’t figured out how to do the equivalent of Assembly.GetExecutingAssembly() in .NET Core yet! if anyone knows – please let me know and I will update this answer.

Leave a Comment