c# - 由于 Microsoft 教程中的代码中的保护级别错误而无法访问

标签 c# azure azure-cognitive-services

以下代码来自 Official Microsoft Azure tutorial在第一行给出以下错误消息:

ITextAnalyticsAPI client = new TextAnalyticsAPI();

TextAnalyticsAPI.TextAnalyticsAPI(param DelegatingHandler[]) is inaccessible due to its protection level

using System;
using Microsoft.Azure.CognitiveServices.Language.TextAnalytics;
using Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Models;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a client.
            ITextAnalyticsAPI client = new TextAnalyticsAPI();
            client.AzureRegion = AzureRegions.Westus;
            client.SubscriptionKey = "ENTER KEY HERE";

            Console.OutputEncoding = System.Text.Encoding.UTF8;

            // Extracting language
            Console.WriteLine("===== LANGUAGE EXTRACTION ======");

            LanguageBatchResult result = client.DetectLanguage(
                    new BatchInput(
                        new List<Input>()
                        {
                          new Input("1", "This is a document written in English."),
                          new Input("2", "Este es un document escrito en Español."),
                          new Input("3", "这是一个用中文写的文件")
                        }));

            // Printing language results.
            foreach (var document in result.Documents)
            {
                Console.WriteLine("Document ID: {0} , Language: {1}", document.Id, document.DetectedLanguages[0].Name);
            }

            // Getting key-phrases
            Console.WriteLine("\n\n===== KEY-PHRASE EXTRACTION ======");

            KeyPhraseBatchResult result2 = client.KeyPhrases(
                    new MultiLanguageBatchInput(
                        new List<MultiLanguageInput>()
                        {
                          new MultiLanguageInput("ja", "1", "猫は幸せ"),
                          new MultiLanguageInput("de", "2", "Fahrt nach Stuttgart und dann zum Hotel zu Fu."),
                          new MultiLanguageInput("en", "3", "My cat is stiff as a rock."),
                          new MultiLanguageInput("es", "4", "A mi me encanta el fútbol!")
                        }));


            // Printing keyphrases
            foreach (var document in result2.Documents)
            {
                Console.WriteLine("Document ID: {0} ", document.Id);

                Console.WriteLine("\t Key phrases:");

                foreach (string keyphrase in document.KeyPhrases)
                {
                    Console.WriteLine("\t\t" + keyphrase);
                }
            }

            // Extracting sentiment
            Console.WriteLine("\n\n===== SENTIMENT ANALYSIS ======");

            SentimentBatchResult result3 = client.Sentiment(
                    new MultiLanguageBatchInput(
                        new List<MultiLanguageInput>()
                        {
                          new MultiLanguageInput("en", "0", "I had the best day of my life."),
                          new MultiLanguageInput("en", "1", "This was a waste of my time. The speaker put me to sleep."),
                          new MultiLanguageInput("es", "2", "No tengo dinero ni nada que dar..."),
                          new MultiLanguageInput("it", "3", "L'hotel veneziano era meraviglioso. È un bellissimo pezzo di architettura."),
                        }));


            // Printing sentiment results
            foreach (var document in result3.Documents)
            {
                Console.WriteLine("Document ID: {0} , Sentiment Score: {1:0.00}", document.Id, document.Score);
            }

        }
    }
}

最佳答案

问题很可能是您得到 the wrong package version .

该帖子来自 09-20-2017,该软件包的 1.0.0 预览版本来自 09-19-2017。< br/> 然而,该软件包的最新版本是昨天发布的 1.0.1,您很可能已安装。

较小的升级不应该有重大变化,但是......

关于c# - 由于 Microsoft 教程中的代码中的保护级别错误而无法访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50263298/

相关文章:

c# - 如何延长使用耐用品的azure功能的超时?

azure - 提高了 Docker 上的 Azure 计算机视觉的性能

Azure Spell 未检测到拼写错误

c# - 并行 http 请求

c# - 将字符串数据绑定(bind)到文本框

c# - 如何使用多个数据源进行单元测试?

c# - 如何使用 C# 在 Excel 范围内添加边框?

java - 具有 Spring Boot Oaut2UserService 问题的 Azure Active Directory

python - azure Blob : upload directory content using a loop in Python

python - Azure Detect faces API,如何将URL图片更改为本 map 片?