Kiksen
Kiksen

Reputation: 1767

Aspnet Core Razor view compile failing

When I try to start my project my Home endpoints doesn't work. I can see it hits the HomeController in breakpoint and returns view where it fails.
My other Api endpoints works eg: /api/values/

I am trying to run it local at this point, but plan is to deploy to AWS Lambda.

I have 3 Controllers:

But when I try to visit my Home controller which should return a simple view I get the following errors:

Error message

I have added my csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <OutputType>exe</OutputType>
  </PropertyGroup>

  <PropertyGroup>
    <TargetFramework>netcoreapp1.0</TargetFramework>
    <OutputTypeEx>exe</OutputTypeEx>
    <PreserveCompilationContext>true</PreserveCompilationContext>
  </PropertyGroup>

  <ItemGroup>
    <Content Include="appsettings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>  

  <ItemGroup>

    <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.2" />

    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="1.1.1" />

    <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.1" />

    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.1" />
    <PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.0.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="1.0.0" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.0.0" />


    <PackageReference Include="AWSSDK.S3" Version="3.3.5.13" />
    <PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.3.0.3" />

    <PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" />
    <PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.1.0" />
    <PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="0.10.1-preview1" />
    <PackageReference Include="Amazon.Lambda.Logging.AspNetCore" Version="1.0.0" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Amazon.Lambda.Tools" Version="1.5.0" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

</Project>

Below here I have added the startup file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace TestLambda
{
    public class Startup
    {
        public const string AppS3BucketKey = "AppS3Bucket";

        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }

        public static IConfigurationRoot Configuration { get; private set; }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddDefaultAWSOptions(Configuration.GetAWSOptions());
            services.AddAWSService<Amazon.S3.IAmazonS3>();
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddLambdaLogger(Configuration.GetLambdaLoggerOptions());

            app.UseMvc();
            app.UseDeveloperExceptionPage();

            app.UseMvcWithDefaultRoute();
        }
    }
}

Below here is the project structure:

Project structure

Adding code to home controller:

using System;
using Microsoft.AspNetCore.Mvc;

namespace TestLambda.Controllers
{
    public class HomeController : Controller
    {

        public IActionResult Index()
        {         
            return View(); // Breakpoint get's hit during debuging.
        }

        public IActionResult Error()
        {
            return View();
        }
    }
}

Upvotes: 1

Views: 334

Answers (1)

arnaudauroux
arnaudauroux

Reputation: 750

I bet you have an error in one of your views, try a rebuid and see if a specific error appears.

Upvotes: 1

Related Questions