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

Notification

Icon
Error

NCrunch with external dependencies
RaringCoder
#1 Posted : Monday, March 26, 2012 2:05:02 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/22/2012(UTC)
Posts: 6

Thanks: 4 times
Hi,

I am trying to use NCrunch with SQL CE 4.0 and it cannot resolve the dependencies. Regular NUnit tests run fine, but NCrunch ones never do. I have noticed that the NCrunch working directory (whenever I happen to remember how to find it) appears to be missing most of the relevant dependencies.

I haven't got any specifics (I'm away from the dev machine at the moment and I can't remember specifically the build error), but is there a general overview somewhere about how to reliably copy all required dependencies for my tests project such that NCrunch can use them?

I've browsed the wiki and found a few articles, but I couldn't get those to work (most likely my fault).

Also, can we control the architecture of NCrunch tests? I always want them running in x86.

Cheers.
RaringCoder
#2 Posted : Monday, March 26, 2012 7:09:37 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/22/2012(UTC)
Posts: 6

Thanks: 4 times
When I have NCrunch in its default configuration, I get the following error on a test that attempts to use the SQL CE managed DLL:

SetUp :
System.Data.SqlServerCe.SqlCeException :
Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8854.
Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details.

When I debug the test, I query the
Code:
System.AppDomain.CurrentDomain.BaseDirectory
for the working directory and get a similar folder path:

C:\Users\RaringCoder\AppData\Local\NCrunch\4764\5\MyApp\bin\Debug

This only contains the DLL of the MyApp.Tests project (where all of my unit tests are located). It doesn't contain any of the references used by the project. Hopefully this is enough information.
Remco
#3 Posted : Monday, March 26, 2012 9:27:50 PM(UTC)
Rank: NCrunch Developer

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

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

If you haven't read it yet, there's a page in the wiki that describes some common problems that can cause test related issues like the one you've described - https://www.ncrunch.net/...-runtime-related-issues

I have a feeling that the library you're using is incompatible with the way NCrunch builds its workspace, so turning on the 'Copy referenced assemblies to workspace' would be the first thing I would try.

You can also force the test runner to run as x86 through your NCrunch project level configuration - though it will use this by default unless you have the assembly set to build as x64. Most likely you're already running as x86.

Let me know if the configuration setting above solves your problem, if not, we'll try something else :)


Cheers,

Remco
1 user thanked Remco for this useful post.
RaringCoder on 3/28/2012(UTC)
RaringCoder
#4 Posted : Tuesday, March 27, 2012 11:14:35 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/22/2012(UTC)
Posts: 6

Thanks: 4 times
Hi Remco,

I tried setting that configuration to copy references on just the test project and set the solution-wide architecture to x86. I then did a resync, rebuild, re-run all and still get the same error unfortunately.
Remco
#5 Posted : Tuesday, March 27, 2012 9:15:59 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Do you have any resource files that the SQL dependency makes use of but aren't included in your project file? You can quickly identify if this is the cause through the following:

1. Right click on the failed test in the tests window
2. Choose Advanced->Browse to workspace
3. Open an explorer window to your test project directory
4. Compare the files that exist between the explorer windows. Check specifically for resource files, binaries and non source files (since if source files were missing, your build will have failed)

If you have any files missing that are being used by the SQL dependency, you can add them using the 'Additional files to include' option under your NCrunch project level configuration.

Does this solve the issue?
1 user thanked Remco for this useful post.
RaringCoder on 3/28/2012(UTC)
Remco
#7 Posted : Tuesday, March 27, 2012 9:17:17 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Also - something else I forgot to mention .. if you haven't already, try turning on that 'Copy referenced assemblies to workspace' for ALL of your projects (not just the test project). Sometimes this makes a difference as the dependency may be deeper down the project tree.
RaringCoder
#6 Posted : Wednesday, March 28, 2012 11:59:56 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/22/2012(UTC)
Posts: 6

Thanks: 4 times
Remco;1555 wrote:
Do you have any resource files that the SQL dependency makes use of but aren't included in your project file? You can quickly identify if this is the cause through the following:

1. Right click on the failed test in the tests window
2. Choose Advanced->Browse to workspace
3. Open an explorer window to your test project directory
4. Compare the files that exist between the explorer windows. Check specifically for resource files, binaries and non source files (since if source files were missing, your build will have failed)

If you have any files missing that are being used by the SQL dependency, you can add them using the 'Additional files to include' option under your NCrunch project level configuration.

Does this solve the issue?

Yeah this helps. My tests project correctly pulls in the native binaries for SQL CE. NCrunch doesn't copy those, I presume because they are referenced by the SQL CE managed DLL as opposed to directly from my project.

