Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generation error: Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0 " or one of its dependencies

I'm getting the following error seemingly randomly when I try generate my .feature files.

Occasionally I change or alter my feature file, and this error crops up out of nowhere:

#error Generation error: Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I have absolutely no idea how to solve this - I have tried adding a reference to the assembly, changing versions of SpecFlow / NUnit but nothing seems to work.

Erasing my copy of the project and pulling it from source control works initially but then it happens again.

Here is a full list of my installed packages:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.2" targetFramework="net461" />
  <package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net461" />
  <package id="Microsoft.Data.Edm" version="5.8.2" targetFramework="net461" />
  <package id="Microsoft.Data.OData" version="5.8.2" targetFramework="net461" />
  <package id="Microsoft.Data.Services.Client" version="5.8.2" targetFramework="net461" />
  <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
  <package id="NUnit" version="3.0.0" targetFramework="net461" />
  <package id="NUnit3TestAdapter" version="3.9.0" targetFramework="net461" />
  <package id="SpecFlow" version="2.2.1" targetFramework="net461" />
  <package id="SpecFlow.NUnit" version="2.2.1" targetFramework="net461" />
  <package id="System.ComponentModel.EventBasedAsync" version="4.0.11" targetFramework="net461" />
  <package id="System.Dynamic.Runtime" version="4.0.0" targetFramework="net461" />
  <package id="System.Linq.Queryable" version="4.0.0" targetFramework="net461" />
  <package id="System.Net.Requests" version="4.0.11" targetFramework="net461" />
  <package id="System.Spatial" version="5.8.2" targetFramework="net461" />
  <package id="WindowsAzure.Storage" version="8.6.0" targetFramework="net461" />
</packages>

I'm running Visual Studio Community 17 (15.5.2), .NET 4.7.02556 and the SpecFlow extension version 2017.1.10

like image 554
Aimee Jones Avatar asked Dec 15 '17 13:12

Aimee Jones


People also ask

Why am I getting ‘could not load file or assembly’ errors?

Especially while installing a new dev machine, and building your project for the first time, you may end up getting the following exception: Could not load file or assembly ‘ [assemblyname]’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

Why can’t I build my project on a new Dev machine?

Especially while installing a new dev machine, and building your project for the first time, you may end up getting the following exception: Could not load file or assembly ‘[assemblyname]’ or one of its dependencies. An attempt was made to load a program with an incorrect format. No fear, though, as this is usually easily fixed.

What does error an attempt was made to load an incorrect format?

An attempt was made to load a program with an incorrect format. No fear, though, as this is usually easily fixed. In quite a few cases, it’s simply a mismatch between architectures and easily changed. The latter part of the error message should point you to the right direction.


4 Answers

What sometimes works for me is deleting the packages folder from the solution path, then restore nuget packages in solution and regenerate the feature files.

Sometimes this is not enough, and you also have to delete the visual studio cache. Which is located: %LOCALAPPDATA%/Microsoft/Visual Studio/<your VS version>/ComponentModelCache

like image 193
Lars Celie Avatar answered Oct 20 '22 13:10

Lars Celie


This is a known issue, which we couldn't yet reproduce and fix.

GitHub Issue: https://github.com/techtalk/SpecFlow/issues/857

like image 20
Andreas Willich Avatar answered Oct 20 '22 12:10

Andreas Willich


It's a Microsoft package issue. This solution worked for me. Issue disappeared and now builds successfully.

In your Azure Build Pipeline > NuGet tool installer step, change Version of NuGet.exe to install to a newer version, like 5.4.0.

Check Nuget's latest ReleasedAndBlessed version at https://dist.nuget.org/tools.json.

like image 1
Alfred Wallace Avatar answered Oct 20 '22 11:10

Alfred Wallace


The fix for me was to remove the existing .feature.cs file(s) and then regenerate them.
I'm using Visual Studio 2017 15.5.1 and the following SpecFlow versions:

SpecFlow Version:2.2.0.0
SpecFlow Generator Version:2.2.0.0

The followin github thread, gave me the clues:
Visual Studio 2017 Generation error: Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0

like image 1
Ralph Willgoss Avatar answered Oct 20 '22 12:10

Ralph Willgoss