如何在 C# 中将程序集安全性设置为完全信任?

how to set assembly security to full trusted in c#?

我有 WPF 网络表单。当我尝试为 SpeechSynthesizer 创建一个实例时,它抛出一个错误。话说,

Assembly 'WpfBrowserApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is partially trusted, which causes the CLR to make it entirely security transparent regardless of any transparency annotations in the assembly itself.  In order to access security critical code, this assembly must be fully trusted.

的确,即使是我也在使用正确的命名空间。即,使用 System.Speech.Synthesis。无论如何,我不知道它为什么会抛出错误。

任何人都可以让我知道我错过了什么吗?

这是我的代码。

 public Page2()
    {
        InitializeComponent();  
        SpeechSynthesizer ss = new SpeechSynthesizer();  
    }

您需要签署程序集。看看下面的文章:How to: Sign an Assembly (Visual Studio).

摘录:

Assembly signing (also called strong-name signing) gives an application or component a unique identity that other software can use to identify and refer explicitly to it. A strong name consists of its simple text name, version number, culture information (if provided), plus a public/private key pair. This information is stored in a key file; this can be a Personal Information Exchange (PFX) file or a certificate from the current user's Windows certificate store. For more information, see Strong-Name Signing for Managed Applications.