Skip to content

Commit

Permalink
Fixes #322 Type.GetType() may throw in Azure Functions environment
Browse files Browse the repository at this point in the history
  • Loading branch information
jzabroski committed Mar 26, 2020
1 parent 320f64d commit 2d9c031
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ internal class OverrideRuntimeNodeWriterTemplateTypeNamePhase : RazorEnginePhase
{
public static void Register(RazorProjectEngineBuilder builder)
{
var defaultRazorCSharpLoweringPhase = builder.Phases.SingleOrDefault(x => x.GetType() == Type.GetType("Microsoft.AspNetCore.Razor.Language.DefaultRazorCSharpLoweringPhase, Microsoft.AspNetCore.Razor.Language"));
var defaultRazorCSharpLoweringPhase = builder.Phases.SingleOrDefault(x => {
var type = x.GetType();
// This type is not public, so we can't use typeof() operator to match to x.GetType() value.
// Additionally, we can't use Type.GetType("Microsoft.AspNetCore.Razor.Language.DefaultRazorCSharpLoweringPhase, Microsoft.AspNetCore.Razor.Language")
// because apparently it can fail during Azure Functions rolling upgrades? Per user report: https://github.com/toddams/RazorLight/issues/322
var assemblyQualifiedNameOfTypeWeCareAbout = "Microsoft.AspNetCore.Razor.Language.DefaultRazorCSharpLoweringPhase, Microsoft.AspNetCore.Razor.Language, ";
return type.AssemblyQualifiedName.Substring(0, assemblyQualifiedNameOfTypeWeCareAbout.Length) == assemblyQualifiedNameOfTypeWeCareAbout;
});

if (defaultRazorCSharpLoweringPhase == null)
{
Expand Down

0 comments on commit 2d9c031

Please sign in to comment.