After publishing Plato you may see the error message The view 'Index' was not found. The following locations were searched. This error can occur if you leave Plato in development mode after publishing for production.

InvalidOperationException: The view 'Index' was not found. The following locations were searched:

You can see the full error message below...

image.png

Cause

For performance reasons in production environments Plato uses pre-compiled Razor views. You'll notice when you publish Plato that the Views folder for each module is not included within the published output. This is by design and instead within production views are loaded from a pre-compiled views assembly for each module. The views assembly for each module is typically located at /Modules/{moduleName}/bin/release/{moduleName}.Views.dll where {moduleName} is the name of the module.

If you leave Plato within development mode after publishing Plato, Plato will still search for module views on disk as opposed to loading the views from the pre-compiled views assembly resulting in the above error message.

Solution

If you see the above error message after publishing Plato please open your Plato web.config file and ensure the ASPNETCORE_ENVIRONMENT environment variable is set to Production as shown below...

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore stdoutLogEnabled="false" processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
      <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
        <environmentVariable name="COMPLUS_ForceENC" value="1" />
      </environmentVariables>
    </aspNetCore>
  </system.webServer>
</configuration>

That's It

If this article does not resolve your problem please don't hesitate to comment within this article or post your questions within our Q&A area.