ASP.NET Web应用程序 – 在部署时,System.Speech.dll对象未设置为对象的实例

我有一个ASP.NET Web应用程序,它使用System.Speech将文本转换为WAV文件。 它在本地工作正常,但当我将其部署到服务器时,我收到以下错误消息。 这是使用Windows Server 2012,ASP.NET 4.5和IIS 8.5:

Object reference not set to an instance of an object. System.Speech at System.Speech.Internal.ObjectTokens.RegistryDataKey..ctor(String fullPath, RegistryDataKey copyKey) at System.Speech.Internal.ObjectTokens.SAPICategories.DefaultDeviceOut() at System.Speech.Internal.Synthesis.VoiceSynthesis..ctor(WeakReference speechSynthesizer) at System.Speech.Synthesis.SpeechSynthesizer.get_VoiceSynthesizer() at QuinnSDS.handlerTransform.c__DisplayClass6.b__1() 

生成此错误消息的代码在服务器上运行:

 if (context.Request.ContentLength > 0) { string line = new StreamReader(context.Request.InputStream).ReadToEnd(); // ********* generate wav file voicing the response ***************** // Using Microsoft voices // initiate new instance of speech synthesizer Thread t = new Thread(() => { try { // The object creation works fine System.Speech.Synthesis.SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer(); if (synth != null) { // The code breaks at synth.GetInstalledVoices() below. It will break any time I try to do anything with the synth object foreach (System.Speech.Synthesis.InstalledVoice voice in synth.GetInstalledVoices()) { System.Speech.Synthesis.VoiceInfo info = voice.VoiceInfo; string voiceName = info.Name; ws.WriteLine(voiceName); } } } catch (Exception e) { ws.WriteLine(e.Message); ws.WriteLine(e.Source); ws.WriteLine(e.StackTrace); } //... code continues... 

创建语音合成对象时不会中断; 每当我尝试以任何方式使用该对象时它都会中断。

我不确定它是否是一个访问问题,但我对ASP.NET和IIS很新,我无法弄清楚如何让Web应用程序访问GAC,或者甚至是问题是什么。 在部署应用程序之前,我尝试在Visual Studio中将System.Speech引用的属性Local Copy更改为True,但这没有用。 我在网上搜索,虽然“对象引用未设置为对象的实例”似乎相当普遍,但由于.NET框架类库,我找不到任何类似的问题…我已经运行了文本到 – 语音代码在服务器本地,它运行正常。 我没有在服务器上本地运行整个应用程序,因为Web应用程序需要语音输入,并且服务器上没有麦克风。

任何想尝试的想法都是最受欢迎的!

从ASP.NET执行时运行的代码是什么用户帐户? 如果Speech API像调用堆栈建议那样触及注册表,则它可能具有与您手动运行代码所使用的帐户不同的权限。

如果您不能只使用同一个帐户运行您的站点的应用程序池,那么您使用Process Monitor就可以成功地使用Process Monitor来跟踪此类问题。 基本上,执行Process Monitor运行时失败的代码,并在“Result”列中查找“ACCESS DENIED”(或其他任何看起来可疑的内容)。 快速切换应用程序池以使用标准用户帐户将是排除安全性或权限相关问题的最快方法。