1

I'm trying to write my first app in Entity Framework.

In program.cs (where my main() is) I have line ProdContext ctx = new ProdContext();. The prodContext.cs is:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Entity;
using System.Text;

namespace Entity_Framework
{
    class ProdContext : DbContext
    {
        public DbSet<Category> Categories { get; set; }
        public DbSet<Product> Products { get; set; }
    }
}

While trying to run main I get exception at above line:


FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

I have fresh install of Visual Studio with C# and EF (I installed it with install-package entityframework -version 6.1.3.0). Why am I getting that exception?

6
  • Do you have System.Configuration in your references folder? Commented Oct 29, 2019 at 9:00
  • References folder? Sorry if it's an obvious question, program is for uni assignment and we were given little to no instructions besides "select Console Application and run install-package entityframework -version 6.1.3.0). Commented Oct 29, 2019 at 9:04
  • In console application, where do you add dlls? Commented Oct 29, 2019 at 9:06
  • You mean EF? Through Package Manager Console, using that install-package command. Commented Oct 29, 2019 at 9:09
  • In Solution Explorer, check whether you have a References folder under your project Commented Oct 29, 2019 at 9:13

1 Answer 1

2

I would suggest that you're using .NET Core application while still trying to install .NET library. EF 6 is ".NET" specific library. With .NET Core application type for your project you will have such crash (or similar) if installing .NET EF Version:

enter image description here

For .NET Core applications, you should install Core version. https://www.nuget.org/packages/Microsoft.EntityFrameworkCore/

Make sure you don't have this (or similar) error in your references:

enter image description here

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.