I was just wondering if anyone has successfully got Spark to work in a .NET 4.0 console application for compiling templates to HTML. Unfortunately I am getting the following error:
Unhandled Exception: Spark.Compiler.CompilerException: Dynamic view compilation failed.
(0,0): error CS1703: An assembly with the same identity 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' has already been imported. Try removing one of the duplicate references.
However, when I target .NET 3.5 everything works fine, however I specifically wish to target 4.0. Has anyone solved this problem, some old threads on the Spark mailing list suggest I may just have to edit a line in the source, and recompile, but I hope this is a last resort.
EDIT:
static void Main(string[] args)
{
if (args.Length > 0)
{
var templatePath = Path.Combine(Environment.CurrentDirectory, args[0]);
var templateName = Path.GetFileName(templatePath);
var templateDirPath = Path.GetDirectoryName(templatePath);
var viewFolder = new FileSystemViewFolder(templateDirPath);
var sparkEngine = new SparkViewEngine
{
DefaultPageBaseType = typeof(SparkView).FullName,
ViewFolder = viewFolder.Append(new SubViewFolder(viewFolder, "Shared")),
};
var descriptor = new SparkViewDescriptor().AddTemplate(templateName);
var view = sparkEngine.CreateInstance(descriptor) as SparkView;
view.Model = args[1];
using (var writer = new StreamWriter(new FileStream(args[2], FileMode.Create), Encoding.UTF8))
{
view.RenderView(writer);
}
}
else
{
Console.WriteLine(">>> error - missing arguments:\n\tSparkCompiler.exe [templatepath] [modelstring] [outputname]");
}
}