1

Yesterday, I got the error message

Could not get the reflection type for DbContext

when trying to add a new controller. I have many controllers in my solution already, so I don't know why this suddenly occured.

Then I followed the solution given to this question, and now I'm faced with a new error message:

Could not find any resource appropriate for the specified culture or neutral culture. Make sure "SolutionName.DbSeedingResource.resources" was correctly embedded or linked into assembly "SolutionName" at compile time, or that all the satellite assemblies required are loadable and fully signed.

I don't understand what this error message means.

The resource file contains a long list of zip codes in JSON format, which are seeded into the database upon initial migration.

UPDATE

I have tried adding this to the csproj, but I still get the same error message:

<ItemGroup>
    <EmbeddedResource Include="DbSeedingResource.resx" />
</ItemGroup>

UPDATE 2

I tried removing the resx-file from my project, and then I got this error again:

Could not get the reflection type for DbContext

Stian
  • 1,522
  • 2
  • 22
  • 52
  • What is your asp.net core verion? Try to check [Could not get the reflection type for DbContext](https://github.com/aspnet/Scaffolding/issues?utf8=%E2%9C%93&q=Could+not+get+the+reflection+type+for+DbContext) – Edward Sep 24 '19 at 07:27
  • @TaoZhou I'm running Asp.Net Core v2.2. VS is v16.2.2. .NET Framework is v4.8.03752. How can I find out if I have any C#8 code in my project? – Stian Sep 25 '19 at 07:49
  • @TaoZhou I haven't done anything to enable C#8 in VS. – Stian Sep 25 '19 at 08:12
  • Does this issue happen to specific project? Is there any demo to reproduce your issue? – Edward Sep 25 '19 at 08:31
  • @TaoZhou It only happens in this one project. I tried creating a new project, but wasn't able to reproduce the issue. – Stian Sep 25 '19 at 08:50

2 Answers2

3

Had a similar issue for a NetCore project and I noticed that after I added my migration (let's name it WhateverMigration), the .resx file reference as EmbeddedResource was not added to the .csproj even tho everything seemed fine. So I opened my .csproj file and I added:

<EmbeddedResource Update="Migrations\202107071914322_WhateverMigration.resx">
    <Generator></Generator>
    <DependentUpon>202107071914322_WhateverMigration.cs</DependentUpon>
</EmbeddedResource>
Mari Faleiros
  • 898
  • 9
  • 24
0

I had a similar problem when trying to run an EF migration, I think the same answer will apply.

My error was "Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "(Namespace).(MyMigrationName).resources" was correctly embedded or linked into assembly "(MyAssembly)" at compile time, or that all the satellite assemblies required are loadable and fully signed."

In VS Solution Explorer I clicked the triangle beside the file to see the .resx file, and I noticed that the resx file for the migration wasn't included in the solution:

enter image description here

I right clicked on the offending .resx file, include in solution, and he little 'missing file' icon was replaced by something more reassuring and boom! it all worked.

enter image description here

Not sure how the issue crept in, but happy to have a fix.

Shewan
  • 61
  • 1
  • 10