Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including an embedded resource in a compilation made by Roslyn

I'm attempting to include an embedded resource into a dll that I am compiling using Roslyn. I've found something that helped put me on the right track here.

However, when I create the dll using the following code:

const string resourcePath = @"C:\Projects\...\Properties\Resources.resources";
var resourceDescription = new ResourceDescription(
                    "Resources.resources",
                    () => File.OpenRead(resourcePath),
                    true);

var result = mutantCompilation.Emit(file, manifestResources: new [] {resourceDescription});   

I find that it will pass all of the unit tests that I have created for the project except for those that rely on the Resources file.

The error I'm getting looks like the following:

System.Resources.MissingManifestResourceException ... Make sure "[Project].Properties.Resources.resources" was correctly embedded or linked into      
assembly "[Project]" at compile time, or that all the satellite assemblies required are loadable and fully signed.

The dll is supposed to be signed, and when it is emitted by roslyn it comes out with the correct public key. Also, the Resource.resx is included in my project directly in the Properties folder.

I would appreciate any help anyone could provide.

like image 253
Matt Hunter Avatar asked Nov 10 '14 19:11

Matt Hunter


1 Answers

Ok, so while I was looking for answers, I came across this web page where it was commented that the resource stream was null until the he added the namespace.

So after adding the namespace I got somehting like this

const string resourcePath = @"C:\Projects\...\Properties\Resources.resources";
var resourceDescription = new ResourceDescription(
                "[namespace].Resources.resources",
                () => File.OpenRead(resourcePath),
                true);

var result = mutantCompilation.Emit(file, manifestResources: new [] {resourceDescription}); 

which runs exactly like you'd expect.

like image 194
Matt Hunter Avatar answered Oct 14 '22 01:10

Matt Hunter