I want to include Stanford CoreNLP in my Unity3D project. I included CoreNLP from Nuget and downloaded the NLP models from CoreNLP. Then I copied the NLP model folder into the project -> bin -> Debug folder.
The code looks like this:
var jarRoot = #"stanford-corenlp-3.9.1-models\";
const string text = "Kosgi Santosh sent an email to Stanford University. He didn't get a reply.";
var props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
props.setProperty("sutime.binders", "0");
var curDir = Environment.CurrentDirectory;
Directory.SetCurrentDirectory(jarRoot);
var pipeline = new StanfordCoreNLP(props);
Directory.SetCurrentDirectory(curDir);
// Annotation
var annotation = new Annotation(text);
pipeline.annotate(annotation);
var sentences = annotation.get(typeof(CoreAnnotations.SentencesAnnotation));
if (sentences == null)
{
return;
}
foreach (Annotation sentence in sentences as ArrayList)
{
System.Console.WriteLine(sentence);
}
After running, I only got some Error info
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for
further details.
I searched SLF4J site however the solution only applies to Java project. How do I supposed to solve this in my C# project?
First, go to the Visual Studio (I have VS 2017). Then go to the Tools menu and select NuGet Package Manager->Package Manager Console. The Package Manager Console will appear. Type this command: Install-Package slf4j-NetCommonLogging -Version 1.7.5.4 and press Enter key. The VS will install slf4j-NetCommonLogging dll file for your project and it will run correctly without any errors or warnings. Enjoy.
Related
I want to use MediaToolkit from Nuget Package Manager and in my test projects, the tool worked fine in VB.NET and C#.NET project. However, when I use it in my real project (which has been upgraded many times to higher version in VB.NET), I am always receiving an error attached screenshot. In my test project and real project, both are in .NET 4.6.
string videoPath = Server.MapPath("~/Video/" + fileUpload.FileName);
var inputVideoFile = new MediaFile { Filename = videoPath };
using (var engine = new Engine())
{
engine.GetMetadata(inputVideoFile);
}
duration = inputVideoFile.Metadata.Duration;
Could you please help me to resolve the issue?
I have a VS 2017 extension and have tried using my own custom Project Template, by adding it programmatically, but things aren't going so well.
In my endeavour to find the mistake, I would like to see whether it is my custom Project Template causing the problem or not. Therefore I want to programmatically add any other existing built-in VS project such as a ClassLibrary type project template.
It seems to be located here:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ProjectTemplates\CSharp\Windows\1033\
But there isn't a zip folder and I can't create one in that directory according to Windows.
I will be using something similar to the following code:
Solution2 soln = (Solution2)visualStudioInstance.Solution;
string templatePath = soln.GetProjectTemplate("ClassLibrary.zip", "CSharp");
soln.AddFromTemplate(templatePath, projPath, "MyProjectName", false);
Am I on the right track?
I've tried it and I got an exception, but perhaps it was just because the zip folder doesn't exist.
UPDATE
The exception I get is:
"Object reference not set to an instance of an object."
I get it in the last line of the following code, when I try to add a reference to calcEngineProject. calcEngineProject is null even though it enters the if-statement and should be assigned the value of projCS.Object as VSProject2.
The code is as follows:
templatePath = soln.GetProjectTemplate("ClassLibrary.zip", "CSharp");
soln.AddFromTemplate(templatePath, prjPath, "ClassLibrary1", false);
foreach (Project p in soln.Projects)
{
if (String.Compare(p.Name, "ClassLibrary1") == 0)
{
projCS = p;
break;
}
}
if (projCS != null)
{
calcEngineProject = projCS.Object as VSProject2;
}
calcEngineProject.References.Add(Path.Combine(Config.Engine.EngineBinPath, "Engines.Calculation.dll"));
Also, I saw that templatePath is this:
"C:\PROGRAM FILES (X86)\MICROSOFT VISUAL
STUDIO\2017\PROFESSIONAL\COMMON7\IDE\EXTENSIONS\EYXTAMKA.FB4\ProjectTemplates\CSharp\.NET
Standard\1033\ClassLibrary\ClassLibrary.vstemplate"
and not
\%USERPROFILE%\Documents\My Exported Templates\
as mentioned in Upgrading custom project template
With C# 7 new Tuple feature we should be able to access fields by it's names derived from the type.
public (double lat, double lng) GetLatLng(string address) { ... }
var ll = GetLatLng("some address");
Console.WriteLine($"Lat: {ll.lat}, Long: {ll.lng}");
This is not possible in .NET Core. Why? -> Works only with Item1; Item2. Not with .lat .lng.
Thanks
UPDATE
Visual Studio 2017 Intellisense may be slow to update itself after adding the System.ValueTuple package and keep displaying error squigglies even when there is no compilation error. Compiling the project though shows that named tuples are working. A quick fix is to re-open the source file or solution.
ORIGINAL
The error message explains that 'Predefined type System.ValueTuple'2 is not defined or imported. You need to add the System.ValueTuple package from NuGet in order to use named tuples.
Once you add the package, the code compiles:
class Program
{
static (double lat, double lng) GetLatLng(string address)
{
return (1, 1);
}
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
var ll = GetLatLng("some address");
Console.WriteLine($"Lat: {ll.lat}, Long: {ll.lng}");
}
}
Scott Hanselman shows how to configure Visual Studio 2017 to automatically suggest NuGet packages for missing types by enabling the settings in Options > Text Editor > C# > Advanced > Using Directives.
After you enable the Suggest usings for types in NuGet packages setting, the Quick Fix menu for the missing tuples shows Install package 'System.ValueTuple' :
The Find this type on nuget.org menu is a similar ReSharper feature
I have the following folder structure once I package my Service Fabric NS1.NS2.MicroServicesTest project (written in C#, using .NET):
pkg
|-NS1.NS2.MicroServicesTest.MicroServiceA
|-NS1.NS2.MicroServicesTest.MicroServiceB
|-NS1.NS2.MicroServicesTest.MicroServiceC
|-NS1.NS2.MicroServicesTest.MicroServiceD
|-ApplicationManifest.xml
I am trying to deploy this package using the following PowerShell script:
Copy-ServiceFabricApplicationPackage pkg -ImageStoreConnectionString file:C:\SfDevCluster\Data\ImageStoreShare -ApplicationPackagePathInImageStore NS1.NS2.MicroServicesTest
Register-ServiceFabricApplicationType NS1.NS2.MicroServicesTest
New-ServiceFabricApplication fabric:/NS1.NS2.MicroServicesTest NS1.NS2.MicroServicesTest 1.0.0
It fails on the last command, New-ServiceFabricApplication, with the following error:
New-ServiceFabricApplication : Application type and version not found
Where have I gone wrong? I have tried to follow this tutorial, albeit it kind of uses a base case in its example, whereas my project has 4 microservices as part of it, and an odd naming convention, which makes it even more confusing...
Edit: When I run the Get-ServiceFabricApplicationType command, I see:
ApplicationTypeName : MicroServicesTestType
ApplicationTypeVersion : 1.0.0
DefaultParameters : { "MicroServiceA_InstanceCount" = "-1";
"MicroServiceB_InstanceCount" = "-1";
"MicroServiceC_Endpoint" = "defaultValue";
"MicroServiceC_InstanceCount" = "-1";
"MicroServiceC_MaxRecords" = "100";
"MicroServiceD_InstanceCount" = "-1" }
(from discussion to answer)
After registering it, validate that your Application Type shows up when calling 'Get-ServiceFabricApplicationType'
Check your Application Type version 1.0.0?
Try using this command: New-ServiceFabricApplication fabric:/ MicroServicesTestType MicroServicesTestType 1.0.0
What's the best way to read (ideally via C#) the packages listed in packages.config files?
Within our source code repository I have a lot of solutions and projects and equally a lot of packages.config files. I'm trying to build a consolidated list of packages (and versions) in use across my source code repository.
I can see there is a NuGet.Core package available - how could I use this to achieve my goal?
Thanks
If you do not want to read the XML directly you can install the NuGet.Core NuGet package and then use the PackageReference class.
Here is some example code that uses this class to print out the package id and its version.
string fileName = #"c:\full\path\to\packages.config";
var file = new PackageReferenceFile(fileName);
foreach (PackageReference packageReference in file.GetPackageReferences())
{
Console.WriteLine("Id={0}, Version={1}", packageReference.Id, packageReference.Version);
}
You will need to find the packages.config files yourself which you can probably do with a directory search, something like:
foreach (string fileName in Directory.EnumerateFiles("d:\root\path", "packages.config", SearchOption.AllDirectories))
{
// Read the packages.config file...
}
An alternative and more up to date way of doing this is to install the NuGet.Packaging NuGet package and use code similar to:
var document = XDocument.Load (fileName);
var reader = new PackagesConfigReader (document);
foreach (PackageReference package in reader.GetPackages ())
{
Console.WriteLine (package.PackageIdentity);
}
As suggested you will need to install NuGet.Core, your solution may have several projects in it, so it's good to know how to specify the project name when installing. Let's say your Solution is MySolution and you have two projects Project01 & Project02 and you only want to install in Project02.
Install-Package NuGet.Core -ProjectName Project02
Next you will need to add a using statement in the whatever.cs page you are going to do your work to target the package and let's say you just want to get the version number so that you can print it out somewhere on your website. That is actually what I wanted to do.
using NuGet;
next I wanted to get at a specific package and read it's version number so that when we release my software I have a visual identifier at a certain place on my website that I can go to and see the version that is in production.
here is the code I wrote to populate a webforms label on my page.
protected void Page_Load(Object sender, EventArgs e)
{
var pkgRefpath = Server.MapPath("~/packages.config");
PackageReferenceFile nugetPkgConfig = new PackageReferenceFile(pkgRefpath);
IEnumerable<PackageReference> allPackages = nugetPkgConfig.GetPackageReferences();
var newtonsoftPkg = (
from pkg in allPackages
where pkg.Id == "Newtonsoft.Json"
select pkg
).FirstOrDefault();
if (newtonsoftPkg== null) return;
var newtonsoftPkg_Version = newtonsoftPkg.Version;
ltrNewtonsoftVer.Text = newtonsoftPkg_Version.ToString();
}
This is a slightly different answer to the question, but this shows the solution that I ended up with for my needs after finding this Question/Answer and modifying what I learned to suit my own needs. I hope it can help someone else out.