0
votes

I'm getting this error when trying to run unit tests against my ASP.NET MVC project using a project called MvcIntegrationTestFramework in Visual Studio 2015. As I've searched around most of the solutions suggest switching to use IIS Express. But I'm already using IIS Express. I could also set up IIS but I'd rather not since multiple developers would have to do the same in their environments.

Other people are suggesting that modifying the Response.Headers collection directly could be causing this error, but I'm not seeing any code in the project that could be doing that.

Is there anything else you can think of that I might be overlooking that could cause this error?

Here is the full error and stack trace...

[PlatformNotSupportedException: This operation requires IIS integrated pipeline mode.] System.Web.HttpResponse.get_Headers() +242
Microsoft.Owin.Host.SystemWeb.OwinCallContext.CreateEnvironment() +532 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.GetInitialEnvironment(HttpApplication application) +372
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.PrepareInitialContext(HttpApplication application) +19
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.BeginEvent(Object sender, EventArgs e, AsyncCallback cb, Object extradata) +354
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +673 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +146

1
You can use Jexus Manager to review application pool settings, jexusmanager.com - Lex Li
Seems this is more related to versioning & IIS application pool settings: weblogs.asp.net/scottgu/introducing-iis-express. Ensure that running IIS version at least using same or higher than project's requirement. - Tetsuya Yamamoto

1 Answers

0
votes

I'm looking into this myself currently. So far I've learned:

  • HttpRuntime.UsingIntegratedPipeline can be used to verify whether or not the Http application is running in an integrated pipeline (as the name suggests)
  • The Microsoft.Web.Administration.ApplicationPool.ManagedPipelineMode property can be used to set the pipeline mode, but this only works when running in an IIS application
  • IntegratedPipelineMode is only available if an HttpApplication runs via IIS

  • MvcIntegrationTestFramework starts an HttpApplication, but does not use IIS, so it cannot use IntegratedPipelineMode

Check the reference sources for HttpRuntime: https://referencesource.microsoft.com/#system.web/HttpRuntime.cs

This bit of code indicates UseIntegratedPipeline is only set to true when running in some kind of IIS context. It also indicates the _iisVersion is only filled in in that case.

     internal static void PopulateIISVersionInformation() {
        if (IsEngineLoaded) {
            uint dwVersion;
            bool fIsIntegratedMode;
            UnsafeIISMethods.MgdGetIISVersionInformation(out dwVersion, out fIsIntegratedMode);

            if (dwVersion != 0) {
                // High word is the major version; low word is the minor version (this is MAKELONG format)
                _iisVersion = new Version((int)(dwVersion >> 16), (int)(dwVersion & 0xffff));
                _useIntegratedPipeline = fIsIntegratedMode;
            }
        }
    }

I debugged into the BrowsingSession class of MvcIntegrationTestFramework. The ProcessRequest method will throw an exception. In that method it is possible to view the properties of HttpRuntime:

HttpRuntime properties

The fact that the _iisVersion is null seems to prove this.

I would assume the MvcIntegrationTestFramework "should be edited" to run the HttpApplication in IIS. But the whole point of the framework is to simulate the application, so doing that would probably defeat the purpose.