davidwhitney / system.configuration.abstractions Goto Github PK
View Code? Open in Web Editor NEWInjectable, mockable, extensible, configuration for .NET
License: MIT License
Injectable, mockable, extensible, configuration for .NET
License: MIT License
I'm using custom converters to translate string values to an enum. I've noticed that every now and then I get the exception mentioned in the issue title. Most of the time, the code works just fine, and I'm wondering if it has to do with too many simultaneous requests.
I'm using v2.0.2.26.
Here's the stack trace when the exception happens in an ashx implementing IHttpHandler:
Stack Trace:
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Collections.Generic.List`1.set_Capacity(Int32 value)
at System.Collections.Generic.List`1.EnsureCapacity(Int32 min)
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at System.Configuration.Abstractions.ConfigurationManager.RegisterTypeConverters(IConvertType[] converters) in c:\projects\system-configuration-abstractions\System.Configuration.Abstractions\ConfigurationManager.cs:line 38
at project.name.Callback.ProcessRequest(HttpContext context) in C:\Users\username\Documents\working\library.name\project.name\Callback.ashx.cs:line 32
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
the usage in the ashx is:
public void ProcessRequest(HttpContext context)
{
var wdsLogging= new Logging(13);
var form = HttpContext.Current.Request.Form;
var ourPlatformEnumConverter = new OurPlatformEnumConverter();
var vendorPlatformEnumConverter = new vendorPlatformEnumConverter();
ConfigurationManager.RegisterTypeConverters(ourPlatformEnumConverter, vendorPlatformEnumConverter );
and I've also had it happen every now and then in a webform page as well.
Do you have any thoughts on what might be causing it or how to fix it?
Hello, I'm using custom converters to map from a string value in the config to an enum. For the most part, everything has been working great, but I noticed via logs that every once in a while, I'd get an InvalidCastException
. This is in a *.ashx web handler acting as a web service (old code base), so I'd hit it once, it'd throw the exception, I'd hit it again right away without changes, and it'd work perfectly.
I've narrowed this down: the first time I deploy the webservice and hit it, the JITer has to spin everything up, and I get a delay and then a InvalidCastException
on my enum. If I immediately send another request via Postman, it works perfectly and immediately. I've hammered the webservice and the only time it fails is the first time after a deploy.
Is there some kind of timeout used by the library or you can you think of any reasons / fixes for this behavior? In case it's relevant, code snippets follow. Thank you.
public enum OurPlatforms
{
Dev,
Production
}
public class OurPlatformEnumConverter : IConvertType
{
public object Convert(string configurationValue)
{
if (configurationValue == OurPlatforms.Dev.ToString())
{
return OurPlatforms.Dev;
}
else if (configurationValue == OurPlatforms.Production.ToString())
{
return OurPlatforms.Production;
}
}
public Type TargetType => typeof(OurPlatforms);
I'm using them in a config factory, which gets wired up like this in the factory constructor:
public ProcessorConfigFactory()
{
var ourPlatformEnumConverter = new OurPlatformEnumConverter();
ConfigurationManager.RegisterTypeConverters(ourPlatformEnumConverter);
}
and then it reads out the config value that should map out to an enum when a Get method is called:
private OurPlatforms GetOurPlatform(IConfigurationManager manager)
{
return manager.AppSettings.AppSettingConvert<OurPlatforms>("SomeNamespace.OurPlatform");
}
Hmm, I'm trying to use this in a service project being deployed to many computers and I'm unable to get it running anywhere but my machine. This is the exception I'm getting out in the wild:
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Configuration.ConfigurationErrorsException
Stack:
at System.Configuration.Abstractions.AppSettingsExtended.AppSetting[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.String, System.Func`1<System.__Canon>)
at Automator.Program.Main()
Any ideas?
Hello devs,
This is really a request and not an issue. I am trying to use your library for our organization but there is no LICENSE file present under the GitHub repo. I know your library is covered by MIT license and per their template https://opensource.org/licenses/MIT you may create a license file by filling out the specific info. May I please request you to create one so that we could use your wonderful library within our application legally?
In case the license file already exists somewhere, would you please provide me with its location?
Thank you,
Faisal
InnerException {"Could not load file or assembly 'System.Configuration.Abstractions.NetStandard, Version=2.0.2.45, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.":"System.Configuration.Abstractions.NetStandard, Version=2.0.2.45, Culture=neutral, PublicKeyToken=null"} System.Exception {System.IO.FileNotFoundException}
Tried adding
It doesn't work
Why is the PublicKeyToken null?
I use IConfigurationManager to mock configuration, but I found no easy way to mock values stored in configuration sections.
For example, I want to change session timeout during test.
I get session timeout from web.config in following way:
SessionStateSection section = (SessionStateSection)_configurationManager.GetSection("system.web/sessionState");
sessionTimeout = TimeSpan.FromMinutes((int)section.Timeout.TotalMinutes);
where _configurationManager is instance of IConfigurationManager.
How can I set values for "system.web/sessionState" section using System.Configuration.Abstractions?
The following doesn't work:
ConfigurationManager.Instance.AppSettings.AppSetting<Guid>("someGuidVal", () => null)
Just can't parse it. What's the option here? I can't tell from your documentation ..
When using a mix of the .NET System.Configuration.ConfigurationManager
and System.Configuration.Abstractions.ConfigurationManager
to retrieve and update appSettings, the returned results aren't consistent.
Here are the full steps to reproduce the problem:
Setup an App.config that contains:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="something" value="A" />
</appSettings>
</configuration>
Create a System.Configuration.Abstractions.ConfigurationManager
instance and load the app setting:
IConfigurationManager config = new ConfigurationManager();
var firstValue = config.AppSettings["something"]; // This returns "A"
Now use a .NET System.Configuration.ConfigurationManager
to update the value.
var testConfig = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
testConfig.AppSettings.Settings["something"].Value = "B";
testConfig.Save();
Then try to refresh the section and retrieve the update value using the System.Configuration.Abstractions.ConfigurationManager
.
config.RefreshSection("appSettings");
var secondValue = config.AppSettings["something"]; // This returns "A" but _should_ return "B".
The above code should have returned the updated value "B" but returns the original value "A".
I've run the above scenario and confirmed the value in App.config file does get updated but I suspect the System.Configuration.Abstractions.ConfigurationManager
is using a memory backed cache of app settings.
I'm not sure of the correct solution to this bug other than possible not mixing usage of System.Configuration.Abstractions.ConfigurationManager
and the .NET System.Configuration.ConfigurationManager
Dave,
I find myself converting Uri entries in the config from strings to 'new Uri(string)' so hoping to perform this naturally within the 'System.Configuration.Abstractions.AppSetting()' method with a simple;
if (typeof(T) == typeof(Uri))
return (T) (object) (new Uri(rawSetting));
Rather than going down the path of supplying a list of Custom Converters, etc., what are you views?
Cheers,
Billy
I've successfully used the library in other projects and have now begun a new API project in .Net Core 2.x targeting the framework 4.6.1 where I'm reusing some of the previous functionality.
Note that I'm not very familiar with .net core yet so it could be that I'm doing something silly. I'm getting a "Calling code requested setting named 'Vendor.OurPlatform' but it was not in the config file" exception. I'm using v2.0.2.45 of Abstractions.
My appsettings.json:
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {},
"Vendor.OurPlatform": "AzureDev",
"Vendor.VendorPlatform": "Demo"
}
and it validates as proper json.
I have the following function:
private OurPlatforms GetOurPlatform(IConfigurationManager manager)
{
return manager.AppSettings.AppSettingConvert<OurPlatforms>("Vendor.OurPlatform");
}
As far as I can tell, the keys match (because I pasted them straight out of the web config of a project where this all works) and they're on the proper level in the json object.
Am I missing something obvious? I've tried about every combination of things I can think of with variations on the json structure, putting it in other files, and even reading up on ConfigurationManager. This issue here (Azure/azure-functions-core-tools#33) seems to suggest that .net's ConfigurationManager
can indeed read the appsettings.json file...
Though Core has its own configuration stuff, I'd prefer to keep using System.Configuration.Abstractions for this project due to a shared library...
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.