Azure Cognitive Services Intent Recognition: System.AccessViolationException

117 Views Asked by At

I'm currently working on an Azure Cognitive Services tutorial, specifically the Intent Recognition sample. I'm encountering a System.AccessViolationException when I use the ApplyLanguageModels() method from IntentRecognizer on my ConversationalLanguageUnderstandingModel.

Here's the snippet of my code:

var speechConfig = SpeechConfig.FromSubscription(_speechKey, _speechRegion);
speechConfig.SpeechRecognitionLanguage = "en-US";

using var audioConfig = AudioConfig.FromDefaultMicrophoneInput();

// Creates an intent recognizer in the specified language using microphone as audio input.
using (var intentRecognizer = new IntentRecognizer(speechConfig, audioConfig))
{
    var cluModel = new ConversationalLanguageUnderstandingModel(
                                                                    _languageKey,
                                                                    _languageEndpoint,
                                                                    _cluProjectName,
                                                                    _cluDeploymentName);
    var collection = new LanguageUnderstandingModelCollection();
    collection.Add(cluModel);
    intentRecognizer.ApplyLanguageModels(collection);

The error occurs at intentRecgonizer.ApplyLanguageModels(collection) and the stack trace shows:

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
   at Microsoft.CognitiveServices.Speech.Internal.Recognizer.intent_recognizer_add_conversational_language_understanding_model(Microsoft.CognitiveServices.Speech.Internal.InteropSafeHandle, Microsoft.CognitiveServices.Speech.Internal.Utf8StringHandle, Microsoft.CognitiveServices.Speech.Internal.Utf8StringHandle, Microsoft.CognitiveServices.Speech.Internal.Utf8StringHandle, Microsoft.CognitiveServices.Speech.Internal.Utf8StringHandle)
--------------------------------
   at Microsoft.CognitiveServices.Speech.Intent.IntentRecognizer.ApplyLanguageModels(Microsoft.CognitiveServices.Speech.Intent.LanguageUnderstandingModelCollection)
   at IntentRecgonition+<DoWork>d__7.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon ByRef)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon ByRef)
   at IntentRecgonition.DoWork()
   at Program+<Main>d__4.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon ByRef)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon ByRef)
   at Program.Main(System.String[])
   at Program.<Main>(System.String[])

I'm using Azure Cognitive Services SDK version 1.28.0. (VS 2022 .NET 6 Console App)

I've checked my keys, endpoints, and deployment names and they all seem to be correct. I've also tried updating my SDK to the latest version. However, none of these attempts have resolved the issue.

Does anyone have any insights or solutions for this System.AccessViolationException?

Thanks in advance for your help.

1

There are 1 best solutions below

0
Robert Green MBA On

I had to restart VS as I just added the environment variables needed.