Spaceman
Spaceman

Reputation: 1337

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

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 :)

Upvotes: 1

Views: 2153

Answers (1)

Spaceman
Spaceman

Reputation: 1337

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 :)

Upvotes: 1

Related Questions