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:
- Uninstalling and reinstalling the Microsoft.CognitiveServices.Speechpackage on my development computer, republishing, and thenreinstalling on the computers.
- Copying the 'Microsoft.CognitiveServices.Speech.core.dll' file directly from the NuGet package directory, and placing the copy inthe same folder as the application file.
- Adding a reference to the file using the Reference Manager, which causes another error to appear: 'A reference toC:\Users\trist\source\repos\ConsoleApp1\bin\Release\Microsoft.CognitiveServices.Speech.core.dll'could not be loaded. Please make sure that the file is accessible,and that it is a valid assembly or COM component.
- Checking the Application Files section under Publish settings to see if the file was there (it isn't, but there was a similarly namedfile, Microsoft.CognitiveServices.Speech.csharp.dll, which isincluded).
- Repairing the C++ redistributable installation.
- Changing the solution and project configurations from 'AnyCPU' to 'x64', and re-publishing.
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.