Exception on IIS Server When try to create .wav file on c# using SpeechSynthesizer.
3 Answers
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.

- 2,063
- 4
- 20
- 30
-
Switched app pool to LocalSystem, no dice. It's not a user permissions issue, it appears to be related to the trust of the execution context. A console app that executes the code you pasted above run from a network drive errors (my user, partial trust execution), but works fine run locally (my user, full trust execution). It's not a user issue, but an issue with the trust of the execution context.. not sure how to change that for dev web server or IIS though... – Jimmy Hoffa Mar 29 '13 at 18:45
-
@JimmyHoffa The security model is handled a little differently for console apps so it isn't a perfect test case. You can find a similar question for console apps [here](http://stackoverflow.com/q/4827670/113343). If you still have the problem with a web app you can try granting full trust another way like through the web.config as shown [here](http://stackoverflow.com/a/10220416/113343). – sglantz Apr 04 '13 at 17:50
-
1Changing the application pool to use the LocalSystem identity worked for me. I have not fully researched the security ramifications of this, so I am not sure if this will be the final solution for me or not, but for now I am happy that it is working. – user3308241 May 17 '15 at 00:16
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.

- 4,481
- 2
- 37
- 64