Enterprise Pattern and Practise: configure Sql Azure transient fault Configuration - c#

I am trying to implement SQL Azure Transient Fault Configuration in my ASP.NET application. I am trying to following: http://msdn.microsoft.com/en-us/library/hh680899(v=pandp.50).aspx
Though I didn't find the block on how can I configure this in config file. I am getting The type RetryManager does not have an accessible constructor. error in my code. I read in some forum that I should configure it using config file, but how is my question. Thanks.
EDIT: I am using Enterprise Lib 5.0

Here's a sample configuration:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="RetryPolicyConfiguration" type="Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration.RetryPolicyConfigurationSettings, Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling, Version=5.1.1209.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section name="typeRegistrationProvidersConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.TypeRegistrationProvidersConfigurationSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<RetryPolicyConfiguration defaultRetryStrategy="Incremental Retry Strategy" defaultSqlConnectionRetryStrategy="Backoff Retry Strategy" defaultSqlCommandRetryStrategy="Incremental Retry Strategy" defaultAzureStorageRetryStrategy="Incremental Retry Strategy" defaultAzureServiceBusRetryStrategy="Fixed Interval Retry Strategy">
<incremental name="Incremental Retry Strategy" retryIncrement="00:00:05" maxRetryCount="5" />
<fixedInterval name="Fixed Interval Retry Strategy" retryInterval="00:00:01" maxRetryCount="10" />
<exponentialBackoff name="Backoff Retry Strategy" minBackoff="00:00:01" maxBackoff="00:00:30" deltaBackoff="00:00:10" maxRetryCount="10" />
</RetryPolicyConfiguration>
<typeRegistrationProvidersConfiguration>
<clear />
<add name="Caching" sectionName="cachingConfiguration" />
<add name="Cryptography" sectionName="securityCryptographyConfiguration" />
<add name="Exception Handling" sectionName="exceptionHandling" />
<add name="Instrumentation" sectionName="instrumentationConfiguration" />
<add name="Logging" sectionName="loggingConfiguration" />
<add name="Policy Injection" sectionName="policyInjection" />
<add name="Security" sectionName="securityConfiguration" />
<add name="Data Access" providerType="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings, Microsoft.Practices.EnterpriseLibrary.Data" />
<add name="Validation" providerType="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationTypeRegistrationProvider, Microsoft.Practices.EnterpriseLibrary.Validation" />
<add sectionName="RetryPolicyConfiguration" name="RetryPolicyConfiguration" />
</typeRegistrationProvidersConfiguration>
<appSettings>
</appSettings>
</configuration>

Related

dll.config not found asp.net

I'm developing asp.net application that uses a 3rd party API, and one of the API use a config file (dll.config).
I access the function in the API using class (.cs) file. When I try to run it, it throws a file not exception and the API won't start.
I tried to run exact same code in the WPF approach, the code works fine.
After review and searching, I tried to use configuration manager yet it does not solve my problem.
Here I attach what I've tried.
public void config3()
{
string path = "E:\\LiveStreaming\\testLiveStreaming\\testLiveStreaming\\bin\\Bosch.Dcn.Ecpc.Client.Logic.dll.config";
System.Diagnostics.Debug.WriteLine("path " + path);
try
{
RemotingConfiguration.Configure(path, false);
}
catch (Exception et)
{
System.Diagnostics.Debug.WriteLine("error conf " + et.Message);
}
}
The thrown error from debug console.
DebugCategory Information: 3 : An error occurred in DCN-SW API
initializing the server link: .Config file
'Bosch.Dcn.Ecpc.Client.Logic.dll.config' cannot be read successfully
due to exception 'System.IO.FileNotFoundException: The system cannot
find the file specified. (Exception from HRESULT: 0x80070002) at
System.BaseConfigHandler.RunParser(String fileName) at
System.ConfigTreeParser.Parse(String fileName, String configPath,
Boolean skipSecurityStuff) at
System.Runtime.Remoting.Activation.RemotingXmlConfigFileParser.ParseConfigFile(String
filename) at
System.Runtime.Remoting.RemotingConfigHandler.LoadConfigurationFromXmlFile(String
filename)'. DebugCategory Information: 4 : Availability state of the
DCN-SW API changed from b to a.
here is my web.config file
<configuration>
<configSections>
<sectionGroup name="applicationSettings">
<section name="Bosch.Dcn.Ecpc.Client.Logic.dll" type="Bosch.Dcn.Ecpc.Client.Logic,Bosch.Dcn.Ecpc.Client.Logic, Version=4.43.4.0, Culture=neutral, PublicKeyToken=99e028c462dbcff9" allowLocation="true" allowDefinition="Everywhere"/>
</sectionGroup>
</configSections>
<applicationSettings >
<Bosch.Dcn.Ecpc.Client.Logic.dll>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="0" username="">
<clientProviders>
<formatter ref="binary"/>
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"/>
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
</Bosch.Dcn.Ecpc.Client.Logic.dll>
</applicationSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer></configuration>

