I firstly wanted to info that I am currently using Visual studio 2017 with .net 4.6.1 version.
I create a wpf application in which I used Entity framework to manager the sqlite database.
My Dbcontext class is as Below.
public class DbContextClass :DbContext
{
public DbSet<HomeModel> Home { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "/EfCrud";
System.IO.Directory.CreateDirectory(path);
optionsBuilder.UseSqlite($"Data source={path}/Database.db");
}
}
And I calling a function inside the ViewModel to Ensure that Database should be there when Application loads in the memory. My code is as below.
try
{
using (var context = new DbContextClass())
{
context.Database.EnsureCreated();
}
}
catch(Exception E)
{
MessageBox.Show(E.ToString());
}
CrudClass.ShowEntries(HomeList);
IsVisible = true;
}
Now the problem is, When I run my application in Visual Studio that the about code create Database in the specified location when no database is present. But When I create Setup of my application and try to run it into the system, It gives me exception and my application ultimately terminated.
The Exception message Which I got is as follow :-
please let me know the issue and how can I fixed this issue.
I tried installing different version of Entity framework but didn't able to get rid of the Exception. I wanted to know the reason for which I am getting such Exception and how can I fix the issue.