1 //------------------------------------------------------------------------------
2 // <copyright file="LicenseException.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
7 namespace System.ComponentModel {
10 using System.Diagnostics;
11 using System.Runtime.Serialization;
12 using System.Security.Permissions;
15 /// <para>Represents the exception thrown when a component cannot be granted a license.</para>
17 [HostProtection(SharedState = true)]
18 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors")] // must not, a Type is required in all constructors.
20 public class LicenseException : SystemException {
22 private object instance;
25 /// <para>Initializes a new instance of the <see cref='System.ComponentModel.LicenseException'/> class for the
26 /// specified type.</para>
28 public LicenseException(Type type) : this(type, null, SR.GetString(SR.LicExceptionTypeOnly, type.FullName)) {
31 /// <para>Initializes a new instance of the <see cref='System.ComponentModel.LicenseException'/> class for the
32 /// specified type and instance.</para>
34 public LicenseException(Type type, object instance) : this(type, null, SR.GetString(SR.LicExceptionTypeAndInstance, type.FullName, instance.GetType().FullName)) {
37 /// <para>Initializes a new instance of the <see cref='System.ComponentModel.LicenseException'/> class for the
38 /// specified type and instance with the specified message.</para>
40 public LicenseException(Type type, object instance, string message) : base(message) {
42 this.instance = instance;
43 HResult = HResults.License;
46 /// <para>Initializes a new instance of the <see cref='System.ComponentModel.LicenseException'/> class for the
47 /// specified innerException, type and instance with the specified message.</para>
49 public LicenseException(Type type, object instance, string message, Exception innerException) : base(message, innerException) {
51 this.instance = instance;
52 HResult = HResults.License;
56 /// Need this constructor since Exception implements ISerializable.
58 protected LicenseException(SerializationInfo info, StreamingContext context) : base (info, context) {
59 type = (Type) info.GetValue("type", typeof(Type));
60 instance = info.GetValue("instance", typeof(object));
64 /// <para>Gets the type of the component that was not granted a license.</para>
66 public Type LicensedType {
73 /// Need this since Exception implements ISerializable and we have fields to save out.
75 [SecurityPermission(SecurityAction.Demand, SerializationFormatter=true)]
76 public override void GetObjectData(SerializationInfo info, StreamingContext context) {
78 throw new ArgumentNullException("info");
81 info.AddValue("type", type);
82 info.AddValue("instance", instance);
84 base.GetObjectData(info, context);