Question

Am loading a blog which is built using BlogEngine4 in IIS7 and IIS6, i have done all the configurations and narrowed down the issue with all the possibilities with the help Google. but i end up get the below error. Anyone with the smart answer?

All the pages are loading fine, but only when i load .cshtml file page is not loading

Server Error in '/blog' Application.

Could not locate Razor Host Factory type: umbraco.MacroEngines.RazorUmbracoFactory, umbraco.MacroEngines 

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: System.InvalidOperationException: Could not locate Razor Host Factory type: umbraco.MacroEngines.RazorUmbracoFactory, umbraco.MacroEngines

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: 
[InvalidOperationException: Could not locate Razor Host Factory type: umbraco.MacroEngines.RazorUmbracoFactory, umbraco.MacroEngines]
System.Web.WebPages.Razor.WebRazorHostFactory.CreateFactory(String typeName) +178
System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +64System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfigCore(RazorWebSectionGroup config, String virtualPath, String physicalPath) +201
System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig(String virtualPath, String physicalPath) +41
System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig(String virtualPath) +7
System.Web.WebPages.Razor.RazorBuildProvider.GetHostFromConfig() +16
System.Web.WebPages.Razor.RazorBuildProvider.CreateHost() +17
System.Web.WebPages.Razor.RazorBuildProvider.get_Host() +21
System.Web.WebPages.Razor.RazorBuildProvider.EnsureGeneratedCode() +66
System.Web.WebPages.Razor.RazorBuildProvider.get_CodeCompilerType() +39
System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider) +94
System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders() +207
System.Web.Compilation.BuildProvidersCompiler.PerformBuild() +41
System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +658
System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +360
System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +107
System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound) +96
System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp) +13
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +45
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(String virtualPath, Type requiredBaseType) +23
System.Web.WebPages.BuildManagerWrapper.CreateInstanceOfType(String virtualPath) +228
System.Web.WebPages.VirtualPathFactoryExtensions.CreateInstance(IVirtualPathFactory factory, String virtualPath) +147
System.Web.WebPages.VirtualPathFactoryManager.CreateInstanceOfType(String virtualPath) +192
System.Web.WebPages.VirtualPathFactoryExtensions.CreateInstance(IVirtualPathFactory factory, String virtualPath) +74
System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(String virtualPath, IVirtualPathFactory virtualPathFactory) +24
System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(String virtualPath) +20
System.Web.WebPages.WebPageRoute.DoPostResolveRequestCache(HttpContextBase context) +250
System.Web.WebPages.WebPageHttpModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +94
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +135
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +168

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

Was it helpful?

Solution

If you are trying to host the blogengine site within a virtual directory of the Umbraco site, then you will have to amend the blogengine web.config to "remove" all the Umbraco-specific handlers and modules, as these will be inherited by the blogengine application, causing this exception because the application can't find the relevant DLLs in its bin folder.

I recently had a similar problem and I have posted the web.config I used in the virtual directory below. Mine was a very simple web application, so obviously this will not work by itself in your blogengine app. You will need to add the relevant parts into your web.config file.

Also, this was for a v6 Umbraco install in IIS7.5, so you may have to experiment a little.

<?xml version="1.0"?>

<configuration>
  <configSections>
    <remove name="urlrewritingnet" />
    <remove name="umbraco.presentation.Properties.Settings" />
    <remove name="clientDependency" />
    <remove name="Examine" />
    <remove name="ExamineLuceneIndexSets" />
    <remove name="FileSystemProviders"  />
    <remove name="log4net" />
    <remove name="BaseRestExtensions" />
    <remove name="system.web.webPages.razor" />
  </configSections>

  <appSettings>
    <clear/>
  </appSettings>

  <system.web>
    <httpModules>
      <remove name="UrlRewriteModule" />
      <remove name="UmbracoModule" />
      <remove name="ClientDependencyModule" />
    </httpModules>
    <httpHandlers>
      <remove verb="*" path="umbraco/channels.aspx" />
      <remove verb="*" path="umbraco/channels/word.aspx" />
      <remove verb="*" path="DependencyHandler.axd" />
      <remove verb="GET,HEAD,POST" path="GoogleSpellChecker.ashx" />
    </httpHandlers>    
    <compilation defaultLanguage="c#" debug="false" batch="false" targetFramework="4.0">
      <buildProviders>
        <remove extension=".cshtml" />
        <remove extension=".vbhtml" />
        <remove extension=".razor" />
      </buildProviders>
    </compilation>
    <membership>
      <providers>
        <remove name="UmbracoMembershipProvider" />
        <remove name="UsersMembershipProvider" />
      </providers>
    </membership>
    <!-- added by NH to support membership providers in access layer -->
    <roleManager enabled="false">
      <providers>
        <remove name="UmbracoRoleProvider" />
      </providers>
    </roleManager>
    <!-- Sitemap provider-->
    <siteMap defaultProvider="UmbracoSiteMapProvider" enabled="false">
      <providers>
        <remove name="UmbracoSiteMapProvider" />
      </providers>
    </siteMap>

  </system.web>

  <system.webServer>
    <modules>
      <remove name="UrlRewriteModule" />
      <remove name="UmbracoModule" />
      <remove name="ClientDependencyModule" />
    </modules>
    <handlers accessPolicy="Read, Write, Script, Execute">
      <remove name="Channels" />
      <remove name="Channels_Word" />
      <remove name="ClientDependency" />
      <remove name="SpellChecker" />
    </handlers>
  </system.webServer>

</configuration>

Update:

It may also be necessary to update the <system.web.webPages.razor> section if this is present in your application web.config, changing the host and pages entries back to their defaults:

<host factoryType="System.Web.WebPages.Razor.WebRazorHostFactory,
    System.Web.WebPages.Razor" />
<pages pageBaseType="System.Web.WebPages.WebPage">

This is because Umbraco implements it's own hostfactory and page base.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top