1 Attachment(s)
[2005] Where is my problem
Greetings,
When I try to run this code i get most time a exception in the part
Catch exc As Exception
It is a IOException
The Process can not access the file D:\views\pledlm_view\applications\ktr\source\KTR Client\KTR Client\bin\Release\KTR Client.exe.config because another process is using it.
Background:
1. The app = not MutliThreating
2. I use the routine to add a new value in to the App.config
For easier understanding i posted the whole class as zip to the thread
VB Code:
Private Function LoadConfigSource() As String
Dim dllPath As String = System.Reflection.Assembly.GetExecutingAssembly.Location
Dim filename As String
#If DEBUG Then
'--> if debug app.config file is not in bin folder
Dim strTemp As String = Path.GetDirectoryName(dllPath)
strTemp = strTemp.Substring(1, strTemp.Length - 1)
strTemp = strTemp.Substring(1, strTemp.LastIndexOf("\bin\"))
filename = strTemp & "app.config"
#Else
'--> get the name of the calling assembly (in the testcase TestConfigProvider) and built the path of the config file in release mode
filename = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) & "\" & System.Reflection.Assembly.GetEntryAssembly.GetName.Name.ToString & ".exe.config"
#End If
configSource = New XmlDocument
Dim cstream As Stream
Try
cstream = File.OpenRead(filename)
configSource.Load(cstream)
Catch ex As FileNotFoundException
Throw ex
Catch exc As Exception
Throw exc
Finally
If Not cstream Is Nothing Then cstream.Close()
End Try
Return filename
End Function
Thanks for any help
Re: [2005] Where is my problem
You shouldn't be opening the config file durectly anyway. Access it via the System.Configuration namespace. Look at the ConfigurationManager.OpenExeConfiguration method.
Re: [2005] Where is my problem
@jmcilhinney:
ok I am using now (which is match more easier ;) could remove the whol.e class)the following line to get a value from the appsettings
Code:
cstMonthView.BColor1 = ConfigurationManager.AppSettings.Get("ABC")
but and sorry jmcilhinney when i do the following line of code
Code:
ConfigurationManager.AppSettings.Set("ABC", "Red")
the value is only temporary availible.
After starting the app again the Value "Red" is not in the app.config
So it seams to me the value are never writen to the key in the app.config
For simplicity i replaced here the org code with dummy Values and keys.
The original Lines would be for get
Code:
Color.FromName(ConfigurationManager.AppSettings.Get(My.Resources.KonfigKalenderBackColor1))
and for set
Code:
cstMonthView.BColor1 = Color.FromName(ConfigurationManager.AppSettings.Get(My.Resources.KonfigKalenderBackColor1))