LicenseException 类

表示当组件不能被授予许可证时引发的异常。

**命名空间:**System.ComponentModel
**程序集:**System(在 system.dll 中)

语法

声明
<SerializableAttribute> _
Public Class LicenseException
    Inherits SystemException
用法
Dim instance As LicenseException
[SerializableAttribute] 
public class LicenseException : SystemException
[SerializableAttribute] 
public ref class LicenseException : public SystemException
/** @attribute SerializableAttribute() */ 
public class LicenseException extends SystemException
SerializableAttribute 
public class LicenseException extends SystemException

备注

当组件不能获得有效的许可证时,LicenseManager.Validate 方法引发 LicenseException。如果组件未被授权,或虽已被授权但未被授予有效的许可证,便会发生这种情况。

有关授权的更多信息,请参见 如何:授予组件和控件许可权限

提示

应用于此类的 HostProtectionAttribute 属性 (Attribute) 具有以下 Resources 属性 (Property) 值:SharedStateHostProtectionAttribute 不会影响桌面应用程序(桌面应用程序通常可通过双击图标、键入命令或在浏览器中输入 URL 来启动)。有关更多信息,请参见 HostProtectionAttribute 类或 SQL Server 编程和宿主保护属性

示例

下面的代码示例显示如何捕捉 LicenseException 并解释其内容。在该示例中,应用程序为 System.Windows.Forms.Form(它未被授权)调用 Validate 方法。捕捉到异常时,该示例获取各自的错误信息、未被授予许可证的组件的类型、堆栈跟踪以及该异常的来源。

此示例需要已经通过用 LicenseProviderAttribute 属性标记 System.Windows.Forms.Form 指定了 LicenseProvider。有关如何实现此操作的更多信息,请参见 LicenseManager 类。

Try
    Dim licTest As License
    licTest = LicenseManager.Validate(GetType(Form1), Me)
Catch licE As LicenseException
    Console.WriteLine(licE.Message)
    Console.WriteLine(licE.LicensedType)
    Console.WriteLine(licE.StackTrace)
    Console.WriteLine(licE.Source)
End Try
try {
    License licTest = null;
    licTest = LicenseManager.Validate(typeof(Form1), this);
}

catch(LicenseException licE) {
    Console.WriteLine(licE.Message);
    Console.WriteLine(licE.LicensedType);
    Console.WriteLine(licE.StackTrace);
    Console.WriteLine(licE.Source);    
}
try
{
   License^ licTest = nullptr;
   licTest = LicenseManager::Validate( Form1::typeid, this );
}
catch ( LicenseException^ licE ) 
{
   Console::WriteLine( licE->Message );
   Console::WriteLine( licE->LicensedType );
   Console::WriteLine( licE->StackTrace );
   Console::WriteLine( licE->Source );
}
try {
    License licTest = null;
    licTest = LicenseManager.Validate(Form1.class.ToType(), this);
}
catch (LicenseException licE) {
    Console.WriteLine(licE.get_Message());
    Console.WriteLine(licE.get_LicensedType());
    Console.WriteLine(licE.get_StackTrace());
    Console.WriteLine(licE.get_Source());
}

继承层次结构

System.Object
   System.Exception
     System.SystemException
      System.ComponentModel.LicenseException

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

LicenseException 成员
System.ComponentModel 命名空间
License 类
LicenseContext 类
LicenseManager
LicenseProvider
LicenseProviderAttribute
LicFileLicenseProvider
LicenseUsageMode