I am new to Asp.Net Core. While reading Adam Freeman's book on Asp.Net Core (2016)
I have done everything properly prior to my problem, however, I can not create database tables using Update-Database Project manager console command as said in the book. Similar topics did not help me. Here is the error.
Invoke must be called on a background thread.
Update-Database : 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:1
+ Update-Database
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Update-Database:String) [],
Comman
dNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
What version of ASP.NET Core did you select when created the project?
Did you add both Microsoft.EntityFrameworkCore.SqlServer and Microsoft.EntityFrameworkCore.Tools packages, did you do that via the Nuget manager or by editing your .csproj and what versions of that packages did you add?
In the book he adds packages by editing project.json which is no more supported and is replaced by PROJECT_NAME.csproj.
Make sure your dependencies were added and there are no warning signs (In Solution Explorer, expand your project tree. Check if required packages are listed in Nuget section under the "Dependencies" and there is no yellow warning triangle sign on the item).
Related
When I trying to add Nuget Packages by Nuget gallery extension from VS Code. It doesn't install the NuGet package.
Executing task: dotnet add /home/[user]/Public/Projects/yogihosting.com/Identity/Identity/Identity.csproj package Microsoft.AspNetCore.Identity.EntityFrameworkCore -v 5.0.6 -s https://api.nuget.org/v3/index.json <
Determining projects to restore...
Writing /tmp/tmpIIHQRz.tmp
info : Adding PackageReference for package 'Microsoft.AspNetCore.Identity.EntityFrameworkCore' into project '/home/[user]/Public/Projects/yogihosting.com/Identity/Identity/Identity.csproj'.
info : Restoring packages for /home/[user]/Public/Projects/yogihosting.com/Identity/Identity/Identity.csproj...
error: Unable to load the service index for source https://api.nuget.org/v3/index.json.
error: The SSL connection could not be established, see inner exception.
error: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot
Usage: NuGet.CommandLine.XPlat.dll package add [options]
Options:
-h|--help Show help information
--force-english-output Forces the application to run using an invariant, English-based culture.
--package Id of the package to be added.
--version Version of the package to be added.
-d|--dg-file Path to the dependency graph file to be used to restore preview and compatibility check.
-p|--project Path to the project file.
-f|--framework Frameworks for which the package reference should be added.
-n|--no-restore Do not perform restore preview and compatibility check. The added package reference will be unconditional.
-s|--source Specifies NuGet package sources to use during the restore.
--package-directory Directory to restore packages in.
--interactive Allow the command to block and require manual action for operations like authentication.
--prerelease Allows prerelease packages to be installed.
The terminal process "/bin/bash '-c', 'dotnet add /home/[user]/Public/Projects/yogihosting.com/Identity/Identity/Identity.csproj package Microsoft.AspNetCore.Identity.EntityFrameworkCore -v 5.0.6 -s https://api.nuget.org/v3/index.json'" terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.
How can I get rid of this problem?
https://api.nuget.org/v3/index.json shows:#
Note: I'm using Ubuntu.
We may solve this issue by one of following process.
copy project to another folder or create new project to another destination.
It may cause, our file or folder is corrupted.
Reinstalling our software(s) like IDE or dotnet or both.
It may cause not to be installed correctly.
The final is so funny. Re-install your OS and then other softwares.
I'm taking a course in MVC that was recorded in 2016, so maybe that has to do with this error. It says to open NuGet console and type in "Enable-Migrations" in order to enable Entity Framework. But when I type that I get all sorts of error messages and yes I double-checked to make sure I'm doing everything the instructor is. I tried different versions of EF in Nuget Package Manager and the error messages change but still happen.
PM> Enable-Migrations
Enable-Migrations : Cannot bind argument to parameter 'Path' because it is null.
At line:1 char:1
+ Enable-Migrations
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Enable-Migrations], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Enable-Migrations
First off, why is this even necessary? From what I've seen of EF and LINQ so far I'd rather code in machine language, but in courses I took before that used EF we never had to do "Migrations" before so I'd like to solve this error message but I don't even see the point of it. I thought I read somewhere that Microsoft in its infinite wisdom has changed the way we do migrations but can't find any updated documentation.
Type following command in package manager console.
dir
or
pwd
pwd show you the path of current directory.
dir list down all folders of current directory. if package manager console is not set to project directory, run
cd "YouProjectDirectory"
and run
Enable-Migrations
If you install required packages in this case entitty framework core packages, it will run successfully.
I'm trying to develop an ASP.Net app ( software app or the web) in visual studio 2013 OR 2015 that uses IBM Watson Visual Recognition service.
I have seen the examples for QA service but it is outdated with the Watson credentials and functionality.
the example: (it requires username and password as credentials, which are not supplied anymore when creating a service):
http://www.nechai.net/2016/07/05/invoking-the-web-api-of-ibm-watsons-speech-to-text-service-from-net/
This example that I have found looks updated to today's credentials ( the API Key instead of username and pass) but I can't import, open or use the sub projects inside it, visual studio does not know how to recognize it)
"https://github.com/watson-developer-cloud/visual-recognition-aspnet"
the two inner projects that the project rely on are VisualRecognition and WatsonServices projects in the main project.
They have a project file with the xproj extension file, which visual studio 2013 AND 2015 seems to not recognize so I can't try it or reuse its code in my test app.
the above example project is too complicated to just grab the code and try it (after failing to import and making it work on VS 2013)
Is there a very simple example on how to connect to a watson service using this type of credentials? :
"credentials": {
"url": "https://gateway-a.watsonplatform.net/visual-recognition/api",
"note": "It may take up to 5 minutes for this key to become active",
"api_key": "********************************************************"
}
I have also tried to install the Watson services SDK by Nuget and by downloading the source and opening it in VS (for visual recognition specifically and the whole services option as well) but with no luck as well.
When opening the source code in VS, it says "incompatible" with all the files.
"https://github.com/watson-developer-cloud/dotnet-standard-sdk"
When trying to install with Nuget I get Errors:
in VS2013:
Install-Package: Could not install package 'IBM.WatsonDeveloperCloud.VisualRecognition.v3 1.0.0'. You are trying to install this package into a project that targets '.NETFram
ework,Version=v4.6', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
At line:1 char:1
+ Install-Package IBM.WatsonDeveloperCloud.VisualRecognition.v3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
in VS 2015:
Install-Package : An error occurred while retrieving package metadata for 'Newtonsoft.Json.10.0.3' from source 'd:\Users*****\Documents\Visual Studio 2015\Projects\FaceDetection\packages'.
At line:1 char:1
+ Install-Package IBM.WatsonDeveloperCloud.VisualRecognition.v3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
There is no example on how to use or install the SDKs except for using Nuget so I'm lost here.
The Watson Developer Cloud .NET Standard SDK has been updated to 1.1.0. Please try to update the packages. You can see examples of how to invoke the service in the readme for the service.
Additionally, there is an example file of how to invoke the service in the examples directory of the github repo.
Basically you instantiate the service
private VisualRecognitionService _visualRecognition = new VisualRecognitionService();
Set the credentials
_visualRecognition.SetCredential(apikey);
And call the API (classify in this example)
var result = _visualRecognition.Classify(<image-url>);
You should be able to traverse the result object to get the classification results
if (result != null)
{
foreach (ClassifyTopLevelSingle image in result.Images)
foreach (ClassifyPerClassifier classifier in image.Classifiers)
foreach (ClassResult classResult in classifier.Classes)
Console.WriteLine(string.Format("class: {0} | score: {1} | type hierarchy: {2}", classResult._Class, classResult.Score, classResult.TypeHierarchy));
}
You can also see the result in json format by serializing the result object
Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
I have a new ASP.net 5 dnx class library I am using for entity framework. I need to target EF 6 because some features I need are not in EF 7.
First the EF tools (like enable-migration) were not there. I added an old style class library and installed EF 6 and now the commands are there.
When I run enable migrations I get this error:
PM> Enable-Migrations
Exception calling "SetData" with "2" argument(s): "Type
'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject'
in assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation,
Version=14.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is
not marked as serializable." At
D:\Projects\Rebus\FMS\Code\Current\FMSSupport\FMSSupport\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:720
char:5
+ $domain.SetData('startUpProject', $startUpProject)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SerializationException System.NullReferenceException: Object reference not set to an instance
of an object. at
System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetProjectTypes(Project
project, Int32 shellVersion) at
System.Data.Entity.Migrations.Extensions.ProjectExtensions.IsWebProject(Project
project) at
System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String
configurationTypeName, Boolean useContextWorkingDirectory) at
System.Data.Entity.Migrations.EnableMigrationsCommand.FindContextToEnable(String
contextTypeName) at
System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0()
at
System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action
command) Object reference not set to an instance of an object.
I have tried different options for enable-migration such as specifying a startup project or the contextTypeName.
Any ideas?
Following this recommendation, EF6 data projects should use the existing .NET Framework class library csproj type.
Even after following the recommendations, I was still getting the same error. Unloading your ASP.NET Core project(s) and then invoking the Enable-Migrations command on the appropriate csproj should allow the command to execute. You can unload a project by right-clicking on the .NET Core project and choosing the 'Unload Project' option. It should also be noted that the Package Manager Console window has a 'Default project:' drop-down selection. You should choose the project with your DbContext.
It's because ASP.NET Core introduced a new project type/configuration system (see package.config vs project.json) and the old EF tools don't know how to work with the newer system (project.json). It would probably be easiest to create a new project and port your code into it if you want to go back to EF6.
Interestingly (well, disappointingly actually) they're backtracking on project.json see:
http://xoofx.com/blog/2016/05/11/goodbye-project-json/
I had the same issue. Just setting the start project from ASP.NET Core to my .NET Framework Lib does the trick for me =) Now i can do EF6 migrations as usual "Add-Migration" command...
P.S. Sorry for my eng.
I'm new to using MVC, and when working through the tutorials regarding migrations in Visual Studio 2013 I appear to have broken the tie-in to EntityFramework in the Package Manager console.
I believe this started when I updated the EntityFramework to version 6.1.3, But that appears to be incompatible with the MVC Controller scaffolding. So I rolled it back to version 5.0.0.
When I now enter the command enable-migrations
I get the following error:
Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'EntityFramework, Version=5.0.0.0
, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified."
At D:\ss\CAP\CAP_MVC_Dev_2\CAP_MVC\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:431 char:31
+ $domain.CreateInstanceFrom <<<< (
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodTargetInvocation
The file EntityFramework.psm1 exists where it is described above, but the error appears to be in that file? How is $domain.CreateInstanceFrom missing, and where from? Uninstalling and reinstalling the EntityFramework package makes no difference.
I've tried creating new projects from scratch and this error persists across them. An uninstall/reinstall of Visual Studio 2013 has not resolved the issue either, nor has destroying the connected database and starting again with an empty one.
So, it turns out the solution was similar to this one
Entity Framework code first migrations throwing error
When I first attempted this solution there were reports of gacutil not being recognised. Due to the environment I work it it is not simple to add the gacutil to be universally recognised (I believe), so i found the gacutil.exe in the file system, copied that to the lib\net45 folder referenced in the linked post, and then ran the command
gacutil /i EntityFramework.dll
This has resolved the problem, and i no longer receive the 'File not Found error'
Instead of installing with GAC, I came to the following solution (VS2013 SP5 + EF 5):
Copied (Solution dir)\packages\EntityFramework.5.0.0 (entire directory)
to
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\EFTools\NuGet Packages\
The NuGet Packages directory did not exist, so one needs to create it manually.