我有一个新的ASP.NET服务。
在我的本地计算机上一切运行正常。但是,在群集上,每当尝试导航到页面时,都会出现以下错误:
Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'
抛出此错误的特定行是我的C#Razor视图的开始:
ViewBag.Title = "My Home Page";
我环顾了StackOverflow,发现其他人已经通过直接引用Microsoft.CSharp
解决了类似的问题,但这并没有解决我的问题。
版本:
我的控制器:
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));
}
}
});
任何有关修复的建议都非常感谢!