Razor “The type or namespace name 'x' could not be found” Error. Compile Only

孤人 提交于 2019-12-24 09:28:30

问题


I have run into an issue with my razor templates.

In the the template I am using it has two using references at the top of the file.

@using Framework;
@using Bundler;

Both of these reference internal namespaces in my project that are both included as refs in the project that is compiling the template. However the bundler reference fails with the classic.

Unable to compile template. The type or namespace name 'Bundler' could not be found (are you missing a using directive or an assembly reference?)

This to me is a bit weird because if I parse the template instead it works fine.

So it is really only a performance issue but as it doesn't effect the site from running correctly.

Is there any reason why compiling (Razor.Compile(content, Name);) fails when parsing (Razor.Parse(content, model, this.Name)) Doesn't?

Thanks for the help :)


回答1:


So I found a solution.

If I call a method in the namespace before the razor.Compile it seems to fix the issue.

I created a method called helloDll anywhere inside of the namespace that is failing.

public static void helloDll(){}

I call this before my compile

Bundler.cvStyleBundle.helloDll();
Razor.Compile(content, Name);

No more error :)

I think it has something to do with just in time dll loading and the fact that the dll is not loaded at the time of compile and because the compile happens in some weird lovely funky way it doesnt load the dll rather it just grabs all existing ones from the project :)



来源:https://stackoverflow.com/questions/22652854/razor-the-type-or-namespace-name-x-could-not-be-found-error-compile-only

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!