Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
744 views
in Technique[技术] by (71.8m points)

c# - ASP.NET Web Application - on deploy, System.Speech.dll object not getting set to an instance of an object

I have an ASP.NET web application that uses System.Speech to transform text to a WAV file. It works fine locally but when I deploy it to the server, I get the below error message. This is using Windows Server 2012, ASP.NET 4.5, and 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.<ProcessRequest>b__1()

The code which is generating this error message runs on the server:

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...

It does not break when the Speech Synthesis object is created; it breaks whenever I try to use that object in any way.

I'm not sure if it's an access issue but I'm pretty new to ASP.NET and IIS and I can't figure out how to give the web app access to the GAC or if that's even what the problem is. I tried changing the property Local Copy for the System.Speech reference to True in Visual Studio, before I deploy the app, but that hasn't worked. I searched online and while the "object reference not set to an instance of an object" seems fairly common, I cannot find any similar issues where it is because of a .NET framework class library...I have run the text-to-speech code locally on the server and it ran fine. I have not run the entire app locally on the server because the web app requires speech input and there is not a microphone on the server.

Any ideas of anything to try would be most welcome!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

What user account is the code running under when executed from ASP.NET? If the Speech API is touching the registry like the call stack suggests, it possibly has different permissions than the account you used to run the code manually.

If you can't just make the application pool for your site run with the same account you log into the machine with, I've had some success using Process Monitor to track down this kind of problem before. Basically, execute the code that fails while Process Monitor is running and look for 'ACCESS DENIED' in the 'Result' column (or anything else that looks suspicious). Quickly switching the application pool to use your standard user account will be the fastest way to rule out security or permission related problems though.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...