We are working on an upgrade project from 10.2.400 to Kinetic 2022.2. Some of our existing method directives use custom code to read configuration values from the appSettings section of the web.config file on the Epicor app server. This is convenient for us because it makes it easy to backup & restore from another environment while keeping those appSettings values specific to the local environment.
To read these values, we were using the
System.Configuration.ConfigurationManager class. The code used would be something like:
string uncPath = System.Configuration.ConfigurationManager.AppSettings["UncPath"].ToString();
When we do this in Kinetic 2022.2, we get the following error:
The type name ‘ConfigurationManager’ could not be found in the namespace ‘System.Configuration’. This type has been forwarded to assembly ‘System.Configuration.ConfigurationManager’, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’ Consider adding a reference to that assembly.
We found a System.Configuration.ConfigurationManager.dll library in the Server\Assemblies folder on the server. It has that same PublicKeyToken. However, if we add that library to our BPM by clicking Usings & References… then Assemblies folder then add the library, we get a new error:
The type forwarder for type ‘System.Configuration.ConfigurationManager’ in assembly ‘System.Configuration.ConfigurationManager’ causes a cycle.
We found this epiusers post which indicates much of what was in the web.config file moved to the host.config file.
Everything we’re reading about Configuration in .NET from Microsoft points to using appsettings.json instead of the traditional .config files. In our Kinetic enviornment, there are appsettings.json and appsettings.Development.json files in the Server\Bin folder.
However, we can’t read from those files via the recommended
ConfigurationBuilder class in the Microsoft.Extensions.Configuration namespace because not all of the required libraries are present in the Server\Assemblies folder on the app server. One of the required libraries that is present is the Microsoft.Extensions.Configuration.Abstractions.dll library, which is version 2.1.1. If we retrieve the other required libraries from NuGet that match that 2.1.1 version (specifically Microsoft.Extensions.Configuration.dll version 2.1.1 and Microsoft.Extensions.Configuration.Json.dll version 2.1.1) and place them in the Server\Customization\Externals folder, then we are able to add references to all three of those libraries in our method directive and use the following code and it works:
IConfiguration config = new ConfigurationBuilder().AddJsonFile("C:\\Epicor\\Websites\\KineticDev2022\\Server\\Bin\\appsettings.json").Build(); string uncPath = config["UNCPath"];
So our question is, what approach are others using for these types of environment specific configuration values in Kinetic?