ttugates
ttugates

Reputation: 6291

How to access Embedded Resource from PCL Targeting ASP.NET CORE & .NET Framework 4.6

I have a PCL Targeting ASP.NET CORE & .NET Framework 4.6.

In the root of PCL, I have added PCLResource.txt and marked it as Build Action > Embedded Resource.

Publish to NuGet, Installed from NuGet to my Consumer WinForm App (4.6.2)

Calling PCL.TestMethod() works. However,

string[] asm = Assembly.GetExecutingAssembly().GetManifestResourceNames();

And

var assembly = GetType().GetTypeInfo().Assembly;
string[] resources = assembly.GetManifestResourceNames();

results in :

And

Stream stream = assembly.GetManifestResourceStream(string.Format("PCL.PCLResrouce.txt"));

results in null

Using dotPeek, I can see PCLResrouce.txt in the DLL. dotPeek of PCL Resources

How do I get access to the Embedded Resource text file as a consumer?

I have used the following resources:

And I realize I mispelled resource :/ but thats not the issue.

Upvotes: 2

Views: 641

Answers (1)

ttugates
ttugates

Reputation: 6291

My issue was I was not getting the PCL Assembly.

Solution:

var assembly = Assembly.GetAssembly(typeof(StaticPCLClass));

I am not necessarily working with this class when I need the resource, but this allows me to get the Assembly. Now I am able to call:

Stream stream = assembly.GetManifestResourceStream(string.Format("PCL.PCLResrouce.txt"));

Used help from here.

Upvotes: 1

Related Questions