locked
Getting a "No connection string named '' cound be found in the application config file" error, and I don't understand why RRS feed

  • Question

  • I'm working on a WPF app, trying to make it very MVVM-y. I'm trying to data bind my ViewModel class to the only window I have in the whole application. I've got this in the Windows.Resources section:

    <vm:SpecMapViewModel x:Key="SpecMapVM" />

    The error message says, "No connection string named 'PrismSpecMap' could be found in the application config file"

    However if I open up the App.Config file for this project, sure enough there's the PrismSpecMap connection string there, exactly where it should be. So why is VS 2013/WPF//.NET 4.5 complaining about something not being there when in fact it is???

    And here is where it gets even weirder. I can compile it and the build informs me that everything succeeded. No problems! We're good to go! And yet there's a blue squiggly line under the line I listed above. And within Solution Explorer the .XAML file has a red squiggly line under it! What? How can there be no problem, but there's a problem, but there's no problem, but there's a problem, ...


    Rod


    • Edited by Doctor-Who Wednesday, April 29, 2015 9:57 PM Needed to add more
    Wednesday, April 29, 2015 9:52 PM

All replies

  • In the designer, the parameterless constructor of your view will run.

    Similarly something you instantiate in xaml like that SpecMapVM.

    You can get problems if that then relies on something which isn't available to it at design time.

    You can stick a bit of code just returns out such a constructor whilst in the designer:

    public MainWindow()
    {
        InitializeComponent();
        if (DesignerProperties.GetIsInDesignMode(new DependencyObject())) 
            return;

    Obviously, this is likely to be your SpecMapVM rather than MainWindow in your case.

    http://social.technet.microsoft.com/wiki/contents/articles/29874.aspx


    Hope that helps.

    Technet articles: Uneventful MVVM; All my Technet Articles


    • Edited by Andy ONeill Thursday, April 30, 2015 6:47 AM
    • Marked as answer by Doctor-Who Thursday, April 30, 2015 5:09 PM
    • Unmarked as answer by Doctor-Who Friday, May 1, 2015 2:49 PM
    Thursday, April 30, 2015 6:46 AM
  • WOW, that is something I did not know. Thank you!

    Rod

    Thursday, April 30, 2015 5:09 PM
  • I must admit it surprised me when I realised it.

    But when you think about it....

    It's kind of obvious that the designer is instantiating something or other.

    You can see styles applied and they're all classes > objects.

    XAML is just a way of declaring a bunch of classes to be instantiated into objects.

    If you put your mind to it, you can see a fully populated window in the designer.

    Like:

    http://social.technet.microsoft.com/wiki/contents/articles/26200.aspx


    Hope that helps.

    Technet articles: Uneventful MVVM; All my Technet Articles

    Thursday, April 30, 2015 5:16 PM
  • Andy,

    I'm still getting the error in the designer. Now I'm wondering if I might have inadvertently put in a conflicting name? For example I'm using EF 6.1.2. At this point I don't remember  all of the details, but what I've got now is 3 classes in a folder I called Data, that relate to 3 tables in the database. One of these classes is named PrismSpecMap. And that is exactly what VS 2013 is complaining about when it says that there's no connection string in the application configuration file named PrismSpecMap. But like I said there is.

    So the question is, did I inadvertently choose a name for the class that is the same name used for the connection string? Or is this something that EF did on it's own?


    Rod

    Thursday, April 30, 2015 5:28 PM
  • Hi Doctor-Who,

    >>” So the question is, did I inadvertently choose a name for the class that is the same name used for the connection string? Or is this something that EF did on it's own?”

    Here is WPF forum, it provide support for WPF. I consider that this issue was related to EF. Then I suggest that you could post a new thread in EF forum. Thank you for your understanding.

    This is the link of EF forum: https://social.msdn.microsoft.com/Forums/en-US/home?forum=adodotnetentityframework

    Best Regards,
    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, May 5, 2015 9:35 AM