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

Notification

Icon
Error

NCrunch Fails to build "Async for .NET Framework 4, Silverlight 4 and 5, and Windows Phone 7.5"
lprichar
#1 Posted : Friday, July 12, 2013 8:08:12 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/12/2013(UTC)
Posts: 41
Location: United States of America

Thanks: 4 times
NCrunch fails to build my .Net 4.0 MVC project when I add a reference to "Async for .NET Framework 4, Silverlight 4 and 5, and Windows Phone 7.5" via Nuget. More specifically it fails on the call to:

System.Threading.Tasks.TaskEx.WhenAll(...);

with an error of:

The type or namespace name 'TaskEx' does not exist in the namespace 'System.Threading.Tasks' (are you missing an assembly reference?)

MSBuild / Visual Studio build fine. I've tried turning on the compatibility modes as described here: http://www.ncrunch.net/d...ing_compatibility-mode, but no luck.

I've submitted a bug report so you should be able to find diagnostic info if needed.

Any help would be greatly appreciated, I feel lost without my NCrunch (awesome product, btw).

Thanks,
Lee
lprichar
#2 Posted : Saturday, July 13, 2013 1:29:09 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/12/2013(UTC)
Posts: 41
Location: United States of America

Thanks: 4 times
FYI you can reproduce this from scratch in Visual Studio 2012 like this:

1. Create a New project of type "ASP.NET MVC 3 Web Application" using .NET Framework 4
2. Add a reference via Nuget to "Async for .NET Framework 4, Silverlight 4 and 5, and Windows Phone 7.5"
3. Create a class and method and in it put: "TaskEx.WhenAll(null);"

Visual Studio will compile and nCrunch will give something like "Class1.cs (13)#0: The name 'TaskEx' does not exist in the current context"

Incidentally this scenario works fine for command line projects, so it must be something specific to web projects. I noticed the project modifies the web.config to add some assembly bindings like this:

<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
</dependentAssembly>

But that shouldn't have anything to do with the compiler, right? Anyway, I would love some help here, nCrunch is awesome and I'd really like to get it back as asap.

Thanks,
Lee
Remco
#3 Posted : Saturday, July 13, 2013 6:14:12 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Lee,

Thanks for sharing this issue and for the detailed reproduction instructions.

I followed the instructions above, but sadly it seems to be working normally for me. I think there must be another variable in here somewhere.

I noticed in the bug report that your web project has quite a few conflicting references (i.e. it looks as though its trying to use two different versions of MVC side-by-side). I'm not sure whether this is responsible for the missed reference resolution, but this sort of thing can cause inconsistent behaviour.

Is there any chance you might have a sample solution you can share with me? If so, you're welcome to submit anything via the contact form on this site.


Cheers,

Remco
lprichar
#4 Posted : Saturday, July 13, 2013 1:36:24 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/12/2013(UTC)
Posts: 41
Location: United States of America

Thanks: 4 times
Thanks for the response and analysis Remco. I would imagine my main project would be harder to debug. I am surprised about the conflicting MVC versions, that shouldn't be the case, I'll look into it. But for now let's focus on the simple out of the box project that I mentioned in post #2.

Since those repro steps don't work for you I tried upgrading from nCrunch 1.45.0.12 to the latest (1.46.0.11) but sadly that didn't help. Next I uploaded the sample project (DeleteMe.sln) to the contact form you mentioned to see if that works for you. It shouldn't be any different since I just followed the steps in #2, but maybe we'll get lucky and it will fail for you.

Assuming DeleteMe.sln works for you, what other external things could be different? machine.config? Version/Edition of Visual Studio?

Thanks again for your help,
Lee
lprichar
#5 Posted : Saturday, July 13, 2013 1:54:58 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/12/2013(UTC)
Posts: 41
Location: United States of America

Thanks: 4 times
FYI I tried loading my DeleteMe.sln project on a second, nearly new computer and it gets the same problem. One more possible difference between our environments: I use ReSharper. That's the only other plugin I have installed on the newer computer.
Remco
#6 Posted : Monday, July 15, 2013 3:48:03 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Thanks for sending through the sample solution. This wasn't easy to figure out, but I think I've established what is happening here.

The binding redirection in the Web.config file is critical to the build for this project, as it looks like these libraries have some dependency issues and they rely on build-time redirections to sort these out.

In order to make these binding redirections work inside the build process, the package includes a special build step (inside Microsoft.Bcl.Build.targets) that overrides normal .config resolution behavior to make it work with web applications and find the web.config - which explains why this has been failing for you on the web application and not on the console app.

