WPF MVVM - No connection string named 'MyEntities' could be found in the application config file.
Hello Team,
While working on a simple WPF MVVM application using Entity Framework 6.x and Visual Studio 2019, I encountered this strange error No connection string named 'MyEntities' could be found in the application config file. However, if I compile and debug my application, it would proceed with running the project. I've searched lots of information and most of the solutions presented were to copy the web.config or app.config file from a class library to the project that is set as the startup application. One thing I've noticed though is that this error appears only on the XAML page of where the DataContext is assigned. After doing some experiments of modifying my application, I came up with a solution that is instead of setting the DataContext in the XAML like below:
I assigned the DataContext in the code behind of the MainWindow and thus the error message disappeared.
Note that this is only a temporary workaround since the common method is to set the DataContext in the XAML page. If this is a bug, I hope Microsoft will release a hotfix for this to resolve this strange issue.
While working on a simple WPF MVVM application using Entity Framework 6.x and Visual Studio 2019, I encountered this strange error No connection string named 'MyEntities' could be found in the application config file. However, if I compile and debug my application, it would proceed with running the project. I've searched lots of information and most of the solutions presented were to copy the web.config or app.config file from a class library to the project that is set as the startup application. One thing I've noticed though is that this error appears only on the XAML page of where the DataContext is assigned. After doing some experiments of modifying my application, I came up with a solution that is instead of setting the DataContext in the XAML like below:
<Window.DataContext> <viewModel:StudentViewModel/> </Window.DataContext>
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.DataContext = new StudentViewModel(); } }
Comments
Post a Comment