I am getting some wonky behavior in Visual Studio for MacOS. I recently installed .NET Core 2.1 SDK and then upgraded a project from 2.0 to 2.1. I wanted to try out the new Data Seeding feature, which lets us seed data into an entity in an override of OnModelCreating method.
modelBuilder.Entity<Role>().HasData(
new Role { ID = 1, Name = "Administrator", RoleType = 0 },
new Role { ID = 2, Name = "Application User", RoleType = 0 });
Initially, that will build. Then I open a command line and type the command:
dotnet ef migration add v001
The result is "build failed". Then when I go into VS and build, it fails. I have restarted VS and can repeat this over and over. Initially, the project builds without error. Then only after attempting to add the EF migration, the build error appears. The code completion does show the HasData method and I seem to be using it properly. I suspect I am hitting a tooling bug here and appreciate any recommendations on how to get around this.
The problem was that I had not followed a migration step that is required when migrating from .NET Core 2.0 to 2.1:
Replace the version specified "Microsoft.AspNetCore.All" package reference with the versionless "Microsoft.AspNetCore.App" package reference. You may need to add dependencies that were removed from "Microsoft.AspNetCore.All"
This is documented here:
https://learn.microsoft.com/en-us/aspnet/core/migration/20_21?view=aspnetcore-2.1
Can someone help me with this problem??. I want use "Reverse Engineering Code First" with entity framework used MySQL. I was installed odbc, connector .net etc but still I cant see this... I did everything in this topic (and I have this same problem): Can't use a MySQL connection for entity framework 6
but still doesnt work :(. I was record all steps what I do it.. (Sry for english): https://youtu.be/xqEgCsu7_eU
I've gotten it to work with MySql Connector 6.9.11. Its so darned difficult and fragile I'm not sure if it was ultimately a good idea. There are at least 10 things that can go wrong and suck up hours of time. Once you get it working be very careful to not change anything. Anyhow. Here's some of my notes:
WARNING use with MySQL server 5.6.39 or 5.7.19. Do NOT use MySQL server version 5.7.21 (it fails with reverse eng) Aurora seems ok.
Install "mysql-connector-net-6.9.11.msi". There seems to be a problem with newer MySQL Connector 6.10 ?? use older 6.9.11. MUST INSTALL VIA msi file. Having the local file is not enough.
Install "mysql-for-visualstudio-1.2.8.msi" or "mysql-for-visualstudio-1.2.7.msi" ? NOTE: 1.2.7 will never uninstall correctly. VS 2015 seems to require "MySQL for Visual Studio" for EF Poco to work, (Pro,Enterprise are different)
Must have "Entity Framework Power tools Beta 4" installed as a plugin to Visual Studio 2013. Its takes some effort to get it to install for 2015, 17 but it can be done.
https://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d
Things that can go wrong:
ISSUE 1:
you get error "One or more errors occurred while processing template 'Entity.tt'."
This ALWAYS happens the first time i use reverse engineer after restarting VS.
Simply changing the .NET assemmbly version seems to do the trick. Target .NET 4.5 (not 4.5.1) for reverse engineer.
use .net4.5 for EF. If you see exception "System.ArgumentException: Empty path name is not legal."
remember to change back to 4.5.2 or greater.
VS2015 Edit and Continue is supported for 64-bit projects that target the .NET Framework 4.5.1. (or 4.5.2)
ISSUE 2:
System.ArgumentException: The specified store provider 'MySql.Data.MySqlClient' cannot be found in the configuration, or 'MySql.Data.MySqlClient' is not valid.
This appears to be an app/web.config issue.
??? MySql.Data.MySqlClient has more than 1 entry in in app.config ?? or bindingRedirect is wrong ?? might be wrong version consistently 6.9.11 ? MySql.Data.MySqlClient
?? Install correct version 6.9.11 in GAC not just nuget ? mysql-connector-net-6.9.11.msi
ISSUE 3:
MySQL issue - "error 6003: The value for column 'IsPrimaryKey' in table 'TableDetails' is DBNull." Specified cast is not valid.
[1 Jan 2016 15:27] "Noman Khan. Run the following command on the MySQL DB and then try if this works. set global optimizer_switch='derived_merge=off'" (on the user you will use. i.e root)
ISSUE 4:
Out of memory execption. Restart VisualStudio.
ISSUE 5:
If "MySQL" option doesnt display in the "Change Data source" listbox. Install the Visual Studio MySQL Plugin
Can't use a MySQL connection for entity framework 6
NOTE:
EntityFrameworkPowerToolsBeta4 is not built for VS2015 or 17. The installer version must be modified for it to install
How to use Entity Framework Power Tools in Visual Studio 2015?
http://thedatafarm.com/data-access/installing-ef-power-tools-into-vs2015/
NOTE:
You can view the Generated SQL query by debugging/break on the object prior to deferred execution of the query.
You can Use Aliases to map to other db's
Watch out for poor pluralization rules like "Statu" to "Status"
Check out https://us.visualstudiogallery.msdn.microsoft.com/ee4fcff9-0c4c-4179-afd9-7a2fb90f5838/view/Discussions
This seems to be more configurable and better supported. But only works for MSSQL?
I create a console application in Visual Studio 2015 RC and add Automapper 3.3.1 using nuget to the project.
If I then add the following snippet to my project:
public class Class1
{
public void Test()
{
AutoMapper.Mapper.Map<B>(new A());
}
}
And then open the same project in Visual Studio Code preview on Windows 10 then I get a red squiggly on the Map function.
The error message says:
The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.
My project is configured to use .NET 4.52 and there are absolutely no errors or warnings when building the same project using visual studio 2015 RC or using MSBuild from the command line.
Automapper is portable class library and this is what seems to trigger the problem.
Is this a known issue with Visual Studio Code or Omnisharp?
Are there any way to suppress these error messages?
Update:
I have now tested with VS Code version 0.3 and it is still not fixed.
To make it even simpler to reproduce I have also verified that the problem also exist for a ClassLibrary project containing only the 3 classes: Class1 as shown and class A and class B, which are just two dummy classes used to have something to map.
It does not matter which version of Visual Studio is used to create the project. The same problem exist if I create the class library project using VS 2013.
Maybe you added the reference in both dnx451 and dnxcore50 in project.json file.
I think the problem is Automapper did not support .NET Core 5.0, please refer this article for more detail about .NET core 5.0 and .NET framework 4.6.
http://blogs.msdn.com/b/cesardelatorre/archive/2014/11/18/what-is-net-core-5-and-asp-net-5-within-net-2015-preview.aspx.
This might be the limitation of multi-environment in .NET Core 5.0 when using available libraries. You should write by yourself or waiting for other libraries update if you want to use, otherwise, please remove dnxcore50 in project.json.
Happy coding!
This is actually a known issue with the OmniSharp-roslyn server which powers VS Code, see: https://github.com/OmniSharp/omnisharp-roslyn/issues/265
I suspect you might have better luck using the yeoman ASP.NET 5 generator to generate an ASP.NET 5 Console application.
See: http://docs.asp.net/en/latest/client-side/yeoman.html
And http://docs.asp.net/en/latest/dnx/console.html
I am trying out an existing .NET 4.0 solution in VS2012 on a test machine (that only has VS2012 and SQL Server 2008 installed), and am getting the above error when I try to use the lambda syntax with the Include extension method.
The existing version of the solution has a reference to EntityFramework.dll, which is the one I had to add to use the Include method, but the upgraded version I'm looking at in VS2012 does not have such a reference, nor can I find a DLL of that name in the location it was on the other machine. The using statement for System.Data.Entity is greyed out, as ReSharper thinks it isn't needed. Don't know why.
Sample code: This is what is in the existing solution...
using (var context = new RSSFeedsEntities()) {
WebSite someSite = context.WebSites.Include(w => w.Feeds).FirstOrDefault(w => w.WebSiteID == 1);
}
Any idea how to solve this? Thanks
Ah ha! Found the answer.
Microsoft, in their, ahem, wisdom, made the (in my opinion) blindingly stupid decision not to have Entity Framework install like other bits of the development rack, but instead made the recent versions only available as NuGet packages. Why on earth they did this is beyond me, as I now have to install EF separately for every solution, instead iof installing it cone and having it available immediately.
Anyway, I used the NuGet package manager to install EF 5.0, and the error went away.
Hope this helps someone.
I am using EF5 beta1 and while I was able to run the "Update-Database" before. Now that I shut down Visual Studio, I cannot get it to run. I get the following error:
The term 'Update-Database' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:16
+ Update-Database <<<< -verbose
+ CategoryInfo : ObjectNotFound: (Update-Database:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I have tried to re-install EF5b1 and while was successful (already installed), the 'Update-Database' still does not work.
Can anyone help???
The solution is to close the Package Manager Console, close Visual Studio and then reopen them.
Rebooting also worked most of the time, but not always.
If you use Entity Framework:
Error Message:
"Error Message (from the Update-Database command in the PMC):
The term 'Update-Database' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."
Solution:
Exit Visual Studio. Reopen project and try again.
For more information please visit: Advanced Entity Framework 6 Scenarios for an MVC 5 Web Application (12 of 12)
For anyone who is using .Net Core and EntityFrameworkCore:
You will need to install Microsoft.EntityFrameworkCore.Tools package to resolve this issue.
Read more here: https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell
Reinstalling the nuget package fixed this issue for me
ie, execute
Install-Package EntityFramework -Version 5.0.0
in the package manager
Sometimes when I load VS, I see this in my package manager console:
Value cannot be null.
Parameter name: path1
I have no idea what causes that yet but it seems that something goes wrong during the start-up of the Powershell console which interrupts the registering of specific modules, such as the EF powershell extensions. You can just manually load it however:
Import-Module .\packages\EntityFramework.6.1.1\tools\EntityFramework.psm1
Make sure you replace 6.1.1 with whatever your current version of Entity Framework is.
you will get this error when the EF tools are not installed properly.
try the below command in Nuget package manager
//Uninstalls and install the same Version of EF
Update-Package "EntityFramework" -reinstall
If you still face the same issue.
create a new Web Project and run the below command in nuget.
(Note : no need to create the new Project in the same solution or
same location.)
// This will update EF to latest version(including the tools)
// if you want to use specific version , use the -version flag.
Update-Package "EntityFramework"
Once this is done, chcek your original project and you can delete the newly created project.
Just restart Visual Studio, it'll solve the problem. Works for me.
Install Microsoft.EntityFrameworkCore.Tools solved the issue for me, used nuget packages
I solved this by uninstalling and reinstalling Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.Tools
I had this same problem, and the origin of it was on my path name, I had on my path a directory name with straight brackets, like this: C:\[PROJ]\TestApp.
When I removed the brackets, to C:\PROJ\TestApp, it started to work just fine...
Just ReOpen visual studio is work for me
For me the problem was the Nuget version.
uninstall Nuget Package Manager.
restart Visual Studio.
installed new version of Nuget Package Manager.
then re-start Visual Studio again.
This problem seems to happen when you open the project directly from File Explorer. Try starting VS first and then opening the project - worked for me. I'm guessing this is about access to paths.
Most of the time those beta versions have some issues, also if Entity Framework failed to load and also this can happen if you are install the Microsoft.EntityFrameworkCore.Tools globally. try to install it locally into your project
. you can try these steps until you fix the issue. and remember this method is not to fix the issue this is the other way to do this.
cd in to your project directory. not the sln directory to the project directory.
then dotnet ef to find out that you have correctly install the Entity Framework.
then use dotnet ef migrations add "ReplaceThisWithSomeText" command. And this will create new migration.
then use dotnet ef database update to update the database.
Migrations Overview. This will helps too..
Windows commands - cd
(This Is for EFCore projects)
If the other answers don't work (VS 2017): clear the NuGet cache, restart VS, then restore the packages.
I found that it was due to a corrupt package. I had installed Automapper when it was already installed. It was only clear that this package was corrupt when I tried to install another package.
Removing the corrupt package solved this issue for me.
You can then reinstall automapper. The issue was with version 5.4, I am now happily on 6.0.
For me it turns out EntityFramework core was not installed on my project (because i started with blank project). So installing EntityFramework package resolved the problem. Sometimes if EntityFramework installation failed then try to install individual packages one by one
E.g.
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.SqlServer.Design
Microsoft.EntityFrameworkCore.Tools
I solved by updateing Package Manager Console.
I was not getting Update-Database in Package Manager Console. Then i restart several time. Also restart Windows.
Then I download new one from nuget and then it was solved.
I had this problem in Visual Studio 2015 and resolved it by updating the version of Nuget.
Tools -> Extensions and Updates -> Updates -> Visual Studio Gallery
Simple fix for me was to make sure there was a dash between update and database, like this: update-database and use lowercase. It may be coincidental, but when I did this in Packet Manager Console, the database actually updated and I got the done message rather than the not recognized as the name of a cmdlet, function, script file error.
I started having the same issue after I accidentally opened a Visual Studio solution with Visual Studio 2015 instead of 2017. The project worked just fine before that mishap. It was an older project with EF 5.0 and not EF Core.
I tried everything suggested - restarted Visual Studio countless times, cleaned up NuGet cache, deleted everything in packages folder, reinstalled EF 5 for the project - no good, add-migration was not recognized. If I upgraded EF to 6, it started to recognize the commands, but I did not want to upgrade yet. So, as soon as I reverted back to EF 5, the problem returned.
The only thing that finally saved me was to do the following:
close Visual Studio
delete everything from packages folder
delete .vs folder in the root of your solution. This folder is usually hidden, you have to turn on Show hidden files and folders setting or check Hidden items in folder View tab
start Visual Studio and open your solution. It will ask to restore NuGet packages, agree to it.
Now EF commands finally started working again.
In my case:
Reload project did not help
Restart VS did not help
Restart computer did not help
Reinstal EF did not help
But I found an article where suggestion was to manualy import missing EF package, using PM Conole:
Import-Module .\packages\EntityFramework.X.X.X\tools\EntityFramework.psm1
And this solution solved my problem.
In my case restarting Visual Studio (many, many times) did not work, then as I was looking elsewhere I found a message on the output terminal:
The current .NET SDK does not support targeting .NET Core 2.2. Either
target .NET Core 2.1 or lower, or use a version of the .NET SDK that
supports .NET Core 2.2.
So I installed the required version of .NET Core and the command ran successfully.
I had this problem in VS 2019 with an existing project using EntityFramework 6.3.0. This project had some strange version changes done to it over a period of time, and nothing would get it working. I believe I tried every suggestion listed here with no luck.
Finally, updating to the pre-release version of EntityFramework (currently 6.4.0-preview3-19553-01) did fix the problem, by running this in the Package Manager Console: Update-Package EntityFramework -prerelease. I'm hopeful that when this version is released live in the next few weeks it will work properly.
In my case, I did the following:
- restored missing NuGet packages by clicking "Restore" button on top of the Package Manager Console
- restarted Visual Studio
- run update-database
Restoring NuGet package didn't help me.
I had to reinstall package manager - https://visualstudiogallery.msdn.microsoft.com/4ec1526c-4a8c-4a84-b702-b21a8f5293ca
For me the problem was the Nuget version.
I removed and re-installed Nuget then re-started Visual Studio and then all started working.