NCrunch has been unable to find the Microsoft.Bcl.Build.targets file because the logic used to import it into the project is using a relative path that makes a dangerous assumption about the working directory of MSBuild. Build imports usually make use of MSBuild variables to specify a root path when importing a project (i.e. "$(MSBuildProjectDirectory)\..\packages\Microsoft.Bcl.Build.1.0.7\tools\Microsoft.Bcl.Build.targets"), although this one is just straight relative to an unrooted location (..\packages\Microsoft.Bcl.Build.1.0.7\tools\Microsoft.Bcl.Build.targets), which in most build situations (excluding NCrunch) seems to be consistent with the project's directory.

The Microsoft.Bcl.Build.targets file further introduces more assumptions about the working state of the MSBuild process by checking for the existence of files without specifying a root location for these files (assuming that the MSBuild default will always be the same directory as the host project, which is not necessarily true).

Basically, this framework has been coded with a number of assumptions about build state that just don't hold during an NCrunch build. I've introduced some pending fixes to NCrunch to try and align this better with the defaults that this framework is expecting, but I can't get it 100% as NCrunch still relies on the MSBuild API which does not seem to behave consistently with what this project expects.

So anyway, to work around the issue, just add this to your project file:

<PropertyGroup>
<AppConfig>Web.config</AppConfig>
</PropertyGroup>

This crudely replicates the workaround in the imported framework to make use of the Web.config so that the binding redirections will kick in.

I hope this does the trick!


Cheers,

Remco
1 user thanked Remco for this useful post.
lprichar on 8/14/2013(UTC)
lprichar
#7 Posted : Friday, July 26, 2013 8:06:21 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/12/2013(UTC)
Posts: 41
Location: United States of America

Thanks: 4 times
Remco, thank you so much for the detailed analysis. I'm sorry for the delay. I found a temporary workaround (return null, and just don't check in that file), but I would like to solve it for real. Well, that and I'm not getting e-mail notifications on this forum despite having signed up for them.

Anyway, that PropertyGroup hack helped. I'm a little further, I think. The problem now is that dependent projects are still failing (e.g. the unit test project). NCrunch reports errors like: using statements are invalid for namespaces defined in my main project.

I tried adding in the PropertyGroup hack you mentioned but with App.Config, but it didn't seem to help. Any thoughts? I can try to reproduce on the sample project.
Remco
#8 Posted : Friday, July 26, 2013 10:37:49 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
The PropertyGroup hack above in theory shouldn't be needed for App.Config files, as the Bcl build above should be able to detect these by default. I think this is the results of another problem. Does putting NCrunch into compatibility mode make any difference?

Sorry for the lack of notification from the forum. It seems to be having some issues at the moment - I'm looking into it.
lprichar
#9 Posted : Monday, August 5, 2013 12:41:29 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/12/2013(UTC)
Posts: 41
Location: United States of America

Thanks: 4 times
It really isn't another problem. nCrunch was working fine until I added this dependency. And again, when I return null rather than returning TaskEx.WhenAll (my workaround), then everything works perfectly. I put NCrunch in compatibility mode as instructed, but as expected it still fails. By the way adding a one click compatibility mode would be very nice for debugging stuff like this.

I've updated DeleteMe.sln again to demonstrate: https://www.dropbox.com/...vcytqnd7vt4u/nSkbZBAZix/
Remco
#10 Posted : Monday, August 5, 2013 1:15:23 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Thanks again for the sample solution. I'm having some trouble in reproducing the issue. It seems as though the sample solution isn't bringing it out for me. It builds and runs the single test correctly under NCrunch with no signs of any error.

Strangely, it doesn't build outside of NCrunch. When I try build using Visual Studio, it complains about the tests project not referencing Microsoft.Build.Bcl. I guess NCrunch's resolution logic must somehow work around this.

Are you able to share any more detailed information, or perhaps a sample project with a different arrangement that might surface the issue? The sample you sent for the Web.Config issue was very useful - there's no way I could have come up with the workaround without it.
lprichar
#11 Posted : Monday, August 5, 2013 7:23:33 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/12/2013(UTC)
Posts: 41
Location: United States of America

Thanks: 4 times
You're right, it wasn't building in Visual Studio. I added the NuGet reference to "Async for .NET Framework 4, Silverlight 4 and 5, and Windows Phone 7.5" to the unit test project and now it compiles in Visual Studio, but still fails to compile in nCrunch.

Interestingly, I noticed that it *does* run the unit test (unlike my real project). But yet on the "NCrunch Tests" tab it says it fails to compile with the error:

Class1Test.cs (1)#0: The type or namespace name 'MvcApplication1' could not be found (are you missing a using directive or an assembly reference?)

This is the same error I get in my real project, so I think this is worth chasing down.

