I’m receiving the following error when trying to run an ASP.NET MVC 3 project:
‘ServiceHostingEnvironment.EnsureServiceAvailable’ cannot be invoked within the current hosting environment. This API requires that the calling application be hosted in IIS or WAS.
When I run the project through Visual Studio 2010 by hitting F5, it loads up just fine. I only get this error when trying to access the application through http://localhost/projectname. What’s strange is that this code base worked on my computer before I formatted and reinstalled Windows on it. Any idea what this error message means?
Here’s the stack trace if it helps at all:
[InvalidOperationException: ‘ServiceHostingEnvironment.EnsureServiceAvailable’ cannot be invoked within the current hosting environment. This API requires that the calling application be hosted in IIS or WAS.]
System.ServiceModel.ServiceHostingEnvironment.EnsureInitialized() +378
System.ServiceModel.AspNetPartialTrustHelpers.PartialTrustInvoke(ContextCallback callback, Object state) +106
System.ServiceModel.Activation.ServiceHttpModule.BeginProcessRequest(Object sender, EventArgs e, AsyncCallback cb, Object extraData) +175
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +115
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371
UPDATE: I went ahead and created a new ASP.NET MVC 3 project using Visual Studio 2010’s templates. I added the application to IIS and tried to access it and received the same error. I’m thinking there may be something wrong with my IIS installation.
You might check the following blog post.UPDATE:
The problem seems to be related to the installation of .NET 4.0. Reinstalling it fixes the issue.