Inclusion of an embedded resource in a collection made by Roslyn

I am trying to include an embedded resource in a dll that I am compiling with Roslyn. I found something that helped 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 the unit tests that I created for the project, except for those that rely on the resource file.

The error I am getting is as follows:

 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. 

It is assumed that the dll is signed, and when it is emitted by roslyn, it issues the correct public key. In addition, Resource.resx is included in my project directly in the Properties folder.

I would appreciate any help anyone could provide.

+6
source share
1 answer

Ok, so when I was looking for the answers, I came across this webpage where it was noted that the resource stream was empty until it added the namespace.

So, after adding the namespace, I got something 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 works exactly as you expected.

+7
source

Source: https://habr.com/ru/post/977994/


All Articles