No connection string named 'x' found in application config file... but it works?

c# entity-framework-6 mvvm wpf xaml


Although I've read a number of inquiries about this problem, none of them appear to be exactly what I'm seeing. I recently used's straightforward, one-project lesson to learn more about using the MVVM paradigm with Entity Framework ( Everything seemed to work great when I followed everything exactly.

But as I became more intrigued, I began to rearrange certain items. I relocated my MainWindowViewModel into a new folder that I titled ViewModels because I wanted to learn more about how XAML's namespaces functioned. Then I established the data context for the window and added a new namespace named "vms" to my XAML with the proper location.

<Window x:Class="CpMvvMWithEntity.MainWindow"
    Title="MainWindow" Height="350" Width="525">

   <vms:MainWindowViewModel />

However, if I try to accomplish this, Visual Studio displays a bright blue underlined warning that says, "No connection string called [myEntities] could be discovered in the application config file." However, the App.config file has a connection string, and the software functions as anticipated when I build and execute it.

Any theories as to why this is taking place?

7/5/2016 6:27:15 PM

Accepted Answer

In the view, you are defining an instance of your view model. As a consequence, Visual Studio creates an instance of your class in the editor and executes the function Object() { [native code] } code inside the VS process.

A database connection attempt is being made by your function Object() { [native code] }. It searches the app.config file for a connection string for the active process. Visual Studio is the process that is now active. There doesn't seem to be adevenv.exe.config Please refrain from creating a file and inserting your connection string into it. If there is a file, it most likely doesn't include your connection string.

Your code is throwing problems, and the editor is built to catch them from UI elements and display warnings in the user interface. It's doing that for your code.

Avoid working in your function Object() { [native code] } as a solution. Really, you shouldn't be doing lengthy operations there. Only you and your application design may decide where to relocate your database logic.

Accepting that it could occur as an option can help you better manage your mistake. Log the missing connection string, if possible. Or acknowledge the exception and go on. That wasn't the finest design choice.

Avoiding setting your DataContext in this manner is another option. Create it and assign it in the code-behind. In this manner, you may do a check to determine whether you are a designer and omit the whole procedure.

Finally, do no damage and do no foul. Just disregard the designer's mistake. Your application is not at all harmed by it. Go on to more crucial projects.

5/23/2017 11:51:29 AM

Popular Answer


Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow