IBM Watson visual recognition c# - c#

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));

Related

Can't get migrations to work: Cannot bind argument to parameter 'Path' because it is null

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.

Pro Asp.Net 2016 nuget Update-Database cmdlet error

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).

Npgsql exception on connection string

I cant get Npgsql connection string to work. I've tried some ways, for example
NpgsqlConnection conn = new NpgsqlConnection("Server=192.168.1.220;User Id=pgsql;Password=pgsql;Database=pgsql;");
or
var conn = new NpgsqlConnection("Host=192.168.1.220;Username=pgsql;Password=pgsql;Database=pgsql");
both throws me exception:
The type initializer for 'Npgsql.NpgsqlConnectionStringBuilder' threw an exception.
Im running Windows XP 64bit with VS 2010. I've already tried to connect from that machine to my pgsql server using ODBC or pgAdmin III - both works ok.
Could be this problem related to my Npgsql installation?
I was not able to install it with NuGet, because I got following error:
PM> Install-Package Npgsql
Installing 'Npgsql 3.2.1'.
Successfully installed 'Npgsql 3.2.1'.
Adding 'Npgsql 3.2.1' to Project.
Uninstalling 'Npgsql 3.2.1'.
Successfully uninstalled 'Npgsql 3.2.1'.
Install failed. Rolling back...
Install-Package : Could not install package 'Npgsql 3.2.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.0,Profile=Client', but the packag
e 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:16
+ Install-Package <<<< Npgsql
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
I've tried also to switch target framework to 4.0 or 3.5, but result was exactly the same.
So I installed Npgsql simply by extracting .dll from MSI installation, then load it as reference.
Does anyone know how to make connection string to work?
You forgot about the port. Maybe this is the cause. The standard PostgreSQL server listening on port 5432.
NpgsqlConnection conn = new NpgsqlConnection("Server=192.168.1.220;Port=5432;User Id=pgsql;Password=pgsql;Database=pgsql;");
Example Connection String
Maybe you haven't a library Mono.Security.dll. It is necessary in the older version less then 3.0 or is enabled the system firewall?

Entity framework 7, visual studio 2015, console commands don't work

I am using the ASP.NET 5 Web application Template (which is using EF7 and MVC 6), the one with the individual User Accounts, and I have the following problem:
When I add my own DBSet to the ApplicationDbContext class, and then going to a page which is trying to use this new DBSet, it doesn't work, I get this:
A database operation failed while processing the request.
SqlException: Invalid object name 'WallMessageModel'.
There are pending model changes for ApplicationDbContext
Scaffold a new migration for these changes and apply them to the database from the command line:
dnx . ef migration add [migration name]
dnx . ef migration apply
Now when I run these commands, or any "dnx" commands I get:
CategoryInfo NotSpecified: Error: Unable t...stemindsWebsite:String, RemoteException FullyQualifiedErrorId : NativeCommandError
And if im trying to run any "k" commands im getting:
CategoryInfo : ObjectNotFound: k:String, CommandNotFoundException FullyQualifiedErrorId : CommandNotFoundException
I'm using "EntityFramework.SqlServer": "7.0.0-beta5", "EntityFramework.Commands": "7.0.0-beta5"
I tried using the 7.0.0-* version and it still doesn't work for me. Can you please tell me what am I doing wrong?
Basically, I believe that EF commands are not installed properly on my machine (via Visual Studio 2015/PowerShell). However, there doesn't seem to be any reference that shows how to get those installed (shouldn't they be built into VS2015 when using EF7?).
When you add another DbSet to your ApplicationDbContext class or add/modify any other existing entity class, your runtime model changes from database model. Hence you need to scaffold a new migration and apply it to database so that both models are in sync with each other. As the exception message suggests, you should run those commands to do that.
For those commands (or any other dnx commands) not running, dnx commands are not built in VS2015. They come from Microsoft ASP.NET and Web Tools extension for visual studio. Please verify that you have it installed for your VS. That will enable you to run dnx commands. k is very old term and it was renamed to dnx. Also beta5 is old version, the latest version is RC1, which has many more features. Detailed information on how to install and use Web Tools is available at https://get.asp.net/

Enable Migrations in MVC throws File not Found Error

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.

Categories

Resources