Results 1 to 8 of 8

Thread: ContextRegistry.GetContext() throws a System.ArgumentException

  1. #1
    Join Date
    Aug 2012
    Posts
    5

    Default ContextRegistry.GetContext() throws a System.ArgumentException

    My project was working fine but suddently it started throwing, the app.config files seems working fine, because when I intentionally broke the configuration, the exception I got is different.

    ContextRegistry.GetContext();
    [System.ArgumentException] {"You must provide either or both Configuration Locations and/or Configuration Resources!"}

    I tried to hookup a debugger to the process, and below is the call stack I got.

    at Spring.Context.Support.XmlApplicationContext..ctor (XmlApplicationContextArgs args)
    at Spring.Context.Support.XmlApplicationContext..ctor (String name, Boolean caseSensitive, String[] configurationLocations)
    at _dynamic_Spring.Context.Support.XmlApplicationCont ext..ctor(Object[] )
    at Spring.Reflection.Dynamic.SafeConstructor.Invoke(O bject[] arguments)
    at Spring.Context.Support.ContextHandler.RootContextI nstantiator.InvokeContextConstructor(ConstructorIn fo ctor)
    at Spring.Context.Support.ContextHandler.ContextInsta ntiator.InstantiateContext()
    at Spring.Context.Support.ContextHandler.InstantiateC ontext(IApplicationContext parentContext, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources)
    at Spring.Context.Support.ContextHandler.Create(Objec t parent, Object configContext, XmlNode section)


    the complete exception text is pased below.Caught exception:

    ----------------------------------------------------------
    Error creating context 'spring.root': You must provide either or both Configuration Locations and/or Configuration Resources!

    Extended message:

    An exception of type 'System.Configuration.ConfigurationErrorsException ' occurred and was caught.
    -------------------------------------------------------------------------------------------------
    2012-08-08T16:03:38+02:00
    Exception Messages:
    ConfigurationErrorsException: Error creating context 'spring.root': You must provide either or both Configuration Locations and/or Configuration Resources!
    ArgumentException : You must provide either or both Configuration Locations and/or Configuration Resources!

    Type : System.Configuration.ConfigurationErrorsException, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
    Message : Error creating context 'spring.root': You must provide either or both Configuration Locations and/or Configuration Resources!
    Source : System.Configuration
    BareMessage : Error creating context 'spring.root': You must provide either or both Configuration Locations and/or Configuration Resources!
    Filename :
    Line : 0
    Errors Collection:
    TargetSite : System.Object EvaluateOne(System.String[], System.Configuration.SectionInput, Boolean, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object)
    Stack Trace : at System.Configuration.BaseConfigurationRecord.Evalu ateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
    at System.Configuration.BaseConfigurationRecord.Evalu ate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
    at System.Configuration.BaseConfigurationRecord.GetSe ctionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
    at System.Configuration.BaseConfigurationRecord.GetSe ctionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
    at System.Configuration.BaseConfigurationRecord.GetSe ctionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
    at System.Configuration.BaseConfigurationRecord.GetSe ction(String configKey)
    at System.Configuration.ClientConfigurationSystem.Sys tem.Configuration.Internal.IInternalConfigSystem.G etSection(String sectionName)
    at System.Configuration.ConfigurationManager.GetSecti on(String sectionName)
    at Spring.Util.ConfigurationUtils.GetSection(String sectionName) in c:\_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Util\ConfigurationUti ls.cs:line 71
    at Spring.Context.Support.ContextRegistry.InitializeC ontextIfNeeded() in c:\_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\Conte xtRegistry.cs:line 390
    at Spring.Context.Support.ContextRegistry.GetContext( ) in c:\_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\Conte xtRegistry.cs:line 256
    at CT.System.Program.Main(String[] args) in d:\TFSShare\MAIN\CT.System\Common\Impl\Program.cs: line 33
    Inner Exception
    ---------------
    Type : System.ArgumentException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    Message : You must provide either or both Configuration Locations and/or Configuration Resources!
    Source : Spring.Core
    ParamName :
    TargetSite : Void .ctor(Spring.Context.Support.XmlApplicationContext Args)
    Stack Trace : at Spring.Context.Support.XmlApplicationContext..ctor (XmlApplicationContextArgs args) in c:\_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\XmlAp plicationContext.cs:line 107
    at Spring.Context.Support.XmlApplicationContext..ctor (String name, Boolean caseSensitive, String[] configurationLocations) in c:\_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\XmlAp plicationContext.cs:line 156
    at _dynamic_Spring.Context.Support.XmlApplicationCont ext..ctor(Object[] )
    at Spring.Reflection.Dynamic.SafeConstructor.Invoke(O bject[] arguments) in c:\_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Reflection\Dynamic\Dy namicConstructor.cs:line 116
    at Spring.Context.Support.ContextHandler.RootContextI nstantiator.InvokeContextConstructor(ConstructorIn fo ctor) in c:\_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\Conte xtHandler.cs:line 563
    at Spring.Context.Support.ContextHandler.ContextInsta ntiator.InstantiateContext() in c:\_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\Conte xtHandler.cs:line 508
    at Spring.Context.Support.ContextHandler.InstantiateC ontext(IApplicationContext parentContext, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) in c:\_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\Conte xtHandler.cs:line 351
    at Spring.Context.Support.ContextHandler.Create(Objec t parent, Object configContext, XmlNode section) in c:\_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\Conte xtHandler.cs:line 289
    Additional Info:
    MachineName : EH5CN06G0011NB
    TimeStamp : 2012-08-08T16:03:38+02:00
    AppDomainName: CT.System.Common.Impl.exe
    ThreadIdentity:
    WindowsIdentity: WW005\gexicb
    ----------------------------------------------------------
    Last edited by xiaoguo.ge; 08-10-2012 at 07:57 AM.

  2. #2
    Join Date
    Aug 2012
    Posts
    5

    Default

    I was able to debug the program and the exceptiong was thrown here. But still it gives me no clue about what is wrong with my program.
    Spring.NET\src\Spring\Spring.Core\Context\Support\ XmlApplicationContext.cs
    public XmlApplicationContext(XmlApplicationContextArgs args)
    : base(args.Name, args.CaseSensitive, args.ParentContext)
    {
    _configurationLocations = args.ConfigurationLocations;
    _configurationResources = args.ConfigurationResources;

    if (args.Refresh)
    {
    bool hasLocations = args.ConfigurationLocations.Length > 0;
    bool hasResources = args.ConfigurationResources.Length > 0;

    if (!hasLocations && !hasResources)
    throw new ArgumentException("You must provide either or both Configuration Locations and/or Configuration Resources!");

  3. #3
    Join Date
    Jul 2010
    Posts
    245

    Default

    Can you provide your Spring.NET config file(s) as well as your app.config/web.config files?

    Also, if this isn't a web app, can you post the code you're using to new-up the ###ApplicationContext you are using?

    Thanks,
    -Steve B.

  4. #4
    Join Date
    Aug 2012
    Posts
    5

    Default

    Quote Originally Posted by Steve Bohlen View Post
    Can you provide your Spring.NET config file(s) as well as your app.config/web.config files?

    Also, if this isn't a web app, can you post the code you're using to new-up the ###ApplicationContext you are using?

    Thanks,
    -Steve B.
    It is a desktop application. The problem is strangly only sporadic. It went away yesterday. I don't know what I have done that broke/fixed it. Below are the c# code and app.config file. The problem should not be in the configuration file. I did several things to intentionally break the configuration
    1. make the app.config invalid
    2. make the file path in <resource uri="filex://%SOMARIS_CONFIG%/CT/System/SpringConfig_SRI.xml" /> invalid
    and always got different exception than the one I mentioned above.

    When everything is working fine.
    _configurationLocations is a one element string array
    with _configurationLocations[0] = “filex:%SOMARIS_CONFIG%/CT/System/Spring/Spring_config.xml”
    In the excpetion case, the array is always empty

    Spring.NET code that throws the exception
    Code:
     
           public XmlApplicationContext(XmlApplicationContextArgs args)
                : base(args.Name, args.CaseSensitive, args.ParentContext)
            {
                _configurationLocations = args.ConfigurationLocations;
                _configurationResources = args.ConfigurationResources;
    
                if (args.Refresh)
                {
                    bool hasLocations = args.ConfigurationLocations.Length > 0;
                    bool hasResources = args.ConfigurationResources.Length > 0;
    
                    if (!hasLocations && !hasResources)
                        throw new ArgumentException("You must provide either or both Configuration Locations and/or Configuration Resources!");
    My code for creating the spring contaxt
    Code:
            static void Main(string[] args)
            {
                // register exception handler
                try
                {
                    // set the exception handler
                    SetExceptionHandler();
                }
                catch (Exception e)
                {
                    // Handle the exception using the global exception handler
                    ExceptionHandler exceptionHandler = new ExceptionHandler();
                    exceptionHandler.HandleException("CT.System caught exception during exception handler registration!", e);
                }
    
                IApplicationContext context = ContextRegistry.GetContext();
                ServiceHost host = (ServiceHost)context.GetObject("ServiceHost");
    
                host.Open();
    
                Console.WriteLine("Hit enter to stop the application.");
                Console.ReadLine();
    
                host.Close();
            }
    My configuration file
    Code:
    <?xml version="1.0"?>
    <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" />
          <section name="resourceHandlers" type="Spring.Context.Support.ResourceHandlersSectionHandler, Spring.Core"/>
        </sectionGroup>
      </configSections>
    
      <spring>
        <resourceHandlers>
          <handler protocol="filex" type="CT.Common.SpringExpansion.Contract.ExpandableFileSystemResource, CT.Common.SpringExpansion.Contract"/>
        </resourceHandlers>
        <context>
          <resource uri="filex://%SOMARIS_CONFIG%/CT/System/SpringConfig_SRI.xml" />
        </context>
      </spring>
      
      <system.web>
        <compilation debug="true"/>
      </system.web>
      <!-- When deploying the service library project, the content of the config file must be added to the host's 
      app.config file. System.Configuration does not support config files for libraries. -->
      <system.serviceModel>
        <services>
          <service name="CT.Common.Aop.Server.WcfServer">
            <clear />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"
              listenUriMode="Explicit" />
            <endpoint address="net.pipe://localhost/Wcf/Scanner" binding="netNamedPipeBinding"
              bindingConfiguration="" contract="CT.Common.Aop.Contract.IWcfService" />
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8732/Design_Time_Addresses/CT.System.WcfService/WcfServiceCore/" />
              </baseAddresses>
            </host>
          </service>
        </services>
        <bindings>
          <netNamedPipeBinding>
            <!--Remark: To set the buffer size might not be a good idea, as it is of static content (should better be set dynamically).
              Also we might get trouble in the future, because name pipe declarations do only work with in the scope of one machine.-->
            <binding
              maxBufferPoolSize="965536"
              maxBufferSize="965536"
              maxReceivedMessageSize="965536">
              <readerQuotas maxStringContentLength="965536" />
              <security mode="Transport">
                <transport protectionLevel="EncryptAndSign" />
              </security>
            </binding>
          </netNamedPipeBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information, 
              set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="True"/>
              <!-- To receive exception details in faults for debugging purposes, 
              set the value below to true.  Set to false before deployment 
              to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="False"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
      <!--Runtime Execution Settings-->
      <runtime>
        <legacyUnhandledExceptionPolicy enabled="1"/>
        <generatePublisherEvidence enabled="false"/>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <probing privatePath=".\DoDll;.\dll;.\extern;.\DoTestDll;.\testdll"/>
        </assemblyBinding>
        <disableCommitThreadStack enabled="1"/>
      </runtime>
    <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
    Last edited by xiaoguo.ge; 08-10-2012 at 07:58 AM.

  5. #5
    Join Date
    Aug 2012
    Posts
    5

    Default

    I am able to reliablly&nbsp;reproduce the problem now. When the <resource> object is empty in the application spring/context configuration, then the exception will be thrown. I am not sure if this is the same cause that caused the exception I mentioned in my post, and how come my context object in the configuration file can become empty.
    Last edited by xiaoguo.ge; 08-10-2012 at 08:45 AM.

  6. #6
    Join Date
    Jul 2010
    Posts
    245

    Default

    I notice that you have written (and registered) your own ResourceHandler (CT.Common.SpringExpansion.Contract.ExpandableFileS ystemResource). This is (of course) an entirely supported extensibility point, but I am wondering if its possible that there's something going wrong your handler. Based on its name + the fact that it looks as if you are trying to substitute (and resolve) what appears to be an environment variable (%SOMARIS_CONFIG%) in your custom resource string, I'm guessing that its possible something is going wrong when attempting to resolve the %SOMARIS_CONFIG% value in order to do the substitution.

    Some ideas to inspect (note that all or none of these might be valid in your situation)...
    • is it possible that you have set the value of %SOMARIS_CONFIG% under the user-specific environment vars instead of the system-wide environment vars? Since the ASP.NET process runs under its own identity, this might affect whether it can 'see' the variable value to properly do the substitution (and this might also explain why it works under a console app but not under a Sharepoint/IIS/ASP.NET app)
    • can you log (somewhere, doesn't matter where) the value that is being resolved for %SOMARIS_CONFIG% and the subsequent path to the resource file that is being understood in order to investigate whether its pointing where you think it is?
    • can you (temporarily) remove your own ResourceHandler registration, hard-code the full path to the config resource (using the SPRNET standard "file://..." syntax) directly in the config and evaluate whether that (reliably) works or fails? That might help isolate whether your handler is the source of the issue or not.


    This might help better isolate the origin of the trouble and give us an idea where to look next!

    Thanks,
    -Steve B.

  7. #7
    Join Date
    Aug 2012
    Posts
    5

    Default

    •is it possible that you have set the value of %SOMARIS_CONFIG% under the user-specific environment vars instead of the system-wide environment vars? Since the ASP.NET process runs under its own identity, this might affect whether it can 'see' the variable value to properly do the substitution (and this might also explain why it works under a console app but not under a Sharepoint/IIS/ASP.NET app)
    •can you log (somewhere, doesn't matter where) the value that is being resolved for %SOMARIS_CONFIG% and the subsequent path to the resource file that is being understood in order to investigate whether its pointing where you think it is?
    The problem seems not to be in the ResourceHandler. The exception was thrown before the code even reach ResourceHandler.
    I tried running the process where %SOMARIS_CONFIG% is not defined, in this case, the exception thrown is that the resource can not be resolved to a local file path.

    •can you (temporarily) remove your own ResourceHandler registration, hard-code the full path to the config resource (using the SPRNET standard "file://..." syntax) directly in the config and evaluate whether that (reliably) works or fails? That might help isolate whether your handler is the source of the issue or not.
    The program work fine both with and without our own ResourceHandler.
    Now I tend to believe that this may be just a stupid mistake I made by deleting the resource definition and failed to notice it during debugging. There may be nothing mysterious about it.

  8. #8
    Join Date
    Jul 2010
    Posts
    245

    Default

    In a sense, I suppose that's good to hear

    Please do try to circle back here to let us know if you were able to resolve the issue on your end. If not, we'll have to dig a little deeper with you.

    -Steve B.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •