I'm using the Razor Engine (razorengine.codeplex.com) in a non-MVC environment. I compile templates that are stored in files and use @inherits
for intellisense support.
View<>
and sets View<>
as baseclassAll cshtml files have the following @inherits
directive:
@inherits View<SomeModel>
An error is thrown:
The type of namespace View isn't found, are you missing an assembly reference?
My web.config contains the following entry:
<add namespace="CustomAssembly.NamespaceContainingViewClass" />
I think this has something to do with the other entry <assemblies>
, where my CustomAssembly
isn't mentioned. Is this the case? Can I compile with my custom base class which is contained in another assembly?
p.s. I cannot retrieve a strong name for the assembly because my custom assembly references a 3d party assembly which isn't strongly named either...
Stacktrace:
at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType(TypeContext context)
at RazorEngine.Templating.TemplateService.CreateTemplate(String template, Type modelType)
at RazorEngine.Templating.TemplateService.GetTemplate(String template, Type modelType, String name)
at RazorEngine.Templating.TemplateService.Compile(String template, Type modelType, String name)
at RazorEngine.Razor.Compile(String template, Type modelType, String name)
You can add a namespace in the TemplateServiceConfiguration:
TemplateServiceConfiguration templateConfig = new TemplateServiceConfiguration();
templateConfig.Namespaces.Add("MyNamespaceGoesHere");
templateConfig.Resolver = new DelegateTemplateResolver(name =>
{
<My template resolve implementation>
}
Razor.SetTemplateService(new TemplateService(templateConfig));
using (TextWriter tw = new StringWriter())
{
Razor.Resolve(viewName + ".cshtml", model).Run(new ExecuteContext(), tw);
var emailHtmlBody = tw.ToString();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With