exe console app calling into web app's dll, all ok until ConfigManager.AppSettings()

Last post 07-10-2009 7:17 AM by motten. 2 replies.

Sort Posts:

  • exe console app calling into web app's dll, all ok until ConfigManager.AppSettings()

    07-09-2009, 10:22 PM
    • Member
      1 point Member
    • motten
    • Member since 07-09-2009, 10:01 PM
    • Posts 2

     I'm writing a small console app to support some background functionality in a 2.0 web app.  I need to call some of the web code from the console app so I tired just adding a reference to the web's dll in the console app, not thinking it would work.  Although all of the dll's for the web app got copied over to my console app's bin directory (understandable), I'm able to call quite a few utility routines successfully, even if I copy (just) the exe into the web server's bin directory. 

    There are only a few more routines in the web app that I need access to but they all use ConfigurationManager.AppSettings to read properties out of web.config, and these values are clearly not there when I call from the exe.  It wouldn't take much for me to write my own web.config reader .... but I have a fairly nagging feeling I've lit a fuse here that is just waiting to take a turn for the worst.

    Can anyone support or complain about this approach?  Or suggest any alternative(s) to accessing web code from an executable.

    Thanks for any feedback-

    PS- I am not accessing any of the web's gui layer or even the code-behind pages, just logic, utility, and database tier (although they are all compiled into a single dll).

  • Re: exe console app calling into web app's dll, all ok until ConfigManager.AppSettings()

    07-10-2009, 12:37 AM
    Answer
    • Contributor
      7,216 point Contributor
    • integrasol
    • Member since 06-05-2009, 11:18 AM
    • Posts 1,379

    A general note first: If you have code in a Web app that could be shared with another app, whether console or not, you should really add this code to a class or even better a component (Class Library) which makes sharing much easier.

    The reason that the ConfigurationManager.AppSettings doesn't work is because it is trying to read the configuration file for the console app; that is the configuration file for the application's host, http://msdn.microsoft.com/en-us/library/ms229689.aspx.

    Thanks

    Carsten

    Please mark this post as Answer if it is of help to you. :-)
  • Re: exe console app calling into web app's dll, all ok until ConfigManager.AppSettings()

    07-10-2009, 7:17 AM
    • Member
      1 point Member
    • motten
    • Member since 07-09-2009, 10:01 PM
    • Posts 2

    That's just golden Carsten!  I copied web.config into the console app's directory and renamed it to myapp.exe.config and everybody is so happy! ;)

    I also use classes in the data tier although a good portion of the methods are static/shared.

    Thanks for the great help-

    Mike

Page 1 of 1 (3 items)