Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type Initialization Exception on pipeline definition

Tags:

stanford-nlp

Integrating Stanford-NLP into ASP.Net Core C# application getting the following error message: System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'edu.stanford.nlp.util.Timing' threw an exception. Source=stanford-corenlp-3.9.1 StackTrace: at edu.stanford.nlp.util.Timing..ctor() at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(Properties , Boolean , AnnotatorImplementations ) at edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props, Boolean enforceRequirements, AnnotatorPool annotatorPool) at edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props, Boolean enforceRequirements) at edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props) at _3x32018.Utility.SearchNLP.ParseNLG(String sent2) in G:\VSProjects\3x32018\3x32018\Utility\SearchNLP.cs:line 52

Inner Exception 1: TypeInitializationException: The type initializer for 'java.util.ResourceBundle' threw an exception.

Inner Exception 2: MissingMethodException: Method not found: 'Void System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.Security.AccessControl.FileSystemRights, System.IO.FileShare, Int32, System.IO.FileOptions)'.

Here's my simple code::

using edu.stanford.nlp.pipeline;
using java.util;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;

namespace _3x32018.Utility 
{ 
  public class SearchNLP 
    { 
      public HashSet<string> ParseNLG(string sent2) 
        { 
          CultureInfo ci = new CultureInfo("en-US"); 
          Thread.CurrentThread.CurrentCulture = ci; 
          Thread.CurrentThread.CurrentUICulture = ci; 

          Properties props = new Properties(); 
          props.setProperty("annotators", "tokenize, ssplit, pos, lemma,
  ner, parse, dcoref"); 
        StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 
        Annotation document = new Annotation(sent2); 
        pipeline.annotate(document); 
      } 
   } 
}

Any ideas why this is failing?

-Lester

like image 250
Lester Edwards Avatar asked Apr 12 '26 14:04

Lester Edwards


1 Answers

You are using ASP.NET Core which doesn't have the constructor for FileStream that the corenlp.net is using (IKVM to be exact). Check this page out, https://learn.microsoft.com/en-us/dotnet/api/system.io.filestream.-ctor?view=netcore-2.0.

like image 154
henrylilei Avatar answered Apr 14 '26 23:04

henrylilei