If I manually copy those files into the bin\debug of the workspace (after setting "Copy referenced assemblies to workspace" to true for all projects), the NCrunch tests start working.

The folder structure of where these DLLs are located is dictated by Nuget. The "packages" folder is a sibling of the "MyApp.Tests" project folder.

I need to include the folders and files under this root directory:

packages\SqlServerCompact.4.0.8852.1\NativeBinaries

Adding additional files takes a path. Can you provide an example of how I might add these files?
Remco
#8 Posted : Wednesday, March 28, 2012 8:30:37 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
The best option would be to include these packages in your 'Additional files to include' at solution level.

The expression for this would be done as relative to your solution file, and you can use **.* to make sure the entire directory structure is included. For example:

packages\SqlServerCompact.4.0.8852.1\**.*
1 user thanked Remco for this useful post.
RaringCoder on 3/30/2012(UTC)
RaringCoder
#9 Posted : Friday, March 30, 2012 8:59:54 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/22/2012(UTC)
Posts: 6

Thanks: 4 times
Hi Remco,

That didn't work.

However, what did work was having NCrunch run the post-build step. This was added by Nuget to my project without me realising (I checked after that setting fixed NCrunch).

I presume this was required because you copy the entire project into the NCrunch area and compile it again? I was mistakenly assuming that you just copy what was output from my project bin.

Thanks for your help, working wonderfully now.

Adam
Remco
#10 Posted : Saturday, March 31, 2012 1:44:17 AM(UTC)
Rank: NCrunch Developer

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

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

Interesting that Nuget was using a post build step - this doesn't match any of my previous experiences in testing NCrunch with Nuget setup. I'm glad you managed to find a solution, though are you able to share any details on the version of Nuget that you're using? Ideally NCrunch should be handling this situation automatically.

You are correct in your understanding that NCrunch shadow copies the entire project :)


Thanks!

Remco
1 user thanked Remco for this useful post.
RaringCoder on 3/31/2012(UTC)
RaringCoder
#11 Posted : Saturday, March 31, 2012 9:49:22 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/22/2012(UTC)
Posts: 6

Thanks: 4 times
I'm currently using Nuget 1.5.20902.9026, though I don't think issue is with Nuget itself. I was referring to the package for SQL CE 4; when I installed it I believe the package itself configured the post-build step. The post-build takes the native binaries that are found in the SQL CE packages area and copies them in, as in VS you only reference the managed DLL.

The plot thickens slightly, I also need to copy the packages directory using the additional files feature, this is because the post build step looks relatively for the files. I also need to enable "copy references to workspace".

So in summary, all the points you initially stated were required along with enabling post-build steps.

Now I just need to address the speed of the unit tests because it creates a SQL CE database file each time... :-)

Cheers,
Adam
Remco
#12 Posted : Saturday, March 31, 2012 9:15:33 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Thanks for the info - I'll have a bit of a think about this one, as it seems quite SQL-CE specific .. maybe I'll add a warning for when the project has a pre/post build step that NCrunch has deactivated.
memark
#13 Posted : Monday, September 8, 2014 7:55:22 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/26/2014(UTC)
Posts: 9
Location: Sweden

Thanks: 4 times
Was thanked: 3 time(s) in 3 post(s)
I ran into this problem today running our integration tests. Not on my local machine though, but on my NCrunch Grid Server. This thread provided some help. Let me expand a bit on the solution, in case anyone else finds this.

When you install SQL Server CE via Nuget to a project, it adds the following post-build step to the project in question:

Code:
if not exist "$(TargetDir)x86" md "$(TargetDir)x86"
xcopy /s /y "$(SolutionDir)packages\Microsoft.SqlServer.Compact.4.0.8876.1\NativeBinaries\x86\*.*" "$(TargetDir)x86"
if not exist "$(TargetDir)amd64" md "$(TargetDir)amd64"
xcopy /s /y "$(SolutionDir)packages\Microsoft.SqlServer.Compact.4.0.8876.1\NativeBinaries\amd64\*.*" "$(TargetDir)amd64"


This fails because the $(SolutionDir) is not resolved to the "correct" place. In order to get everything to work on the grid server, I had to take these steps:

  1. Activate "Copy referenced assemblies to workspace" for the project in question.
  2. Activate "Run post-build events" for the project in question.
  3. Add "..\packages\Microsoft.SqlServer.Compact.*\NativeBinaries\**.*" to "Additional files to include" for the project in question. The star in the middle is just to avoid hardcoding a specific version number.

(I also had to check in the ".ncrunchproject" file, something I had no need to do before.)
1 user thanked memark for this useful post.
Remco on 9/8/2014(UTC)
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.083 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download