存在显式转换。你错过了演员吗?

时间:2017-03-17 09:17:58

标签: api microsoft-cognitive emotion

我收到以下错误:

An explicit conversion exists. Are you missing a cast?

为什么会这样?

an explicit conversion exists

private async void getEmotion_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            try
            {
                emotionResult = await emotionServiceClient.RecognizeAsync(imageStream.AsStream());
                if(emotionResult != null)
                {
                    Scores score = emotionResult[0].Scores; 
                }
            }
            catch
            {
                Output.Text = "Error returning the Emotion";
            }
        }

1 个答案:

答案 0 :(得分:0)

请参阅类似的问题,在此处回答:Cannot implicitly convert type 'Microsoft.ProjectOxford.Common.Contract.EmotionScores[]' to 'Microsoft.ProjectOxford.Emotion.Contract.Scores[]'

Scores和EmotionScores是名称相同的对象,但不能自动转换。你可以说

EmotionScores scores = emotionResult[0].Scores;

或只是

var scores = emotionResult[0].Scores;