이 중 어느 것도 나를 위해 일하지 않았습니다.
내 클래스 라이브러리는 모두 System.Core와 Microsoft.CSharp를 모두 참조하고있었습니다. 웹 응용 프로그램은 4.0이며 지원 문제로 인해 4.5로 업그레이드 할 수 없습니다.
Razor Engine을 사용하여 면도기 템플릿을 컴파일하는 중 오류가 발생했으며 웹 응용 프로그램을 다시 시작한 후 간헐적으로 만 발생했습니다.
나를 위해 일한 해결책은 수동으로 어셈블리를로드 한 다음 동일한 작업을 다시 시도하는 것입니다 ...
bool retry = true;
while (retry)
{
try
{
string textTemplate = File.ReadAllText(templatePath);
Razor.CompileWithAnonymous(textTemplate, templateFileName);
retry = false;
}
catch (TemplateCompilationException ex)
{
LogTemplateException(templatePath, ex);
retry = false;
if (ex.Errors.Any(e => e.ErrorNumber == "CS1969"))
{
try
{
_logger.InfoFormat("Attempting to manually load the Microsoft.CSharp.RuntimeBinder.Binder");
Assembly csharp = Assembly.Load("Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
Type type = csharp.GetType("Microsoft.CSharp.RuntimeBinder.Binder");
retry = true;
}
catch(Exception exLoad)
{
_logger.Error("Failed to manually load runtime binder", exLoad);
}
}
if (!retry)
throw;
}
}
잘하면 이것은 다른 누군가를 도울 수 있습니다.