I have a console application that I made in Visual Studio 2022, using C#, .NET Framework 4.8.1, and the Azure Cognitive Services Speech SDK (version 1.25) installed through NuGet. The application works fine in the development environment, but when I publish it and then install it on either the development computer, or a target computer, the following error message appears:
Unhandled exception: System.DllNotFoundException: Unable to load DLL 'Microsoft.CognitiveServices.Speech.core.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at Microsoft.CognitiveServices.Speech.Internal.SpeechConfig.speech_config_from_subscription(IntPtr& config, String subscriptionKey, String region)
at Microsoft.CognitiveServices.Speech.SpeechConfig.FromSubscription(String, subscriptionKey, String region)
at CommandApp.Program.Main()
To be clear, both the development computer (Windows 11) and target computer (Windows 10) are using the same CPU architecture (64-bit). The target architecture is set to 'Any CPU'. I have also installed the Microsoft Visual C++ Redistributable (x64) (version 14.34.31938) on both machines, which I believe is used by the SDK.
To try to resolve the issue, I have tried the following:
The advice to use a NuGet package was taken from here.
So, not quite sure what I am missing, here. Any help would be appreciated, even from individuals who have had publishing problems using other NuGet packages, and were then able to resolve them.
Thanks in advance.
You can configure your .NET Framework project to include the native dlls from the Speech SDK Nuget package by adding following changes to your application .csproj file:
<PropertyGroup>
<NuGetPackageRoot>$(USERPROFILE)\.nuget\packages</NuGetPackageRoot>
</PropertyGroup>
<ItemGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<Content Include="$(NuGetPackageRoot)\microsoft.cognitiveservices.speech\1.25.0\runtimes\win-x64\native\Microsoft.CognitiveServices.Speech.core.dll">
</Content>
<Content Include="$(NuGetPackageRoot)\microsoft.cognitiveservices.speech\1.25.0\runtimes\win-x64\native\Microsoft.CognitiveServices.Speech.extension.audio.sys.dll">
</Content>
</ItemGroup>
Here it is assumed that Speech SDK gets installed under $(USERPROFILE)\.nuget\packages
folder. Also note that Speech SDK Nuget contains more dlls than given in the example above. You can include all of them, however for most of the scenarios the example above is sufficient.
Also seems that this problem does not happen with .NET Core applications, where current NuGet installation is sufficient for app publish. I will see if we will update the Speech SDK NuGet to support better the .NET Framework scenario.