Build/Test Issues

Problem using NCrunch with FSharp.Data.SqlClient

Started by simonhdickson on 6,754 views

In my test I'm trying to mock out database access which I'm using the F# Sql Command type provider for. The project with the type provider code in builds fine in NCrunch. But when I try to create an instance of the record in my test project, the test project doesn't build in NCrunch (it builds normally with VS & msbuild and runs fine in the standard xnunit test runner).

To give a minimum example:


// In Data Project
type MyQuery = SqlCommandProvider<"SELECT hello FROM dbo.world", connectionString>

// In Test Project
[<Fact>]
let test () =
    MyQuery.Record("hello") |> ignore


System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.Reflection.AssemblyName.nInit(RuntimeAssembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent)
at System.Reflection.AssemblyName..ctor(String assemblyName)
at Gallio.Common.Reflection.Impl.CecilReflectionPolicy.GetAssemblyReferences(StaticAssemblyWrapper assembly)
at Gallio.Common.Reflection.Impl.StaticAssemblyWrapper.<GetReferencedAssemblies>b__2()
at Gallio.Common.Memoizer`1.Memoize(Func`1 populator)
at Gallio.Common.Reflection.Impl.StaticAssemblyWrapper.GetReferencedAssemblies()
at Gallio.Model.DefaultTestFrameworkManager.SelectTestFrameworksForCodeElementsImpl(IEnumerable`1 filteredTestFrameworkHandlesWithoutFallback, TestFrameworkFallbackMode testFrameworkFallbackMode, TestFrameworkOptions testFrameworkOptions, IEnumerable`1 codeElements)
at Gallio.Model.DefaultTestFrameworkManager.FilteredTestDriver.DescribeImpl(IReflectionPolicy reflectionPolicy, IList`1 codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
at Gallio.Model.BaseTestDriver.Describe(IReflectionPolicy reflectionPolicy, IList`1 codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
at nCrunch.Module.Gallio.Integration.GallioWrapper.FindFrameworkTestsInAssembly(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths)
at nCrunch.Module.Gallio.Integration.GallioTestFramework.FindFrameworkTestsInAssembly(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths, ComponentUniqueName testComponentUniqueName)
at nCrunch.TestExecution.TestFinder.FindTestsForFrameworks(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths, TestFrameworkDescription[] frameworks, ComponentUniqueName testComponentUniqueName)
at nCrunch.Compiler.StaticManipulation.BuiltAssembly.DiscoverTests(TestFrameworkDescription[] applicableTestFrameworks, ComponentUniqueName testComponentUniqueName)
at nCrunch.Compiler.RemoteBuildRunner.(ComponentBuildParameters , FilePath , BuildOutput , DirectoryPath[] , FilePath[] )
at nCrunch.Compiler.RemoteBuildRunner.Build(ComponentBuildParameters parameters)
Hi,

Thanks for sharing this issue. NCrunch does have some known compatibility problems with FSharp type providers. There are ways you can work around these issues - see http://forum.ncrunch.net/yaf_postst1203_Making-NCRUNCH-aware-of-additional-reference--for-which-there-is-no-code--just-dlls.aspx for more information.

The error you're receiving is coming from the static analysis code invoked by Gallio to discover tests. It's possible that you won't see this for other test frameworks .. and I do hold a hope that the above type provider workaround may solve the issue. Let me know how you get on. If you still see the error with the workaround in place, I may need to ask for a sample solution to help reproduce the problem in order to understand it better.


Cheers,

Remco
Hi,

I encountered the same problem (first missing *.DesignTime.dll and now -- HResult). I've also put a sample solution to github: https://github.com/skalinets/ncrunch-type-providers
It uses VS2013 Community and NCrunch 2.10.0.4.
Could you please take a look?

Thanks :)

Edited

Hi, thanks for sharing the sample solution! I'll take a look and will get back to you :)


Cheers,

Remco
Hi, just an update on this one...

This looks to be caused by some strange structural problems around how the assembly references are being physically declared inside the test assembly.

The problem doesn't appear if you set your 'Framework utilisation type for Gallio/Xunit' to 'DynamicAnalysis' - This is a solution-level NCrunch configuration option. I hope that adjusting this setting will allow you to work around the problem.

Alternatively you can also look towards using a later version of Xunit. Xunit V2 is in an advanced beta state and it is also supported by NCrunch.

I'm implementing a fix for this problem that will allow NCrunch to function normally with the Static Analysis enabled. This will be included in the full release of 2.11.

Sorry for the time it's taken to get back to you on this one.


Cheers,

Remco

Post a reply

Log in to reply.