Spring.Net. ContextRegistry.GetContext() exception, cannot configure Common.Logging - c#

I cannot get the IApplication context for my console app
I get an exception with this detail:
The type initializer for 'Spring.Context.Support.ContextRegistry' threw an exception.
With inner exception:
Could not configure Common.Logging from configuration section 'common/logging
There's clearly something basic I've not hooked up, but I'm not sure what.
using Spring.Context;
using Spring.Context.Support;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
IApplicationContext ctx = ContextRegistry.GetContext();
}
}
}
And my app.config looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects"/>
</context>
<objects xmlns="http://www.springframework.net">
<description>An example that demonstrates simple IoC features. </description>
</objects>
</spring>
</configuration>

Spring.Net uses Common Logging as facility for logging, you have to add the logging configuration to your app.config and the proper library to the referenced assemblies.
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
<arg key="level" value="DEBUG" />
<arg key="showLogName" value="true" />
<arg key="showDataTime" value="true" />
<arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
</factoryAdapter>
</logging>
</common>
</configuration>
http://netcommon.sourceforge.net/docs/1.2.0/reference/html/logging.html#logging-declarative-config

The type initializer for 'Spring.Context.Support.ContextRegistry'
threw an exception
This is valueable information and Spring.net is really good at providing additional information. Whenever Spring.net throws something, be sure to read the InnerException.
WHen I edit my config I get the messages: Could not find schema
information for the attribute #. for # = 'uri', 'context', 'resource'
and 'spring'
This is normal if you didn't install the schemas. You can download the schemas at their site and find additional information in their docs. Please note that this is optional and spring runs without those schemas.

Related

Paypal: Configuration.GetApiContext -> VS: Cannot resolve Issue

If I install .Net SDK and uses Sample Code, VS says: Cannot resolve symbol 'Configuration' at this line:
var apiContext = Configuration.GetAPIContext();
So, what DLL or namespaces did I missed?
It is a wrapper class around the configuration section.
Please look into \PayPal-NET-SDK-develop\Samples\Source\Utilities\Configuration.cs and create it to suit your configuration.
Don't forget to modify your web.config or app.config
<configSections>
<section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />
</configSections>
<!-- PayPal SDK settings -->
<paypal>
<settings>
<add name="mode" value="sandbox" />
<add name="clientId" value="youclientid" />
<add name="clientSecret" value="yoursecret" />
</settings>
</paypal>

Unity Interceptor Support at Design-Time

How can I "translate" this Unity Fluent API code into XML Design-Time?
container.RegisterType<IRat, Rat>().Configure<Interception()
.SetInterceptorFor<IRat>(new InterfaceInterceptor());
I tried the code here but it seems to be outdated, since I am working with the last version of Unity.
Assuming you want to do interception with an IInterceptionBehavior the configuration would look something like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
</configSections>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<assembly name="MyApp"/>
<namespace name="MyApp"/>
<sectionExtension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Microsoft.Practices.Unity.Interception.Configuration" />
<container>
<extension type="Interception"/>
<register type="MyInterceptor">
<lifetime type="singleton" />
</register>
<register type="IRat" mapTo="Rat">
<interceptor type="InterfaceInterceptor"/>
<interceptionBehavior type="MyInterceptor"/>
</register>
</container>
</unity>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
You need to declare a sectionExtension and then add the Interception extension to the container. Then when registering types supply the interceptor and interceptionBehavior. If using call handlers then you would add the PolicyInjection behavior.

Tell ConfigurationManager to ignore App.config section

My App.config file is markuped as:
<configuration>
<configSections>
<section name="Custom" type="…" />
</configSections>
<Custom>
...
</Custom>
<Ignored>
...
</Ignored>
</configuration>
So, I have an configuration file, where:
one section ("Custom") is handled by API and I have written ConfigurationSection inheritor for it
second section ("Ignored") I will parse by myself, because Configuration API doesnt let me solve my task.
When I run program, exception occurs "Unrecognized configuration section 'Ignored'".
Do I have possibility to tell ConfigurationManager to ignore this section "Ignored"?
You can add the following to your <configSections> element:
<section name="Ignored" type="System.Configuration.IgnoreSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

Common.logging doesn't pick up the App.config in a class library

The class library project has a App.config file as given:
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections>
<common>
<logging>
<factoryAdapter type="MyApp.Logging.NLog2FactoryAdapter, MyApp.Logging">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.netfx40.xsd">
<extensions>
<add assembly="MyApp.Logging" />
</extensions>
<targets async="true">
<target type="Console" name="ConsoleTarget" layout="${longdate}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring:innerFormat=tostring:maxInnerExceptionLevel=8}" />
<target type="File" name="FileTarget" fileName="C:\Users\liangj\Desktop\log.log" layout="${longdate}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring:innerFormat=tostring:maxInnerExceptionLevel=8}" />
<target type="JsonNetwork" name="SplunkTarget" address="tcp4://log-staging.dbrs.local:10500" newLine="true" layout="${message} ${exception:format=tostring:innerFormat=tostring:maxInnerExceptionLevel=8}" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="SplunkTarget,ConsoleTarget,FileTarget" />
</rules>
</nlog>
<appSettings>
<add key="AppVersion" value="2.1" />
</appSettings>
</configuration>
In the c# code, I have:
public static void WriteLog(string msg, IDictionary<string, object> metadata)
{
Configuration Configuration = ConfigurationManager.OpenExeConfiguration(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath);
string version = Configuration.AppSettings.Settings["AppVersion"].Value.ToString();
string LogTime = DateTime.Now.ToString("yyyy-M-dd H:mm:ss tt");
metadata["LogTime"] = LogTime;
Console.WriteLine(version );
Console.WriteLine(Logger.Log.ToString());
Logger.Log.InfoWithMetadata(msg, metadata);
}
The way this class library used is that it will be imported into PowerShell which adds custom cmdlets to it. When I open powerShell and execute the custom cmdlet, the open shows that the Logger is a taken as a default logger which doesn't do anything, but I do expect a proper logger to log to files.
I doubt that since this is a class library, it automatically generates a solutionName.dll.config file, which is not recognized by common.Logging, which may expects a exe.config instead?

can not find schema info when configuration quartz.net

When i add this code to app.config in Windows service program:
<quartz>
<add key="quartz.scheduler.instanceName" value="ExampleDefaultQuartzScheduler"/>
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz"/>
<add key="quartz.threadPool.threadCount" value="10"/>
<add key="quartz.threadPool.threadPriority" value="2"/>
<add key="quartz.jobStore.misfireThreshold" value="60000"/>
<add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz"/>
</quartz>
it tips:
Could not find schema information for the element `key`.
Could not find schema information for the attribute `quartz`.
Could not find schema information for the element `value`.
I am sure i have using job_scheduling_data_2_0.xsd file in background.
And predefine the quartz:
<configSections>
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
Where is the problem?And where to find the schema info?
And when is the label <quartz> namespace?
Where should i find the xsd file of quartz.net?
Normal reason is your config file lack of schema file like *.xsd in:..\Microsoft Visual Studio\Xml\Schemas folder.
You can omit these tips,it could not affect your program running.
Or you can write the xsd schema file by yourself.

Categories

Resources