Is it possible in vb.net/C# to change where the application.exe.config
file is located?
This is not a duplicate of this question, as you can see in my code I tried this method already, it didn't work for me.
The thing I want to achieve with this is to make this path dynamically.
Public Class Form1
Public Sub New()
Try
'Two Methods to change the path of the application.exe.config file i tried, both dont work
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", "C:\Temp\AppConfig.exe.config")
Dim config As Configuration = ConfigurationManager.OpenExeConfiguration("C:\Temp\AppConfig.exe.config")
InitializeComponent()
'EntityFramework ---------------------------
Dim db = New WfpModel 'DbContext --> MyBase.New("name=ConnectionMSSQL")
gridWFP.DataSource = db.ADR.ToList()
gridWFP.Refresh()
'WebService ---------------------------
Dim Client = New Netlogistik.ServiceClient
Dim filter = New TRANSPORT_FILTER With {.ID = 0}
gridNet.DataSource = Client.WfpNetTransport("myUserName", "myPassword", filter.GetTransportFilter)?.Tables("OUT")
gridNet.Refresh()
Catch ex As Exception
'EntityFramework Result: System.InvalidOperationException:
' "No connection string named ConnectionMSSQL was found in the application configuration file."
'
'WebService Result: No default endpoint element was found that references the Netlogistic.IService
' contract in the ServiceModel client configuration section.
' This could be due to the following reasons: No configuration file was found for the application,
' Or no endpoint element matching the contract was found in the client element.
MsgBox(ex.Message)
End Try
End Sub...
You can't change the app config file location since the behavior is managed by the .NET Framework internally.
But you can create your own configuration file and manage parameters with a hand-made singleton class that can be serialized in xml or binary format where you want to put it.
Example:
The test:
It needs to add
System.Runtime.Serialization
assembly reference in the project file.