cant read custom section from web config

Why can't I read this from my web config? When I used App.config it worked fine..
FundGroups = null
private static readonly NameValueCollection FundGroups =
(NameValueCollection)ConfigurationManager.GetSection("FundGroups");
Web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="FundGroups" type="System.Configuration.NameValueSectionHandler" />
</configSections>
<FundGroups>
<add key="Group1" value="Value1" />
<add key="Group2" value="Value2" />
<add key="Group3" value="Value3" />
<add key="Group4" value="Value4" />
<add key="Group5" value="Value5" />
<add key="Group6" value="Value6" />
<add key="Group7" value="Value7" />
</FundGroups>
</configuration>
I found a possible duplication here. But the ConfigurationSettings.GetConfig seems to be obsolete and doesnt work for me

App.config can't find my element

I have a simple app.config file that doesn't quite pass the IDEs checker.
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="XmlRoot" type="System.String"/>
</configSections>
<connectionStrings>
<omitted/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<XmlRoot>
<add key="relativepath" value=""/>
</XmlRoot>
</configuration>
I added the <section name="XmlRoot" type="System.String" /> part to the config and then I tried to define the name and key here: <add key="relativepath" value=""/>. But for some reason the IDE gives me the following Messages:
I rarely use the app.config file so it could just be a noob mistake. How do I make it recognize my tags?
If it's just a simple string, you can use AppSettings to accomplish this.
<configuration>
<appSettings>
<add key="relativepath" value="mypath" />
</appSettings>
</configuration>
Access it from C# like this:
string path = ConfigurationManager.AppSettings["relativepath"]);
Try changing your type to System.Configuration.NameValueSectionHandler
this is how I define my sections:
<configSections>
<sectionGroup name="MySettings">
<section name="serverConfiguration" type="System.Configuration.NameValueSectionHandler"></section>
<section name="sqlSettings" type="System.Configuration.NameValueSectionHandler"></section>
</sectionGroup>
</configSections>
...
<MySettings>
<sqlSettings>
<add key="sqlTransactionTimeOut" value="0" />
</sqlSettings>
<serverConfiguration>
<add key="resolveDnsAsync" value="true" />
</serverConfiguration>
</MySettings>
Probably you need to use the section appSettings
<configuration>
<appSettings>
<!-- and Here you define the key and the value like you do-->
<add key="relativepath" value="path"/>
</appSettings>
</configuration>
then in your code write something like this to read it.
String path = ConfigurationManager.AppSettings["relativepath"].ToString();
hope it works for you.
:)

How to get contents of a .config file using ConfigurationManager.GetSection(columnsSectionName) without altering the sections' order?

