locked
wpf_development RRS feed

  • Question

  • Hello,

    Trying to develop a wpf application in vs2008.. Failed to fetch the connectionstring defined in app.config , throwing a null exception .

    app.config ->::<connectionstring> <add name="con" connectionstring="xxx..."</connec..string>

    in code ::-> string con = ConfigurationManager.ConnectionStrings["con"].Tostring();

    Null exception at connectionstring !!!

    {Used System.configuration + add reference }{ samething when applied in console/winform application -- no problem))

    Is there any limitation in Wpf in VisualStudio2008 !!

    Thanks in advance

    Ab1-1

    Thursday, December 4, 2014 6:40 AM

Answers

  • I am not sure can anybody help in this topic ?

    If you just add a config file to a project then by default it rather unhelpfully calls it app1.config.

    You have to rename it app.config or take extraordinary measures to cope with it.


    Hope that helps
    Please don't forget to upvote posts which you like and mark those which answer your question.

    • Marked as answer by ab1-1 Wednesday, December 10, 2014 5:50 AM
    Tuesday, December 9, 2014 3:13 PM

All replies

  • Hi Ab1-1,

    There is no such limitations in WPF or any other technology, there might some other problem like name of the connection string key.

    Please share the same code or reproduce it in a sample.


    Thanks & Regards
    Syed Amjad Sr. Silverlight/WPF Developer,
    yahoo : syedamjad6736@yahoo.com, skype : syedamjad.0786.
    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    Thursday, December 4, 2014 9:30 AM
  • Thanks .. I got it but not very sure . I just changed my app1.config to app.config and it worked .

    Can you please explain it !! I added a config file named 'app1.config' default --- Problem Here as value comes from 'app.config' why !!!

    Friday, December 5, 2014 6:24 AM
  • I am not sure can anybody help in this topic ?
    Tuesday, December 9, 2014 1:54 PM
  • You cannot change the name of your configuration file to anything else than "app.config" if you want to be able to use the ConfigurationManager class to access its contents. You can use some tricks to be able to use a file that is called something else but it is not worth the hassle: http://stackoverflow.com/questions/439538/changing-the-net-application-configuration-file-name

    A configuration file for a WPF application should always be named "app.config" and nothing else. It is a simple as that.

    Please remember to mark helpful posts as answer and/or helpful.

    Tuesday, December 9, 2014 2:13 PM
  • I am not sure can anybody help in this topic ?

    If you just add a config file to a project then by default it rather unhelpfully calls it app1.config.

    You have to rename it app.config or take extraordinary measures to cope with it.


    Hope that helps
    Please don't forget to upvote posts which you like and mark those which answer your question.

    • Marked as answer by ab1-1 Wednesday, December 10, 2014 5:50 AM
    Tuesday, December 9, 2014 3:13 PM