Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Tests that use RazorEngine get odd exception when NCrunch is the runner.
jbuedel
#1 Posted : Tuesday, March 13, 2012 4:07:06 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/2/2012(UTC)
Posts: 6
Location: Saint Louis, MO

Was thanked: 2 time(s) in 2 post(s)
I am using a text templating engine called RazorEngine to format some text for an email (not to be confused with the MVC Razor stuff - RazorEngine is an enabler for using the Razor view syntax outside of Mvc iews).

The RazorEngine seems to be doing some compiling at runtime. When the unit test is run via NCrunch, I get this error:

Code:

RazorEngine.Templating.TemplateCompilationException : Unable to compile template. The predefined type 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias; using definition from 'c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Remco Software\NCrunch for Visual Studio 2010\nCrunch.TestExecution.dll'


When the test is run via R#:

Code:
RazorEngine.Templating.TemplateCompilationException : Unable to compile template. 'ClassLibrary1.AnonymousClass' does not contain a definition for 'userName' and no extension method 'userName' accepting a first argument of type 'ClassLibrary1.AnonymousClass' could be found (are you missing a using directive or an assembly reference?)


Note, the template clearly has a bug (@Model.userName should be @Model.Name). Fixing the bug seems to make it work. Also using an anonymous type instead of a concrete class changes things as well. This does seem to imply that at runtime my code is being linked up to NCrunch dlls. That doesn't seem right. I haven't put this into production yet, so I don't yet know if there is a real dependency on NCrunch dlls yet.

A sample project is here: https://s3.amazonaws.com...o304q/ClassLibrary1.zip

Remco
#2 Posted : Tuesday, March 13, 2012 9:01:50 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,986

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi,

Thanks for posting and for sharing the sample project. I can assure you that there is no static linking between your code and the NCrunch binaries, and there won't be any mention of NCrunch in your production code. Basically this is a runtime issue that has occurred because of an extension method clash inside the execution environment (which is controlled by NCrunch). Does the problem cause you any serious issues with day-to-day working? Or is it just that the error message is confusing?


Thanks!

Remco
jbuedel
#3 Posted : Thursday, March 15, 2012 2:43:34 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/2/2012(UTC)
Posts: 6
Location: Saint Louis, MO

Was thanked: 2 time(s) in 2 post(s)
Once I figured out what was going on I can easily work around it. (Just rely on R# or NUnit and ignore NCrunch until that particular test is passing). See, the NCrunch error hides the RazorEngine error. But once the RazorEngine error is fixed the NCrunch error also goes away. So no, it is not causing me serious issues anymore.
Remco
#4 Posted : Thursday, March 15, 2012 9:00:50 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,986

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Thanks - I've noted it down for a later look :)
james
#5 Posted : Tuesday, February 25, 2014 9:59:29 AM(UTC)
Rank: Member

Groups: Registered
Joined: 3/13/2013(UTC)
Posts: 24
Location: United Kingdom

Thanks: 6 times
Was thanked: 6 time(s) in 6 post(s)
Just hit this. Spent 20min trying to find a resolution. Would be great if NCrunch would display the correct error message. It's shame to have to flick between test runners.

I can foresee that, when these tests break, another developer will spend another 20+ minutes trying to solve a problem that doesn't exist. :(
1 user thanked james for this useful post.
Remco on 2/25/2014(UTC)
Remco
#6 Posted : Wednesday, February 26, 2014 12:54:55 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,986

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
I regret that this problem cannot be solved within NCrunch.

NCrunch defines the System.Runtime.CompilerServices.ExtensionAttribute to work around a compiler issue that results from needing to have backwards compatibility with older toolsets. Removing the declaration simply isn't possible without unplugging support for older toolsets, or introducing a whole new specialised version of NCrunch (overkill).

My understanding about this error message is that it is actually a warning. I have no knowledge of the internal workings of Razer, but my assumption is that whatever code is responsible for displaying the true compile error is confusing the warning with an error, and displaying the warning instead .. meanwhile, the real error is not shown.

You may want to look at raising this issue with the RazerEngine team.


Cheers,

Remco
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.063 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download