简体   繁体   English

Google NLP Api C#发生System.AggregateException

[英]Google NLP Api C# an System.AggregateException occured

I try to filter a line of text by using the NLP Api from Google. 我尝试使用Google的NLP Api过滤一行文本。

But once I try to return a value an error message occured. 但是,一旦我尝试返回一个值,就会出现一条错误消息。

I already tried to debug the code but it will not go futher than the creation of the variable "google". 我已经尝试调试代码,但是它不会比创建变量“ google”更持久。 After this the program returns the error message saying "An System.AggregateException occured in MESSAGE_CREATED." 此后,程序将返回错误消息,指出“ MESSAGE_CREATED中发生了System.AggregateException”。 What basically means that multiple error's occured. 这基本上意味着发生多个错误。

Does someone onderstand why this is happening, or how I can fix this? 有人知道为什么会这样吗,或者我该如何解决?

    public dynamic DataFilter(string data)
    {
        var client = LanguageServiceClient.Create();

        var response = client.AnalyzeSentiment(new Document()
        {
            Content = data,
            Type = Document.Types.Type.PlainText
        });

        var sentiment = response.DocumentSentiment;
        return sentiment;
    }

    private async Task AnalyzeMessage(MessageCreateEventArgs e)
    {
        string retrievedData = e.Message.Content;
        string userMessage = retrievedData.ToLower();

        if(!e.Author.IsBot)
        {
            if(userMessage.Contains("nlp"))
            {
                string line = "What is the capital of the Netherlands";

                var google = DataFilter(line);

                await e.Channel.SendMessageAsync($"The value given back is {google.Magnitude}");
            }
        }
    }

I found the problem! 我发现了问题!

The problem was not in the code but in the google api. 问题不在代码中,而是在Google API中。 The api returns an "System.AggregateException" because the environment variable was not added into the application (I added it into my computer but this was not enough). api返回“ System.AggregateException”,因为环境变量未添加到应用程序中(我将其添加到计算机中,但这还不够)。

Go to "Solution Explorer" > "Right click on your project" > "Properties" > "Debug" and add under name "GOOGLE_APPLICATION_CREDENTIALS" and as value the location of to your authentication JSON file (you can download this on https://cloud.google.com/natural-language/docs/quickstart-client-libraries ) 转到“解决方案资源管理器”>“右键单击您的项目”>“属性”>“调试”,并添加名称“ GOOGLE_APPLICATION_CREDENTIALS”,并将其位置值添加到身份验证JSON文件中(您可以在https://上下载该文件) cloud.google.com/natural-language/docs/quickstart-client-libraries

I hope this helps for someone else! 我希望这对其他人有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试使用Google API进行身份验证时,mscorlib.dll中发生“ System.AggregateException” - 'System.AggregateException' occurred in mscorlib.dll, when trying to authenicate using Google API API 中的 System.AggregateException “某些服务无法构建” - System.AggregateException in API "Some services are not able to be constructed" 异常被捕获为System.AggregateException - Exception catched as System.AggregateException System.AggregateException程序崩溃 - System.AggregateException the program crashes ScrapySharp 表单提交导致 System.AggregateException - ScrapySharp Form Submit causing System.AggregateException Task.WaitAll上的System.AggregateException - System.AggregateException on Task.WaitAll ASP.NET中GetStringAsync上的System.AggregateException - System.AggregateException on GetStringAsync in asp.net System.AggregateException 已被抛出 - System.AggregateException has been thrown Web Api的PostAsync HttpClient错误 - System.AggregateException“任务已取消。” - PostAsync HttpClient error with Web Api - System.AggregateException “A task was canceled.” 尝试连接到我的 Common Data Service web api 时出现“System.AggregateException” - 'System.AggregateException' when attempting to connect to my Common Data Service web api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM