Closed JasonFoglia closed 10 years ago
I figured this out, but I wondering if it has to work this way.
Basically, I had to create or not a dummy class in Html5 project, then created an instance of this class before running the Compile code on Template.
var dummy = new Html5.Dummy();
var template = Template.WithBaseType() .AddNamespace("Html5") .Compile("@Html5.Tag.Create(\"div\", \"test\")"); // Worked!
Jason, thank you. I will investigate this strange behavior.
Volkovku, the behavior seems to be expected or as designed. Your method GetLoadedAssemblies() says it all. I wonder tho, if I am referencing Html5 in my project is there away to reference the assemble in RazorTemplates, even if it's not loading into the current domain? Oh and thank you for your work! Great stuff!
Here is how I ended up doing it so far. Yeah its definitely the GetLoadedAssemblies(), I don't think there is a way to improve it, since .Net removes assembly references it thinks are not being used. You'd have to get the referenced assemblies before its gone through the compiler...
var useful1 = typeof(HtmlString);
var outputBody = _templateService.Parse<T>(outputTemplate, model, null, typeof(T).Name);
@Eibwen I'm glad you got it working
@Jason54 @Eibwen @volkovku I needed this and it was actually pretty easy to fix. If anyone is still interested, I can add a PR although the project no longer seems active.
@lvermeulen thanks for you interest. Unfortunately in last years I have no time to support this project. But I can review and merge you pull request.
@volkovku That's great! PR submitted.
Html5 is a separate project.
var template = Template.WithBaseType()
.AddNamespace("Html5")
.Compile("@Html5.Tag.Create(\"div\", \"test\")"); // Fails
error CS0246: The type or namespace name 'Html5' could not be found (are you missing a using directive or an assembly reference?)
There is a reference to the project and there is a using directive at the top of the code.