3

I'm failing at being able to read embedded resources in ASP.NET Core 3.1. Specifically, I'm following the example in the docs here:

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/file-providers?view=aspnetcore-3.1

I've updated my csproj file to the following adding the <GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
  </PropertyGroup>


  <ItemGroup>
    <EmbeddedResource Include="Data\sessions.json" />
    <EmbeddedResource Include="Data\speakers.json" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\EFLib\EFLib.csproj" />
    <ProjectReference Include="..\RepositoryLib\RepositoryLib.csproj" />
    <ProjectReference Include="..\SeedDataLib\SeedDataLib.csproj" />
  </ItemGroup>

</Project>

I have console app as follows and I get the error below when I run it.

class Program
{
    static async Task Main(string[] args)
    {
        Console.WriteLine("Hello World!");

        var manifestEmbeddedProvider =
            new ManifestEmbeddedFileProvider(typeof(Program).Assembly); // ERROR HERE

{"Could not load the embedded file manifest 'Microsoft.Extensions.FileProviders.Embedded.Manifest.xml' for assembly 'TestConsoleApp'."}

I'm basically trying to do what I use to do in ASP.NET Core 2 which was this and it's not working.

var assembly = Assembly.GetEntryAssembly();
        string[] resources = assembly.GetManifestResourceNames(); // debugging purposes only to get list of embedded resources
1
  • 1.new ManifestEmbeddedFileProvider(typeof(Program).Assembly); used in Startup.cs not console app.2.assembly.GetManifestResourceNames(); could work well in asp.net core3.1,what is your scenario? Commented Feb 10, 2020 at 3:10

1 Answer 1

4

I faced the same issue you described. Make sure that you added the following package reference to the .csproj where embedded resources are declared. Once I added it to my project and rebuilt the solution, it started working.

<ItemGroup>
  <PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="3.1.0" />
</ItemGroup>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.