Last week, everybody was talking about the final release of Visual Studio 2017. I have to admit, I was excited too so of course I installed it! At the beginning, everything seemed to be just fine. Nothing forecasted a few hours of google’ing to solve the problems that occurred later.
When I installed VS2017, I have to do some of the strange tricks described in my previous post. There were errors claiming that my project lacks some Nuget package, which was of course installed but I knew the solutions so that was cool, really. In the end, adding migration started to work so I felt some kind of relief.
But the problem came back when I wanted to fire the Update-Database command. I received the following error:
Could not load file or assembly 'System.Data.SqlClient, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Here we go again! Problem no 1.
I tried to downgrade this package, but it was coming back to the version 4.3 just a few moments after I clicked ‘Update‘ button in Nuget Package Manager. With no error or warning message! That’s strange…
I googled a lot to solve this problem! Of my, I searched the whole Internet, seen all the kittens’ images and still no reasonable solution for problem with Update-Database in VS2017. That’s sad, shame on you, nasty Internet!
At that moment, I even decided to let it go, come back to VS2015, eat a bar of chocolate and write a post entitled ‘Why I will never ever use VS2017‘. And get a lot of fame and FB likes because of that.
I found a solution!
That’s right – I did it! At exactly 2 AM two days later I read this short article. This guy is right! EF seems to need System.Data.SqlClient in version 4.3 (although VS tells you to downgrade to version 4.1). So what does it error mean? Ha! Let me show you the whole message:
Do you see the yellow highlighted part? Yeah, I finally saw it too! So I set the ReMaster (previously ReMaster.Web – migrating to VS2017 changed its name o.0 ) as the startup project. Opposite to the situation from the last post (about VS2015), where I wrote that I needed to set EF project as startup!
BTW To make things perfectly clean, let me remind you my project’s structure:
Error no 2
Yay! This time it looked better.
Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Solution no 2
Of course I have this package in ReMaster.EF project. Sooo I installed it in ReMaster (the Web one) project. Genius, isn’t it? 😉
Error no 3
Ok, I tried again to update DB and got the following error:
Could not load assembly 'ReMaster.EntityFramework'. Ensure it is referenced by the startup project 'ReMaster'.
In fact, I want all my EF migrations in ReMaster.EntityFramework project. And I don’t really see a reason to have some reference between ReMaster (previously ReMaster.Web) and ReMaster.EntityFramework. Buuuut…
Solution no 3
It seems that VS2017 has an opposite opinion at this subject :). So in ReMaster I added reference to ReMaster.EF.
… Did I say that I have opposite opinion? Forget it, it was a great idea, VS2017 is a fantastic IDE because I got only…
One more error!
Could not load file or assembly 'Microsoft.Extensions.Logging, Version=188.8.131.52, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
The last solution!
So I just installed Microsoft.Extensions.Logging in my ReMaster project.
And updating database started to work!
Visual Studio, you pugnacious animal, I still love you!