Visual Studio 2022 - how to to Load Embedded Resources in a Class Library Project
I'm stuck on something that should probably be simple... I'm testing a new approach and I'm stuck on something that should probably be simple. I've searched everywhere and can't find a clear answer. I'm currently working on a .NET 6 class library where I need to embed some resource files (like images and text files) to access them at runtime. I've set the 'Build Action' property of these files to 'Embedded Resource', but when I try to load them using the `Assembly.GetManifestResourceStream` method, I'm working with a `NullReferenceException`. Hereโs the code snippet I'm using: ```csharp using System; using System.IO; using System.Reflection; namespace MyLibrary { public class ResourceLoader { public Stream GetResourceStream(string resourceName) { var assembly = Assembly.GetExecutingAssembly(); var stream = assembly.GetManifestResourceStream(resourceName); if (stream == null) { throw new InvalidOperationException("Resource not found: " + resourceName); } return stream; } } } ``` The resource name Iโm passing is in the format of `MyLibrary.Resources.MyImage.png`. I've double-checked that the namespace is correct and that the file is indeed marked as an embedded resource. However, I'm still getting the `NullReferenceException`. I've also tried debugging the assembly and listing out the manifest resources via `assembly.GetManifestResourceNames()` to verify the resource name, but it does not show up in the list. Hereโs the output I get when I call `GetManifestResourceNames()`: ```plaintext MyLibrary.dll ``` It seems like the resources are not being compiled into the assembly. I've tried cleaning and rebuilding the solution, but that hasn't resolved the scenario. Is there something I'm missing, or is there a specific configuration I need to check in Visual Studio 2022 to ensure these resources are correctly embedded? For context: I'm using C# on Ubuntu. Thanks in advance! I'm working on a microservice that needs to handle this. How would you solve this? How would you solve this?