ASP.NET Razor的CSharp编译器运行时错误

时间:2018-08-03 17:25:50

标签: c# razor asp.net-core asp.net-core-mvc

我有一个新的ASP.NET服务。

在我的本地计算机上一切运行正常。但是,在群集上,每当尝试导航到页面时,都会出现以下错误:

Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'

抛出此错误的特定行是我的C#Razor视图的开始:

ViewBag.Title = "My Home Page";

我环顾了StackOverflow,发现其他人已经通过直接引用Microsoft.CSharp解决了类似的问题,但这并没有解决我的问题。

版本:

  • ASP.NET Core v1.1.0
  • ASP.NET Core MVC v1.1.0
  • .NET Framework v4.6.1

我的控制器:

public sealed class MyController: Controller
{
    private readonly ILogger logger;

    /// <summary>
    /// Initializes a new instance of the <see cref="MyController"/> class.
    /// </summary>
    /// <param name="logger">Dependency Injected logger</param>
    public MyController(ILogger<MyController> logger)
    {
        if (logger == null)
        {
            throw new System.ArgumentNullException(nameof(logger));
        }

        this.logger = logger;
    }

    /// <summary>
    /// Gets the homepage
    /// </summary>
    /// <returns>ASP.NET Razor page</returns>
    [ActionName("Index")]
    [Route("")]
    public ActionResult Index()
    {
        return this.View();
    }
}

我的视图的开始(Index.cshtml):

@{
    ViewBag.Title = "My Home Page";
}

我必须将此添加到My Program.cs(在ConfigureServices块中),以使其在本地运行。我怀疑这可能是问题所在,但不确定如何解决:

services.AddMvc().AddRazorOptions(options =>
{
    foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
    {
        if (!assembly.IsDynamic && !string.IsNullOrEmpty(assembly.Location))
        {
            options.AdditionalCompilationReferences.Add(MetadataReference.CreateFromFile(assembly.Location));
        }
    }
});

任何有关修复的建议都非常感谢!

0 个答案:

没有答案