1

I have a CodedUI Test project in Visual Studio 2013. After following instructions for integrating SpecFlow with the CodedUI API, I'm getting the following error in the FeatureSetup (Assembly binding logging was turned on)

Test Name: TheWelcomeScreen

Test FullName: (...)Feature.TheWelcomeScreen

Test Source: c:\path\to\My.feature : line 6

Test Outcome: Failed

Test Duration: 0:00:00

Result Message: Class Initialization method (...)Feature.FeatureSetup threw exception. System.IO.FileNotFoundException: System.IO.FileNotFoundException: Could not load file or assembly 'SpecFlow.Assist.Dynamic, Version=1.0.2.0, Culture=neutral' or one of its dependencies. The system cannot find the file specified.

=== Pre-bind state information ===

LOG: DisplayName = SpecFlow.Assist.Dynamic, Version=1.0.2.0, Culture=neutral
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: SpecFlow.Assist.Dynamic, Version=1.0.2.0, Culture=neutral | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Path/To/Current/TestResults/Directory/Out
LOG: Initial PrivatePath = NULLCalling assembly : TechTalk.SpecFlow, Version=1.9.0.77, Culture=neutral, PublicKeyToken=0778194805d6db41.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Path\To\Current\TestResults\Directory\Out\BWE.Tests.DLL.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Path/To/Current/TestResults/Directory/Out/SpecFlow.Assist.Dynamic.DLL.
LOG: Attempting download of new URL file:///C:/Path/To/Current/TestResults/Directory/Out/SpecFlow.Assist.Dynamic/SpecFlow.Assist.Dynamic.DLL.
LOG: Attempting download of new URL file:///C:/Path/To/Current/TestResults/Directory/Out/SpecFlow.Assist.Dynamic.EXE.
LOG: Attempting download of new URL file:///C:/Path/To/Current/TestResults/Directory/Out/SpecFlow.Assist.Dynamic/SpecFlow.Assist.Dynamic.EXE.

Result StackTrace:

at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at TechTalk.SpecFlow.Infrastructure.BindingAssemblyLoader.Load(String assemblyName)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at TechTalk.SpecFlow.Infrastructure.TestRunnerFactory.Create(Assembly testAssembly)
at TechTalk.SpecFlow.TestRunnerManager.CreateTestRunner(TestRunnerKey key)
at TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(TestRunnerKey key)
at TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(Assembly testAssembly, Boolean async)
at TechTalk.SpecFlow.TestRunnerManager.GetTestRunner()
at (...)Feature.FeatureSetup(TestContext testContext) in c:\path\to\My.feature.cs:line 0

My packages.config file for this solution:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="AutoMapper" version="3.3.0" targetFramework="net40" />
  <package id="CompareNETObjects" version="3.01.0.0" targetFramework="net40" />
  <package id="ImpromptuInterface" version="6.2.2" targetFramework="net40" />
  <package id="SpecFlow" version="1.9.0" targetFramework="net40" />
  <package id="SpecFlow.Assist.Dynamic" version="1.0.2" targetFramework="net40" />
</packages>

In the "Properties" for the SpecFlow.Assist.Dynamic DLL, the CopyLocal setting is set to true. After building the solution, the bin\Debug folder has SpecFlow.Assist.Dynamic.dll in it, but the folder for the current test run in the TestResults folder does not contain this DLL. It does contain these DLLs:

  • The DLL for my project
  • AutoMapper.dll
  • KellermanSoftware.Compare-Net-Objects.dll
  • TechTalk.SpecFlow.dll

I've opened and closed Visual Studio, uninstalled and reinstalled the NuGet package, deleted the package sources locally, cleaned, rebuilt, rebooted, manually removed the bin\Debug folder and rebuilt... The list goes on. I'm still getting the same exception.

Sam Holder
  • 32,535
  • 13
  • 101
  • 181
Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
  • are you actually using the reference in your tests? It sounds ike it'll be fixed by switching to NUnit rather than MSTest OR by adding that dll as a deployment item in one of the tests to ensure that it gets copied to the test run directory by MSTest. This seems like a hack though, I'm not sure why its not working out of the box... – Sam Holder Jul 31 '15 at 08:23
  • As it turns out I'm not using SpecFlow.Assist.Dynamic. I removed that NuGet package and things are working fine now. That's not really a "solution" but worked because I wasn't using it. – Greg Burghardt Aug 03 '15 at 15:02
  • and if you had used it MSBuild would have included it in the test deployed files I think. ?we've seen similar before where we had to place a dummy reference to a class in an assembly just to get VS to deploy it along with the tests – Sam Holder Aug 03 '15 at 15:05
  • I'm just compiling through Visual Studio, not using MsBuild from the command line. The SpecFlow.Assist.Dynamic.dll file was not in the test directory. It was in the bin\Debug directory, though. – Greg Burghardt Aug 03 '15 at 15:54
  • sorry meant MSTest not MSBuild. in my experience MSTest only deploys files that have classes that are used by the test code or the code under test, so even if an assembly is referenced, if you use types only through reflection the assmbly won't be deployed – Sam Holder Aug 03 '15 at 15:59
  • Ah, ok. And that's exactly what was happening. It was dynamically loading SpecFlow.Assist.Dynamic.dll from a setting in the project's App.config file. – Greg Burghardt Aug 03 '15 at 16:01
  • then a simple solution is to have a 'dummy' reference to a class in the assembly in your test code, and then MSTest will see that it is actually being used and will deploy the assembly. – Sam Holder Aug 03 '15 at 16:02

1 Answers1

1

I don't know if it by design or not but MSTest does not deploy assemblies to the test folder unless at least one type from that assembly is used in the tests or code under test. So if you are instantiating types from and assembly by reflection then you'll run into issues.

This issue has been noted by others.

The simple solution is to do one of two things:

  • Use a dummy type from the assembly in question in your tests. Just do a redendant var dummy = new TheType()
  • Use a deployment item to copy the dll. This is less good I think as you might not get it deployed unless you are running a test which has the deployment item on it, which could mean you need to use the attribute several times, although I'm not 100% sure about that.
Community
  • 1
  • 1
Sam Holder
  • 32,535
  • 13
  • 101
  • 181