Start Debugging
2020-11-20 Updated 2023-11-05 csharp

Get Embedded Resource Stream in .NET Core

Learn how to retrieve an embedded resource stream in .NET Core by understanding how resource names are composed and using GetManifestResourceStream.

In order to retrieve an embedded resource in .NET Core, we first need to understand how the resource name is composed. It’s got 3 elements, all joined by dots (.):

Let’s take a concrete example. We have a project (assembly) with a root namespace MyApp.Core. Inside our project we’ve got a folder + subfolder like Assets > Images. And inside of that, we have an embedded resource called logo.png. In this case:

Join them using . and you get: MyApp.Core.Assets.Images.logo.png.

Once you know the resource identifier, all you need is a reference to the assembly containing the actual resource. We can easily obtain that off of any class we have defined in that assembly – assuming we have a class MyClass:

typeof(MyClass).Assembly.GetManifestResourceStream("MyApp.Core.Assets.Images.logo.png")

Retrieve list with all embedded resources in an assembly

If you can’t find the resource, it’s usually because of one of the following:

To help troubleshoot, you can list all the embedded resources in an assembly and go from there. To do so:

typeof(MyClass).Assembly.GetManifestResourceNames()

This will return a simple string[] and you can easily use it in the Immediate Window for debugging purposes.

< Back