I installed Visual Studio 2015 Community edition this morning. After that I created a new ASP.NET Web Application and opted for the "Web Application" template in the "ASP.NET 5 Preview Templates" section.
After the project was created I added a 2nd project to the solution (Class Library) which is supposed to contain all my entities (EF Code First), business objects, utilities and other core stuff.
The Class Library uses .NET Framework 4.5.2 and references EntityFramework 6.1.3. I also added ASP.NET Identity 2.2.1 (including the EntityFramework provider).
In App.config I have this connection string:
<connectionStrings>
<add name="ApplicationDbContext" connectionString="Server=(localdb)\projectsv12;Database=myDB;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
And here is the corresponding Database Context class:
public class ApplicationDbContext : IdentityDbContext<User> {
public ApplicationDbContext() : base("name=ApplicationDbContext") { }
public static ApplicationDbContext Create() {
return new ApplicationDbContext();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
}
public System.Data.Entity.DbSet<Branch> Branches { get; set; }
public System.Data.Entity.DbSet<Dimension> Dimensions { get; set; }
}
As you can see the name of the connection string is identical in both App.config and DbContext constructor. I also set up two POCO entities and added them to the DbContext (Branches and Dimensions).
Everything should be ready for "enable-migrations" and then "update-database" as I have done it several times with Visual Studio 2013.
However, in Visual Studio 2015, I am getting an error message. Here is what I did:
- I pulled up the Package Manager Console.
- I chose my Class Library project in the "Default project" dropdown.
- I entered "enable-migrations" at the command prompt (and I also tried the new "add-migration" that comes with EF7 - since EF7 is referenced in my Web project I though I'll give it a try).
Here is the error message I am getting:
Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable." At C:\Tfs\Dev\primaVISTA\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:720 char:5 + $domain.SetData('startUpProject', $startUpProject) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SerializationException System.NullReferenceException: Object reference not set to an instance of an object. at System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetProjectTypes(Project project, Int32 shellVersion) at System.Data.Entity.Migrations.Extensions.ProjectExtensions.IsWebProject(Project project) at System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String configurationTypeName, Boolean useContextWorkingDirectory) at System.Data.Entity.Migrations.EnableMigrationsCommand.FindContextToEnable(String contextTypeName) at System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0() at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) Object reference not set to an instance of an object.
Does anybody have an idea what I am doing wrong? Am I missing anything? Or is this due to a bug in VS2015 maybe?
I really appreciate any help! Thanks!!
As Sirwan suggested, I opened a command prompt and cd'ed my way up to my library project folder. Here I executed the add migration command:
C:\Tfs\Dev\primaVISTA\src\primaVISTA.Core>dnx . ef migration add M1
System.InvalidOperationException: Unable to resolve project 'primaVISTA.Core' from C:\Tfs\Dev\primaVISTA\src\primaVISTA.Core at Microsoft.Framework.Runtime.ApplicationHostContext..ctor(IServiceProvider serviceProvider, String projectDirectory, String packagesDirectory, String configuration, FrameworkName targetFramework, ICache cache, ICacheContextAccessor cacheContextAccessor, INamedCacheDependencyProvider namedCacheDependencyProvider, IAssemblyLoadContextFactory loadContextFactory, Boolean skipLockFileValidation) at Microsoft.Framework.Runtime.DefaultHost.Initialize(DefaultHostOptions options, IServiceProvider hostServices) at Microsoft.Framework.Runtime.DefaultHost..ctor(DefaultHostOptions options, IServiceProvider hostServices) at Microsoft.Framework.ApplicationHost.Program.Main(String[] args) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Framework.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider) at dnx.host.Bootstrapper.RunAsync(List`1 args, IRuntimeEnvironment env, FrameworkName targetFramework) at dnx.host.RuntimeBootstrapper.ExecuteAsync(String[] args, FrameworkName targetFramework) at dnx.host.RuntimeBootstrapper.Execute(String[] args, FrameworkName targetFramework)
I have no clue what this means ...