Skip to content

Commit

Permalink
Merge pull request #976 from riganti/bugfix/better-error-corrupted-ma…
Browse files Browse the repository at this point in the history
…sterpage

Improved error reporting for corrupted master page
  • Loading branch information
tomasherceg committed Apr 9, 2021
2 parents 79074ab + 2671043 commit fad57d9
Showing 1 changed file with 8 additions and 1 deletion.
Expand Up @@ -208,7 +208,14 @@ protected virtual void ValidateMasterPage(IAbstractTreeRoot root, IAbstractContr
if (masterPage == null)
return;
var viewModel = root.DataContextTypeStack.DataContextType;
if (!masterPage.DataContextType.IsAssignableFrom(viewModel))

if (masterPage.DataContextType is ResolvedTypeDescriptor typeDescriptor && typeDescriptor.Type == typeof(UnknownTypeSentinel))
{
masterPageDirective!.DothtmlNode!.AddError("Could not resolve the type of viewmodel for the specified master page. " +
$"This usually means that there is an error with the @viewModel directive in the master page file: \"{masterPage.FileName}\". " +
$"Make sure that the provided viewModel type is correct and visible for DotVVM.");
}
else if (!masterPage.DataContextType.IsAssignableFrom(viewModel))
{
masterPageDirective!.DothtmlNode!.AddError($"The viewmodel {viewModel.Name} is not assignable to the viewmodel of the master page {masterPage.DataContextType.Name}.");
}
Expand Down

0 comments on commit fad57d9

Please sign in to comment.