Template engine in .NET 4 console app

58 views
Skip to first unread message

MotoWilliams

unread,
Apr 12, 2010, 1:43:54 PM4/12/10
to Spark View Engine Dev
In reference to this topic 'Template engine'
http://groups.google.com/group/spark-dev/browse_thread/thread/9411da77994c801c
and 'Using Spark as a general purpose template engine'
http://whereslou.com/2008/12/16/using-spark-as-a-general-purpose-template-engine

Works fine when targeting .NET 3.5. When trying to run the code in
VS2010 targeting .NET 4 it runs into problems with mscorlib.

Any ideas?
Eric Williams

--ERROR AS FOLLOWS--
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.

1
2 [global::Spark.SparkViewAttribute(
3 Templates = new string[] {
4 "sample.spark"
5 })]
6 public class Viewba973fbcc82b4686a5213cfd1edc2138 :
SparkConsole.EmailView
7 {
8
9
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
10 private static System.Guid _generatedViewId = new
System.Guid("ba973fbcc82b4686a5213cfd1edc2138");
11 public override System.Guid GeneratedViewId
12 { get { return _generatedViewId; } }
13
14
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
15 private void RenderViewLevel0()
16 {
17 #line hidden
18 Output.Write("Dear ");
19 #line default
20 try
21 {
22
23 #line 1 "sample.spark"
24 Output.Write(user.Name);
25 #line default
26 }
27 catch(System.NullReferenceException)
28 {
29 Output.Write("${user.Name}");
30 }
31 #line hidden
32 Output.Write(",\r\nThis is an email.\r\nSincerely,\r\nSpark
View Engine\r\n");
33 #line default
34 }
35
36
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
37 public override void Render()
38 {
39 RenderViewLevel0();
40 }
41 }

at Spark.Compiler.BatchCompiler.Compile(Boolean debug, String
languageOrExtension, String[] sourceCode) in c:\Code\Spark\src\Spark
\Compiler\BatchCompiler.cs:line 165
at
Spark.Compiler.CSharp.CSharpViewCompiler.CompileView(IEnumerable`1
viewTemplates, IEnumerable`1 allResources) in c:\Code\Spark\src\Spark
\Compiler\CSharp\CSharpViewCompiler.cs:line 30
at Spark.SparkViewEngine.CreateEntryInternal(SparkViewDescriptor
descriptor, Boolean compile) in c:\Code\Spark\src\Spark
\SparkViewEngine.cs:line 260
at Spark.SparkViewEngine.CreateEntry(SparkViewDescriptor
descriptor) in c:\Code\Spark\src\Spark\SparkViewEngine.cs:line 238
at Spark.SparkViewEngine.CreateInstance(SparkViewDescriptor
descriptor) in c:\Code\Spark\src\Spark\SparkViewEngine.cs:line 220
at SparkConsole.Program.Main(String[] args) in C:\Users\user
\Documents\Visual Studio 2010\Projects\SparkConsole\Program.cs:line 29

MotoWilliams

unread,
Apr 19, 2010, 2:56:54 PM4/19/10
to Spark View Engine Dev
Now that .NET 4 has RTM'ed - could someone from the dev team comment,
verify and or suggest a solution?

On Apr 12, 10:43 am, MotoWilliams <ericwilliam...@gmail.com> wrote:
> In reference to this topic 'Template engine'http://groups.google.com/group/spark-dev/browse_thread/thread/9411da7...
> and 'Using Spark as a general purpose template engine'http://whereslou.com/2008/12/16/using-spark-as-a-general-purpose-temp...
--
You received this message because you are subscribed to the Google Groups "Spark View Engine Dev" group.
To post to this group, send email to spar...@googlegroups.com.
To unsubscribe from this group, send email to spark-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spark-dev?hl=en.

Louis DeJardin

unread,
Apr 19, 2010, 5:10:44 PM4/19/10
to spar...@googlegroups.com
I'll need to look into that. Will reply as anything is learned.

attilah

unread,
Apr 21, 2010, 6:47:55 PM4/21/10
to Spark View Engine Dev
If you're setting the version CompilerOptions within BatchCompiler.cs
at line 60 from 3.5 to 4.0 to look like this:

var providerOptions = new Dictionary<string, string>
{ { "CompilerVersion", "v4.0" } };

it will works like a charm.

The root of the problem is that the running .Net version is 4.0 and
mscorlib is added by default as a referenced assembly. When specifying
3.5 it causes a conflict.

Maybe this problem can be mitigated by checking the hosting
environment's version and use that as a setting for CompilerVersion
property in batch compiler.

hth,
Attila
> For more options, visit this group athttp://groups.google.com/group/spark-dev?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "Spark View Engine Dev" group.
> To post to this group, send email to spar...@googlegroups.com.
> To unsubscribe from this group, send email to spark-dev+...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/spark-dev?hl=en.- Idézett szöveg elrejtése -
>
> - Idézett szöveg megjelenítése -

Charles Strahan

unread,
Apr 22, 2010, 5:22:00 PM4/22/10
to spar...@googlegroups.com
Would this do the trick?

var version = string.Format("v{0}.{1}",
System.Environment.Version.Major, System.Environment.Version.Minor);
var providerOptions = new Dictionary<string, string> { {
"CompilerVersion", version } };

-Charles

attilah

unread,
Apr 23, 2010, 10:32:24 AM4/23/10
to Spark View Engine Dev
There is a problem with that.

When you targeting .Net 3.5 from an application this version number
will be 2.0 and not 3.5!!!

Framework version is NOT runtime version, so this does not help us
here.

- Attila


On Apr 22, 11:22 pm, "Charles Strahan" <charles.c.stra...@gmail.com>
wrote:
> athttp://groups.google.com/group/spark-dev?hl=en.-Idézett szöveg elrejtése
> -
>
> > - Idézett szöveg megjelenítése -
>
> --
> You received this message because you are subscribed to the Google Groups
> "Spark View Engine Dev" group.
> To post to this group, send email to spar...@googlegroups.com.
> To unsubscribe from this group, send email to
> spark-dev+...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/spark-dev?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "Spark View Engine Dev" group.
> To post to this group, send email to spar...@googlegroups.com.
> To unsubscribe from this group, send email to spark-dev+...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/spark-dev?hl=en.- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages