Exception on IIS Server When try to create .wav file on c# us开发者_StackOverflow社区ing SpeechSynthesizer.
This error is caused when the application is unable to access a voice for the SpeechSynthesizer to use. The first possible cause is the lack of any installed voices on the system. Odds are this isn't the problem, but you should still double check by running something like the following bit of code:
SpeechSynthesizer ssTest = new SpeechSynthesizer();
System.Diagnostics.Debug.WriteLine(ssTest.GetInstalledVoices().Count);
Assuming the above returns a number higher than 0, the problem is likely a more complicated issue with your application's security settings.
Several methods in the SpeechSynthesizer class, including SetOutputToWaveFile, require the immediate caller to be fully trusted. This might not be a huge concern for a desktop application (which the SpeechSynthesizer class was likely designed for) but has more serious security repercussions in a web environment. Therefore, IIS's default settings only make applications partially trusted. There are a number of ways to change this, possibly the quickest and certainly the dirtiest way is switching the application pool's identity from the default to an account with administrator privileges like the LocalSystem account.
Once again, just for emphasis, this will seriously harm the security of your application and should be fully researched before implementing.
Simple fix: Grant read/write access to C:\windows\system32\config\systemprofile\appdata\roaming
for the same user that the app pool is running under.
Simply, run the app as "administrator". ;)
精彩评论