What version of NCrunch are you using? I'm on 1.46.0.20.

So your version of DeleteMe compiled for you in nCrunch, even though it didn't in Visual Studio? Or perhaps did it run the test but not compile like for me?

If our versions of NCrunch are the same and yours is compiling, the only other thing I can think to do to get it to reproduce for you is to start up a VM and share that via Dropbox. Seems a bit extreme though, and quite a bit of work. I love nCrunch enough I'm willing to do it, but I'd like to see if you have any other suggestions. If not, does VirtualBox format work for you?

Thanks,
Lee
Remco
#12 Posted : Monday, August 5, 2013 10:46:14 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Lee,

I was testing this using 1.46.0.20 in a clean VM. I'm wondering if somehow the issue may be related to the SDKs or frameworks you have installed on your machine. Build behaviour can be affected by a huge range of factors outside the solution itself. Are you able to share any details on the setup you're using? Which versions of Visual Studio and the .NET framework do you have installed? Are you testing using VS2012 or the VS2013 preview?

I'm hoping we can avoid the need for you to build a whole VM just to surface this issue.. it's a bit of a job. Is there any chance you can submit a bug report right after the build has failed? I'd really like to see a full build log if we can get one.


Thanks!

Remco
lprichar
#13 Posted : Tuesday, August 13, 2013 2:24:59 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/12/2013(UTC)
Posts: 41
Location: United States of America

Thanks: 4 times
Yes, outside factors is about all that's left I'm afraid. Which probably means if I build a clean VM it will work fine :(.

Visual Studio 2012, and obviously .Net 4 (assuming we're both still working on the DeleteMe solution). I just submitted a bug report. Hopefully there's something in there that can help.

I'll wait to hear back before I build a VM. Seems like a last resort kind of thing to do.

p.s. I mentioned ReSharper as another plug-in that's installed earlier, but I forgot to mention Web Essentials is there too.
Remco
#14 Posted : Tuesday, August 13, 2013 10:36:26 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Thanks for sending the bug report. This helped highlight some interesting information:

The primary reference "C:\Users\Lee\AppData\Local\NCrunch\17572\1\MvcApplication1\bin\MvcApplication1.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "C:\Users\Lee\AppData\Local\NCrunch\17572\1\MvcApplication1\bin\MvcApplication1.dll" or retarget your application to a framework version which contains "System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

The primary reference "C:\Users\Lee\AppData\Local\NCrunch\17572\1\MvcApplication1\bin\MvcApplication1.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "C:\Users\Lee\AppData\Local\NCrunch\17572\1\MvcApplication1\bin\MvcApplication1.dll" or retarget your application to a framework version which contains "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

I'm wondering if this is somehow related to the binding redirection issue we experienced earlier. It still doesn't make any sense to me why this is appearing on your system but not mine... Perhaps there is some difference in the various SDKs that are loaded or available in the GAC. Does introducing a .config file in the tests project with the appropriate binding redirections make any difference for you?

I'm wondering if you'd also like to try giving this build a spin - http://downloads.ncrunch.net/NCrunch_VS2012_1.47.0.1.msi. This build introduces some changes in the way that references are resolved at load time by NCrunch... which may or may not make a difference in this situation.

These new packages from Microsoft contain all sorts of new build logic including several overrides, so I have a feeling it may take a while to fully understand what is happening here. Let me know how you go with the above suggestions, and if neither of them work, we'll try something else.
1 user thanked Remco for this useful post.
lprichar on 8/14/2013(UTC)
lprichar
#15 Posted : Wednesday, August 14, 2013 8:34:56 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/12/2013(UTC)
Posts: 41
Location: United States of America

Thanks: 4 times
Woot! That did it! Thank you Remco! Thought I'd tried that one already. For future reference the exact app.config file that fixes for the unit test project (once you've already added the PropertyGroup/AppConfig mentioned in Post #6 to your main project) is:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>


Cheers,
Lee

p.s. e-mail notifications are now working again.
Remco
#16 Posted : Wednesday, August 14, 2013 9:42:02 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Excellent! Just to clarify - was it the app.config change that did the trick, or the new build, or both?
lprichar
#17 Posted : Wednesday, August 14, 2013 11:05:13 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/12/2013(UTC)
Posts: 41
Location: United States of America

Thanks: 4 times
Just the app.config. That fixed it in DeleteMe.sln and my real project. I didn't try the 1.47.0.1 build you mentioned.
Remco
#18 Posted : Wednesday, August 14, 2013 11:11:41 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Great. Thanks for letting me know. I've noted this down for a review, as if things were working correctly, such a change shouldn't really be necessary.
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.128 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download