Closed CZEMacLeod closed 5 years ago
This issue started for us after we migrated our projects to PackageReference. In other solution where we have some projects with EF not yet migrated to PackageReference it somehow works, error is still displayed at the end but all EF commands do their job. Unfortunately I can't post any logs from this environment.
including mentioned MsBuild references by @avonwyss and calling MSBuildLocator.RegisterDefaults() results now in this error: System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)
I've had the same issue just changed the devenv.exe.config file to use the full path instead of the relative path.
<dependentAssembly>
<assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="2.0.0.0-99.0.0.0" newVersion="15.1.0.0"/>
<codeBase version="15.1.0.0" href="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Build.Framework.dll" />
</dependentAssembly>
@johanjvr I tried your solution but it didn't work for me :( Restarting VS2017 works sometimes and it seems to be currently the only workaround?. This is very annoying... @ajcvickers please consider giving this issue a higher priority. Thanks Regards
@johanjvr I tried your solution but it didn't work for me :( Restarting VS2017 works sometimes and it seems to be currently the only workaround?. This is very annoying... @ajcvickers please consider giving this issue a higher priority. Thanks Regards
Hi @LeonardoX77, I've found the problem eventually it was caused by a dynamic filter which I've added to the Constructor:
SetFilterScopedParameterValue
I was using the variable which was still null at the time. This I found by enabling the Fusion logging maybe try enabling it and see if you can find the reason why it's giving you this error.
Johan
Hi @johanjvr Thanks for your reply. Sorry, could you please provide more details about what constructor and variable are you talking about and if I can follow this guide to enable Fusion logging? Thanks Leo
My project is not using PackageReference and I still have the issue so this does not appear to be a factor.
In my case this error occurs only when running the Seed method, and more specifically, only when the overridden SaveChanges
method attempts to access System.Web.HttpContext.Current for audit logging purposes - which normally simply returns null when called via Update-Database.
This may be fixed in 6.3.0-preview8--this area of the code was changed significantly while adding support for .NET Core
I'm running 16.4.1 and I'm seeing this same issue during Update-Database
:
System.IO.FileNotFoundException: 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.
File name: 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
not fixed. worse, this is a regression, this is when re-running migrations that used to work.
Also in 16.4.2
I had the same issue several times and always used to resolve it with a VS restart (which is annoying, because for a big solution and when using ReSharper, Task Runner, etc. it takes a long time for everything to start).
But this time, restarts were no longer working (tried to restart it like 4 times, running Clean solution, etc.) and I was desperate as I was under time pressure and couldn't add migrations I needed... I finally tried the suggested fix and replaced this line in
devenv.exe.config
:<codeBase version="15.1.0.0" href="..\..\MSBuild\15.0\Bin\Microsoft.Build.Framework.dll" />
With this one (I'm using VS 2017 Community 15.5.0):
<codeBase version="15.1.0.0" href="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Build.Framework.dll" />
Then I restarted VS and it started working again. When I searched for a solution on Google, it seemed that many people are having the exact same issue...
I use EF 6.2.0.
This works for me
With VS2017 15.4 or 15.5 (Preview), I regularly get a fail when adding or applying migrations due to the 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.
The result from e.g. Update-Database is
Obviously my class library and main project do not include any references to MSBuild Framework and the update does work at runtime.
Closing VS and re-opening then running the command before doing anything else sometimes seems to resolve the issue. I did find a proposed solution online which involved editing
DevEnv.exe.config
and replacing the relative path for the codebase element with an absolute path - although this doesn't seem to have worked in my case.This could be a red-herring however, as the solution said to close VS, edit the .config and then re-open which in my case seems to resolve the issue (temporarily) anyway.
Adding that section to my web.config results in a different error
Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)
Any guidance or ideas?
N.B. this happens to me with both EF 6.1.3 and the latest 6.2.0-beta2-60920 and I am targeting net461.