In my config section I have the following:
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
<section name="NFeColumns" type="System.Configuration.DictionarySectionHandler" />
<section name="CTeColumns" type="System.Configuration.DictionarySectionHandler" />
</configSections>
<appSettings>
<add key="csv.separator" value=";" />
<add key="infNFe.columns" value="NFeColumns"/>
<add key="infCte.columns" value="CTeColumns"/>
<add key="infNFe.filename" value=".\Extracted\NFeCollection.csv"/>
<add key="infCte.filename" value=".\Extracted\CTeCollection.csv"/>
</appSettings>
<NFeColumns>
<add key="infNFe.Id" value="Id" />
<add key="ide.cUF" value="cUF" />
<add key="dest.CNPJ" value="CNPJ" />
<add key="dest.xNome" value="xNome" />
<add key="det.nItem" value="nItem" />
<add key="prod.cProd" value="cProd" />
<add key="prod.xProd" value="xProd" />
<add key="IPI.cEnq" value="cEnq" />
</NFeColumns>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
I want to catch the values from and put in a IDictionary in the same order as the configuration file. I`m doing this:
string columnsSectionName = ConfigurationManager.AppSettings[colFileName + ".columns"];
IDictionary columns = (IDictionary)ConfigurationManager.GetSection(columnsSectionName);
However, Im geting the <NFeColumns> in a totally different order, and I cant figure out why. Can you please help me?
ConfigurationManager.GetSection returns an instance of HashTable. Items in a hash table won't be stored in the order they are inserted. You will have to manually order them.

Split EnterpriseLibrary Block configurations into multiple files

Is it possible to split the configuration for an enterprise library block into multiple files?
For example: I have three assemblies and one hosting project. I want to store the entlib v6 Exception Handling Application Block (EHAB) configuration for each assembly in a separate config file located in the particular assembly.
The hosting project references the three assemblies:
assembly_X
ehabX.config
assembly_Y
ehabY.config
assembly_Z
ehabZ.config
Hosting project
using ehabX.config
using ehabY.config
using ehabZ.config
I already tried the following:
App.config in the hosting project:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common" requirePermission="true" />
</configSections>
<enterpriseLibrary.ConfigurationSource>
<sources>
<add name="ehabX" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common" filePath="ExceptionHandling\ehabX.config" />
<add name="ehabY" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common" filePath="ExceptionHandling\ehabY.config" />
<add name="ehabZ" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common" filePath="ExceptionHandling\ehabZ.config" />
</sources>
<redirectSections>
<add sourceName="ehabX" name="exceptionHandling" />
<add sourceName="ehabY" name="exceptionHandling" />
<add sourceName="ehabZ" name="exceptionHandling" />
</redirectSections>
</enterpriseLibrary.ConfigurationSource>
</configuration>
ehabX.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"/>
</configSections>
<exceptionHandling>
<exceptionPolicies>
<add name="Swallow NotImplementedException">
<exceptionTypes>
<add type="System.NotImplementedException, mscorlib" postHandlingAction="None" name="NotImplementedException"/>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
</configuration>
ehabY.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"/>
</configSections>
<exceptionHandling>
<exceptionPolicies>
<add name="Swallow ArgumentException">
<exceptionTypes>
<add type="System.ArgumentException, mscorlib" postHandlingAction="None" name="NotImplementedException"/>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
</configuration>
The ehabZ.config is omitted.
Using the EHAB with the policy "Swallow NotImplementedException" works fine. But if I try to use the policy "Swallow ArgumentException" defnied in ehabY.config I get this error message:
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingException: The policy with name 'Swallow ArgumentException' cannot be found. Exception handling aborted.
Any suggestions?
Unfortunately, there is nothing out of the box that will let you merge multiple configuration sources into one configuration set.
I think you can probably do what you want but you will have to do some coding. You'll need to read in the appropriate configuration sources and create a custom IConfigurationSource that will merge them all. Additive merge of different config sources? has an example of a MergeConfigurationSource that could help you.

Categories