Skip to content
March 31, 2008 / kiranpatils

Service XXX.ABCService is not available in the current context.+WCSF

Problem:

if you have changed your solution structure to one level down means first your page opens up like this: /Employee/Employee.aspx and now you
moved Employee Folder to EMI folder. So now page URL should look like this when it s open: EMI//Employee/Employee.aspx

and it is dependent on its Module named as Employee and now when you run the application the page says:

Service XXX.ABCService is not available in the current context.

Stack Trace:
Service XXX.ABCService is not available in the current context.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Microsoft.Practices.CompositeWeb.ServiceMissingException: Service IEmployeeService is not available in the current context.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ServiceMissingException: Service IEmployeeService is not available in the current context.]
Microsoft.Practices.CompositeWeb.Collections.ServiceCollection.Get(Type serviceType, Boolean ensureExists) +291
Microsoft.Practices.CompositeWeb.Collections.ServiceCollection.Get(Type serviceType, Boolean ensureExists) +237
Microsoft.Practices.CompositeWeb.ServiceDependencyParameter.GetValue(IBuilderContext context) +142
Microsoft.Practices.ObjectBuilder.ConstructorPolicy.GetParameters(IBuilderContext context, Type type, String id, ConstructorInfo constructor) +102
Microsoft.Practices.ObjectBuilder.WCSFExtensions.CreationStrategy.InitializeObject(IBuilderContext context, Object existing, String id, ICreationPolicy policy) +117
Microsoft.Practices.ObjectBuilder.WCSFExtensions.CreationStrategy.BuildUpNewObject(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +208
Microsoft.Practices.ObjectBuilder.WCSFExtensions.CreationStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +51
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +171
Microsoft.Practices.ObjectBuilder.TypeMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +322
Microsoft.Practices.ObjectBuilder.CreationParameter.GetValue(IBuilderContext context) +31
Microsoft.Practices.ObjectBuilder.ConstructorPolicy.GetParameters(IBuilderContext context, Type type, String id, ConstructorInfo constructor) +102
Microsoft.Practices.ObjectBuilder.WCSFExtensions.CreationStrategy.InitializeObject(IBuilderContext context, Object existing, String id, ICreationPolicy policy) +117
Microsoft.Practices.ObjectBuilder.WCSFExtensions.CreationStrategy.BuildUpNewObject(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +208
Microsoft.Practices.ObjectBuilder.WCSFExtensions.CreationStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +51
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +171
Microsoft.Practices.ObjectBuilder.TypeMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +322
Microsoft.Practices.ObjectBuilder.CreationParameter.GetValue(IBuilderContext context) +31
Microsoft.Practices.ObjectBuilder.PropertySetterInfo.GetValue(IBuilderContext context, Type type, String id, PropertyInfo propInfo) +10
Microsoft.Practices.ObjectBuilder.PropertySetterStrategy.InjectProperties(IBuilderContext context, Object obj, String id) +259
Microsoft.Practices.ObjectBuilder.PropertySetterStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +29
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.CreationStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +68
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +38
Microsoft.Practices.ObjectBuilder.WCSFExtensions.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +322
Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild) +171
Microsoft.Practices.ObjectBuilder.TypeMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +322
Microsoft.Practices.ObjectBuilder.WCSFExtensions.WCSFBuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) +151
Microsoft.Practices.CompositeWeb.CompositionContainer.BuildItem(IBuilder`1 builder, IReadWriteLocator locator, Object item) +256
Microsoft.Practices.CompositeWeb.WebClientApplication.InnerPreRequestHandlerExecute(IHttpContext context) +92
Microsoft.Practices.CompositeWeb.WebClientApplication.Application_PreRequestHandlerExecute(Object sender, EventArgs e) +79
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64

Solution:
In web. config under that folder means /DevelopmentWebsite/EMI/Employee/Web.config
and locate modules section under it
you will have like this:
<module name=”Employee” assemblyName=”Employee” virtualPath=”~/Employee”> //old configuration

change it to like this
<module name=”Employee” assemblyName=”Employee” virtualPath=”~/EMI/Employee”> //new configuration


That’s it!!
Why it happened?


for it you should understand Web.config file.
Web.config file. This is an ASP.NET configuration file that contains the module definition. The module definition is a <module> entry inside the <modules> configuration section of the Composite Web Application Block. A module definition has the following elements:
name attribute. This is the name of the module. for example Employee
assemblyName attribute. This is the name of the module assembly.for example Employee
virtualPath attribute. This is the relative path where the Web pages of the module are located within the Web site. Business modules must always declare the attribute. Foundational modules must not declare the attribute. for example ~/EMI/Employee
<dependencies> element. This defines inter-module dependencies. A module can express dependencies on other modules by adding <dependency> entries inside the <dependencies> element. All modules listed as dependencies will be loaded before the current module is loaded.

This may be occur for others too..main problem is modules section and in web.config.

UPDATED 23-APR-2008

I had faced the same error before few days.. and found one more cause for this error.

If you have not register your service under XYZModuleInitializer.cs file’s method

protected virtual void AddModuleServices(IServiceCollection moduleServices)

{

//REGISTER YOUR SERVICE HERE.

}

Then it will also give you same error..so register your service first and kill that error.

2 Comments

Leave a Comment
  1. sharpguru / May 5 2009 7:48 pm

    I ran into a subtle version of this error. If the service is added using the interface reference and referenced inside the class with a concrete implementation it fails.

    e.g.

    moduleServices.AddNew();

    … and later in some presenter

    public HumanKiller( [ServiceDependency] KillHumans Terminator)

    … breaks! Should read…

    public HumanKiller( [ServiceDependency] IKillHumans Terminator)

    … subtle, hard to find / easy to fix bug!

Trackbacks

  1. Service XXX.ABCService is not available in the current context | davidrogers.id.au – blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: