By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,246 Members | 1,515 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,246 IT Pros & Developers. It's quick & easy.

Shared app.config

P: n/a
This situation requres many exes to be sitting on a network share. I would
like all of these to use the same app.config file, which will be stored in
the same location on the network. A quick test though gave me this
exception:

System.InvalidOperationException: The key 'ConnectionString' does not exist
in the appSettings configuration section.
at System.Configuration.AppSettingsReader.GetValue(St ring key, Type type)
at test_appconfig.Form1.FromApplicationConfig(String Key) in
F:\VB.NET\junk\test_appconfig\test_appconfig\Form1 .vb:line 62
The program '[2808] test_appconfig.exe' has exited with code 0 (0x0).

What's the best way to share the app.config in this common network folder?
Thanks, Eric
Public Function FromApplicationConfig(ByVal Key As String) As String
Try
Dim reader As New AppSettingsReader
Return CStr(reader.GetValue(Key, GetType(String)))
Catch ex As Exception
MessageBox.Show(ex.Message.ToString & vbCrLf & _
ex.Source.ToString & vbCrLf & _
ex.StackTrace.ToString, "Function: FromApplicationConfig Exception",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Function
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Assign them the same appDomain. I "believe" thats what is used to read the
app.config file... I could be wrong on that. But tests that I've done show
it.

-CJ

"Eric Sabine" <mopar41@____h_o_t_m_a_i_l_._ScPoAmM> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
This situation requres many exes to be sitting on a network share. I would like all of these to use the same app.config file, which will be stored in
the same location on the network. A quick test though gave me this
exception:

System.InvalidOperationException: The key 'ConnectionString' does not exist in the appSettings configuration section.
at System.Configuration.AppSettingsReader.GetValue(St ring key, Type type)
at test_appconfig.Form1.FromApplicationConfig(String Key) in
F:\VB.NET\junk\test_appconfig\test_appconfig\Form1 .vb:line 62
The program '[2808] test_appconfig.exe' has exited with code 0 (0x0).

What's the best way to share the app.config in this common network folder?
Thanks, Eric
Public Function FromApplicationConfig(ByVal Key As String) As String
Try
Dim reader As New AppSettingsReader
Return CStr(reader.GetValue(Key, GetType(String)))
Catch ex As Exception
MessageBox.Show(ex.Message.ToString & vbCrLf & _
ex.Source.ToString & vbCrLf & _
ex.StackTrace.ToString, "Function: FromApplicationConfig Exception",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Function

Nov 20 '05 #2

P: n/a
Thanks CJ, so then I would be creating a new appdomain in my sub main? In
what way though do I instruct each exe to share this appdomain? Are the
parameters for itself somehow loaded from some additional universal file.
This is new territory for me.

Could you share and representative code please?

Eric
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.com...
Assign them the same appDomain. I "believe" thats what is used to read the app.config file... I could be wrong on that. But tests that I've done show it.

-CJ

"Eric Sabine" <mopar41@____h_o_t_m_a_i_l_._ScPoAmM> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
This situation requres many exes to be sitting on a network share. I

would
like all of these to use the same app.config file, which will be stored in the same location on the network. A quick test though gave me this
exception:

System.InvalidOperationException: The key 'ConnectionString' does not

exist
in the appSettings configuration section.
at System.Configuration.AppSettingsReader.GetValue(St ring key, Type type) at test_appconfig.Form1.FromApplicationConfig(String Key) in
F:\VB.NET\junk\test_appconfig\test_appconfig\Form1 .vb:line 62
The program '[2808] test_appconfig.exe' has exited with code 0 (0x0).

What's the best way to share the app.config in this common network folder? Thanks, Eric
Public Function FromApplicationConfig(ByVal Key As String) As String
Try
Dim reader As New AppSettingsReader
Return CStr(reader.GetValue(Key, GetType(String)))
Catch ex As Exception
MessageBox.Show(ex.Message.ToString & vbCrLf & _
ex.Source.ToString & vbCrLf & _
ex.StackTrace.ToString, "Function: FromApplicationConfig Exception",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Function


Nov 20 '05 #3

P: n/a
Your sub main creates an appdomain nonetheless on a current thread with the
same name as the executable.

So it looks like you can create a new Domain... and run
AppDomain.ExecuteAssembly() and get the desired results. I have never
actually done this, I'm just looking at things and think it can do it..

But hey, not a lot of code to test out..

Lookup AppDomain.ExecuteAssembly in your help file it gives an example.

-CJ

"Eric Sabine" <mopar41@____h_o_t_m_a_i_l_._ScPoAmM> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Thanks CJ, so then I would be creating a new appdomain in my sub main? In
what way though do I instruct each exe to share this appdomain? Are the
parameters for itself somehow loaded from some additional universal file.
This is new territory for me.

Could you share and representative code please?

Eric
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.com...
Assign them the same appDomain. I "believe" thats what is used to read the
app.config file... I could be wrong on that. But tests that I've done

show
it.

-CJ

"Eric Sabine" <mopar41@____h_o_t_m_a_i_l_._ScPoAmM> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
This situation requres many exes to be sitting on a network share. I

would
like all of these to use the same app.config file, which will be
stored in the same location on the network. A quick test though gave me this
exception:

System.InvalidOperationException: The key 'ConnectionString' does not

exist
in the appSettings configuration section.
at System.Configuration.AppSettingsReader.GetValue(St ring key, Type type) at test_appconfig.Form1.FromApplicationConfig(String Key) in
F:\VB.NET\junk\test_appconfig\test_appconfig\Form1 .vb:line 62
The program '[2808] test_appconfig.exe' has exited with code 0 (0x0).

What's the best way to share the app.config in this common network folder? Thanks, Eric
Public Function FromApplicationConfig(ByVal Key As String) As String
Try
Dim reader As New AppSettingsReader
Return CStr(reader.GetValue(Key, GetType(String)))
Catch ex As Exception
MessageBox.Show(ex.Message.ToString & vbCrLf & _
ex.Source.ToString & vbCrLf & _
ex.StackTrace.ToString, "Function: FromApplicationConfig Exception",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Function



Nov 20 '05 #4

P: n/a
The application configuration file must reside in the application directory
and must be named the same as the exe file, with a .config extension. For
example, if your application exe is "test.exe" the config file will be
"test.exe.config". The simplest way to solve your problem is to dynamically
copy the app.config master copy to the application directory for each
application, renaming it appropriately when the application starts. For
example, this code will work. Note that it only works as written in
*release* mode, not in debug mode. However, you can probably add an ifdef
and change the pathname for the copied file to make it work in either--I
didn't test that.

Also note that, as written, there's a hard-coded path to the master
app.config file in the code, which is generally a bad idea. You'd be better
off retreiving the master pathname from the Registry, from some text file,
passing it in as a startup parameter, or getting it from a database

Put this code in your startup form load or in the module containing Sub
Main, changing the master-location path and "someKey" appropriately.
Imports System.IO
Imports System.Reflection
' at startup in *RELEASE* mode
' get the location of this executable
Dim appLocation As String = [Assembly].GetExecutingAssembly.Location
File.Copy("master-location\app.config", appLocation & ".config", True)
' read the config file (proof that it works)
'
Debug.WriteLine(System.Configuration.Configuration Settings.AppSettings.Get("
someKey"))

"Eric Sabine" <mopar41@____h_o_t_m_a_i_l_._ScPoAmM> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
This situation requres many exes to be sitting on a network share. I would like all of these to use the same app.config file, which will be stored in
the same location on the network. A quick test though gave me this
exception:

System.InvalidOperationException: The key 'ConnectionString' does not exist in the appSettings configuration section.
at System.Configuration.AppSettingsReader.GetValue(St ring key, Type type)
at test_appconfig.Form1.FromApplicationConfig(String Key) in
F:\VB.NET\junk\test_appconfig\test_appconfig\Form1 .vb:line 62
The program '[2808] test_appconfig.exe' has exited with code 0 (0x0).

What's the best way to share the app.config in this common network folder?
Thanks, Eric
Public Function FromApplicationConfig(ByVal Key As String) As String
Try
Dim reader As New AppSettingsReader
Return CStr(reader.GetValue(Key, GetType(String)))
Catch ex As Exception
MessageBox.Show(ex.Message.ToString & vbCrLf & _
ex.Source.ToString & vbCrLf & _
ex.StackTrace.ToString, "Function: FromApplicationConfig Exception",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Function

Nov 20 '05 #5

P: n/a
Eric,

You can put the settings in the machine.config file.
Its located in the CONFIG directory of the runtime install path
(System.Web.Hosting.SimpleWorkerRequest.MachineCon figPath Property will
return the path)
machine.config already contains an <appSettings> although it is commented
out
AppSettingsReader first checks this file before checking the applications
configuration file

Stephen

"Eric Sabine" <mopar41@____h_o_t_m_a_i_l_._ScPoAmM> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
This situation requres many exes to be sitting on a network share. I would like all of these to use the same app.config file, which will be stored in
the same location on the network. A quick test though gave me this
exception:

System.InvalidOperationException: The key 'ConnectionString' does not exist in the appSettings configuration section.
at System.Configuration.AppSettingsReader.GetValue(St ring key, Type type)
at test_appconfig.Form1.FromApplicationConfig(String Key) in
F:\VB.NET\junk\test_appconfig\test_appconfig\Form1 .vb:line 62
The program '[2808] test_appconfig.exe' has exited with code 0 (0x0).

What's the best way to share the app.config in this common network folder?
Thanks, Eric
Public Function FromApplicationConfig(ByVal Key As String) As String
Try
Dim reader As New AppSettingsReader
Return CStr(reader.GetValue(Key, GetType(String)))
Catch ex As Exception
MessageBox.Show(ex.Message.ToString & vbCrLf & _
ex.Source.ToString & vbCrLf & _
ex.StackTrace.ToString, "Function: FromApplicationConfig Exception",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Function

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.