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. … Read more

Could not find any resources appropriate for the specified culture or the neutral culture

I just hit this same exception in a WPF project. The issue occurred within an assembly that we recently moved to another namespace (ProblemAssembly.Support to ProblemAssembly.Controls). The exception was happening when trying to access resources from a second resource file that exists in the assembly. Turns out the additional resource file did not properly move … Read more

Reading a resource file from within jar

Rather than trying to address the resource as a File just ask the ClassLoader to return an InputStream for the resource instead via getResourceAsStream: try (InputStream in = getClass().getResourceAsStream(“/file.txt”); BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { // Use resource } As long as the file.txt resource is available on the classpath then this approach will … Read more

Storing WPF Image Resources

If you will use the image in multiple places, then it’s worth loading the image data only once into memory and then sharing it between all Image elements. To do this, create a BitmapSource as a resource somewhere: <BitmapImage x:Key=”MyImageSource” UriSource=”../Media/Image.png” /> Then, in your code, use something like: <Image Source=”{StaticResource MyImageSource}” /> In my … Read more

How to read embedded resource text file

You can use the Assembly.GetManifestResourceStream Method: Add the following usings using System.IO; using System.Reflection; Set property of relevant file: Parameter Build Action with value Embedded Resource Use the following code var assembly = Assembly.GetExecutingAssembly(); var resourceName = “MyCompany.MyProduct.MyFile.txt”; using (Stream stream = assembly.GetManifestResourceStream(resourceName)) using (StreamReader reader = new StreamReader(stream)) { string result = reader.ReadToEnd(); } … Read more