As mentioned in the comments, you get
Warning 1 Failed to copy "... \ cookbook \ Cookbook.Services \ Database1.mdf" to "bin \ Debug \ Database1.mdf". Start repetition 1 in 1000 ms.
The process cannot access the file '... \ cookbook \ Cookbook.Services \ Database1.mdf' because it is being used by another process. Cookbook.Services
warning (and after reporting a sufficient number of attempts) from the compiler in the assembly, because the process created for the application that you ran / debugged:
- not yet completed, or
- all connections to the database file are not closed.
So, when you create it again, its file descriptor is still open, and you cannot copy it through an open file.
It is hard to establish from the code that you posted in your question what the direct reason for this is, but this line:
Messenger.Default.Send<ViewModelBase>(new MainViewModel());
clearly problematic because it returns a new instance instead of a singleton lifecycle instance from the SimpleIoC container. Although still ugly in terms of DI, you can change it to:
Messenger.Default.Send<ViewModelBase>(ServiceLocator.Current.GetInstance<MainViewModel>());
Therefore, it will not create a new instance of your MainViewModel , but will return it from the IoC container.
In addition, you may want to make sure that your database context is registered in your container and entered into the desired view models. Illustrating this (if your database context / class is called MyDbContext , implements IMyDbContext and takes the connection string as a constructor argument):
SimpleIoc.Default.Register<IMyDbContext>(() => new MyDbContext(GetMyConnectionString()));
Now you also need to make sure that the correct cleanup is performed when you exit the application, so that Dispose is called on the IMyDbContext instance and any other potential resources of your application that require removal. If this has not already been done, through MVVM Light you can do this by responding to the Application.Exit event on Application :