-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue and Proposed Fix for : the type initializer for 'AuthorizeNet.Util.HttpUtility' error #292
Comments
This fix has been incorporated, along with a more standard mutex lock, in v2.0.3. @schandan-ssactivewear : Kindly validate the fix and close this issue if you are satisfied. |
Thanks so much @gnongsie . |
@gnongsie I am facing same issue , I am using AuthorizeNet version 2.0.3 The type initializer for 'AuthorizeNet.Util.HttpUtility' threw an exception. |
we haven't seen this problem since last 3 months after we started using AuthorizeNet version 2.0.3. |
Inner exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. Stack trace : at AuthorizeNet.Util.HttpUtility.GetPostUrl(Environment env) |
I am not able to see that In class HttpUtility , GetPostUrl method at below line throwing error |
This seems a different issue- Does it break during the first time load ? or It loads fine the first time and breaks after few transactions goes thru ? |
I am not able to do single transaction due to this error , I am using NuGet package AuthorizeNet version 2.0.3 |
Ok , then it is a different issue . |
We can eliminate this issue by installing System.Net.Http.Formatting.Extension package from the NuGet package manager. I hope it solves the issue. |
Sorry, it didn’t work. Maybe the cause of your error wasn’t due to thread conflict from multiple instances initializing at the same time. |
I am seeing the same issue with version 2.0.3 .NET 7.0 The type initializer for 'AuthorizeNet.Util.HttpUtility' threw an exception. Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. at AuthorizeNet.Environment.GetProperty(String propertyName) |
Hi Team,
We are one of the heavy users of this framework for our retail application .
We see this below issue intermittently 3 or 4 times a month which blocks the users from checking out . The only way to fix it is restarting the app pool. Until the app pool is restarted out checkout screen breaks
Analysis :
To replicate the issue in lower environment we started hitting the service from our app while the app is getting recycled or redeployed. (in sandbox)
The HTTPUtility is the entry point class for any API calls that goes to Authorize and it has this Static Properties which invokes the AuthorizeNet.Envvironment.getBooleanProperty()
The issue seems to be coming from this class AuthorizeNet. Environment.GetProperty() (https://github.com/AuthorizeNet/sdk-dotnet/blob/master/Authorize.NET/Environment.cs)
When the app is getting recycled or deployed , the ConfigurationManager.AppSettings native object is in the process of getting populated with appsettings propery from Web.config file ,
Since it is a NameValue collection , (which is not ThreadSafe )if any other process tried to read the ConfigurationManager.AppSettings.AllKeys , the below exception is thrown .
And the Problem with Static attributes is that if gets corrupted due to an error , the only way to fix that is by getting app pool restarted
Proposed Fix:
Please let us know if there is a way to get around this issue . If not this is what we tried and it seems if you make this change in the Environment.cs File it might work
We tested by bombarding requests the below snippet of code when the app is getting recycled , an error gets thrown when the “ConfigurationManager.AppSettings.AllKeys” gets invoked.
Microsoft documentation says it’s a NamedValue collection by design (which is not thread safe). Hence when other process is trying to access it when it is written it throws an error
We tried this snippet and bombarded with similar load and it seems to do the trick as it doesn’t access AllKeys variable and right after we added the snippet that is similar to Environment.CS file and it fails
Conclusion :
Changing the way ConfigurationManager.AppSettings is read might fix the issue (By not accessing AllKeys)
Or Please let us know if there is a different way to handle this issue
The text was updated successfully, but these errors were encountered: