EDN Admin
Well-known member
When I want to add my custom control assembly (DLL) file to the Visual Studio Toolbox, I encounter with following error:<br/>
There was an error loading types from assembly "my assembly file."<br/>
Inheritance security rules violated by type: ItemsCollectionEditor. Derived types must either match the security accessibility of the base type or be less accessible.<br/>
My code is:
<div id="x_premain0" width="100%" style="display:block
<pre class="prettyprint using System;
using System.Design;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Data;
using System.Drawing;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Security.Permissions;
using DevComponents.DotNetBar;
internal class ToolboxIconResFinder
{
}
namespace WindowsFormsControlLibrary2
{
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]
[ToolboxItem(true), ToolboxBitmap(typeof(ToolboxIconResFinder), "FloorsGrouping.bmp")]
[DisplayName("Floors Group")]
[Editor("WindowsFormsControlLibrary2.FloorsGrouping, WindowsFormsControlLibrary2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=197889249da45bfc", typeof(UITypeEditor))]
[Description("Floorssssssss")]
[Category("Saino")]
public partial class FloorsGrouping : Bar
{
private Items items = new Items();
private Tabs tabs = new Tabs();
public FloorsGrouping()
{
InitializeComponent();
}
[Category("Member Persisting")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Items Item
{
get
{
return items;
}
}
[Category("Collections")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(ItemsCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
public Tabs Tab
{
get
{
return tabs;
}
}
[ReadOnly(true)]
public new System.Windows.Forms.AccessibleRole AccessibleRole
{
get { return base.AccessibleRole; }
private set { base.AccessibleRole = System.Windows.Forms.AccessibleRole.ToolBar; }
}
[Browsable(false), ReadOnly(true)]
public new bool AlwaysDisplayDockTab
{
get { return base.AlwaysDisplayDockTab; }
private set { base.AlwaysDisplayDockTab = true; }
}
[Browsable(false), ReadOnly(true)]
public new bool AlwaysDisplayKeyAccelerators
{
get { return base.AlwaysDisplayKeyAccelerators; }
private set { base.AlwaysDisplayKeyAccelerators = true; }
}
[ReadOnly(true)]
public new bool AntiAlias
{
get { return base.AntiAlias; }
private set { base.AntiAlias = true; }
}
[Browsable(false), ReadOnly(true)]
public new bool AutoCreateCaptionMenu
{
get { return base.AutoCreateCaptionMenu; }
}
[ReadOnly(true)]
public new bool AutoHide
{
get { return base.AutoHide; }
}
[Browsable(false), ReadOnly(true)]
public new bool AutoHideTabTextAlwaysVisible
{
get { return base.AutoHideTabTextAlwaysVisible; }
}
[Browsable(false), ReadOnly(true)]
public new bool AutoSyncBarCaption
{
get { return base.AutoSyncBarCaption; }
private set { base.AutoSyncBarCaption = true; }
}
[Browsable(false), ReadOnly(true)]
public new eBarType BarType
{
get { return base.BarType; }
private set { base.BarType = eBarType.DockWindow; }
}
[ReadOnly(true)]
public new bool CanAutoHide
{
get { return base.CanAutoHide; }
}
[ReadOnly(true)]
public new bool CanDockTab
{
get { return base.CanDockTab; }
private set { base.CanDockTab = false; }
}
[ReadOnly(true)]
public new bool CanUndock
{
get { return base.CanUndock; }
private set { base.CanUndock = false; }
}
[Browsable(false), ReadOnly(true)]
public new bool CloseSingleTab
{
get { return base.CloseSingleTab; }
}
[Browsable(false), ReadOnly(true)]
public new bool DisplayMoreItemsOnMenu
{
get { return base.DisplayMoreItemsOnMenu; }
private set { base.DisplayMoreItemsOnMenu = true; }
}
[ReadOnly(true)]
public new DockStyle Dock
{
get { return base.Dock; }
}
[Browsable(false), ReadOnly(true)]
public new bool DockTabCloseButtonVisible
{
get { return base.DockTabCloseButtonVisible; }
}
[Browsable(false), ReadOnly(true)]
public new bool FadeEffect
{
get { return base.FadeEffect; }
private set { base.FadeEffect = true; }
}
[Browsable(false), ReadOnly(true)]
public new eGrabHandleStyle GrabHandleStyle
{
get { return base.GrabHandleStyle; }
private set { base.GrabHandleStyle = eGrabHandleStyle.Caption; }
}
[Browsable(false), ReadOnly(true)]
public new eLayoutType LayoutType
{
get { return base.LayoutType; }
private set { base.LayoutType = eLayoutType.DockContainer; }
}
[Browsable(false), ReadOnly(true)]
public new bool MenuBar
{
get { return base.MenuBar; }
}
[Browsable(false), ReadOnly(true)]
public new bool TabNavigation
{
get { return base.TabNavigation; }
private set { base.TabNavigation = true; }
}
[Browsable(false), ReadOnly(true)]
public new bool WrapItemsDock
{
get { return base.WrapItemsDock; }
private set { base.WrapItemsDock = true; }
}
protected override void OnParentChanged(EventArgs e)
{
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
}
public class Items
{
private string _Name = "SimpleItem";
private int _Id = -1;
[Category("TestProperties")]
[DefaultValue(typeof(string), "")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public string Name
{
get
{
return _Name;
}
set
{
_Name = value;
}
}
[Category("TestProperties")]
[DefaultValue(typeof(int), "-1")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public int Id
{
get
{
return _Id;
}
set
{
_Id = value;
}
}
public Items()
{
}
public Items(int Id, string Name)
{
_Id = Id;
_Name = Name;
}
}
public class Tabs : CollectionBase
{
public Items this[int Index]
{
get
{
return (Items)InnerList[Index];
}
set
{
InnerList[Index] = value;
}
}
public bool Contains(Items itemType)
{
return InnerList.Contains(itemType);
}
public int Add(Items itemType)
{
return InnerList.Add(itemType);
}
public void Remove(Items itemType)
{
InnerList.Remove(itemType);
}
public void Insert(int index, Items itemType)
{
InnerList.Insert(index, itemType);
}
public int IndexOf(Items itemType)
{
return InnerList.IndexOf(itemType);
}
public void AddRange(Items[] si)
{
InnerList.AddRange(si);
}
public Items[] GetValues()
{
Items[] si = new Items[InnerList.Count];
InnerList.CopyTo(0, si, 0, InnerList.Count);
return si;
}
protected override void OnInsert(int index, object value)
{
base.OnInsert(index, value);
}
}
public class ItemsCollectionEditor : CollectionEditor
{
private Type[] types;
public ItemsCollectionEditor(Type type)
: base(type)
{
types = new Type[] { typeof(Items) };
}
protected override Type[] CreateNewItemTypes()
{
return types;
}
}
}[/code]
<br/>
<span id="x_precollapse0" style="margin-bottom:0px <br type="_moz
<span>
Furthermore, I add assembly SecurityRulesAttribute to AssemblyInfo.cs file for solve the problem. However, it didnt work for me.<br/>
My AssemblyInfo file code is:
<div id="x_premain1" width="100%" style="display:block
<pre class="prettyprint using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WindowsFormsControlLibrary2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("SSSSSSSSS")]
[assembly: AssemblyProduct("WindowsFormsControlLibrary2")]
[assembly: AssemblyCopyright("Copyright © SSSSSSSSS 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ed5d434c-36e8-4883-a4d3-3eb6459546b3")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the * as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
//[assembly: AssemblyDelaySign(true)]
[assembly: AssemblyKeyFile("Saino.snk")]
[assembly: AssemblyKeyName("")]
[assembly: System.Security.AllowPartiallyTrustedCallers]
[assembly: SecurityRules(SecurityRuleSet.Level2, SkipVerificationInFullTrust = true)]
//[assembly: SecurityRules(SecurityRuleSet.Level1)][/code]
<br/>
<span id="x_precollapse1" style="margin-bottom:0px <br type="_moz
<span><span class="x_code-comment <hr class="sig Regards Mohsen Rostami
View the full article
There was an error loading types from assembly "my assembly file."<br/>
Inheritance security rules violated by type: ItemsCollectionEditor. Derived types must either match the security accessibility of the base type or be less accessible.<br/>
My code is:
<div id="x_premain0" width="100%" style="display:block
<pre class="prettyprint using System;
using System.Design;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Data;
using System.Drawing;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Security.Permissions;
using DevComponents.DotNetBar;
internal class ToolboxIconResFinder
{
}
namespace WindowsFormsControlLibrary2
{
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]
[ToolboxItem(true), ToolboxBitmap(typeof(ToolboxIconResFinder), "FloorsGrouping.bmp")]
[DisplayName("Floors Group")]
[Editor("WindowsFormsControlLibrary2.FloorsGrouping, WindowsFormsControlLibrary2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=197889249da45bfc", typeof(UITypeEditor))]
[Description("Floorssssssss")]
[Category("Saino")]
public partial class FloorsGrouping : Bar
{
private Items items = new Items();
private Tabs tabs = new Tabs();
public FloorsGrouping()
{
InitializeComponent();
}
[Category("Member Persisting")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Items Item
{
get
{
return items;
}
}
[Category("Collections")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(ItemsCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
public Tabs Tab
{
get
{
return tabs;
}
}
[ReadOnly(true)]
public new System.Windows.Forms.AccessibleRole AccessibleRole
{
get { return base.AccessibleRole; }
private set { base.AccessibleRole = System.Windows.Forms.AccessibleRole.ToolBar; }
}
[Browsable(false), ReadOnly(true)]
public new bool AlwaysDisplayDockTab
{
get { return base.AlwaysDisplayDockTab; }
private set { base.AlwaysDisplayDockTab = true; }
}
[Browsable(false), ReadOnly(true)]
public new bool AlwaysDisplayKeyAccelerators
{
get { return base.AlwaysDisplayKeyAccelerators; }
private set { base.AlwaysDisplayKeyAccelerators = true; }
}
[ReadOnly(true)]
public new bool AntiAlias
{
get { return base.AntiAlias; }
private set { base.AntiAlias = true; }
}
[Browsable(false), ReadOnly(true)]
public new bool AutoCreateCaptionMenu
{
get { return base.AutoCreateCaptionMenu; }
}
[ReadOnly(true)]
public new bool AutoHide
{
get { return base.AutoHide; }
}
[Browsable(false), ReadOnly(true)]
public new bool AutoHideTabTextAlwaysVisible
{
get { return base.AutoHideTabTextAlwaysVisible; }
}
[Browsable(false), ReadOnly(true)]
public new bool AutoSyncBarCaption
{
get { return base.AutoSyncBarCaption; }
private set { base.AutoSyncBarCaption = true; }
}
[Browsable(false), ReadOnly(true)]
public new eBarType BarType
{
get { return base.BarType; }
private set { base.BarType = eBarType.DockWindow; }
}
[ReadOnly(true)]
public new bool CanAutoHide
{
get { return base.CanAutoHide; }
}
[ReadOnly(true)]
public new bool CanDockTab
{
get { return base.CanDockTab; }
private set { base.CanDockTab = false; }
}
[ReadOnly(true)]
public new bool CanUndock
{
get { return base.CanUndock; }
private set { base.CanUndock = false; }
}
[Browsable(false), ReadOnly(true)]
public new bool CloseSingleTab
{
get { return base.CloseSingleTab; }
}
[Browsable(false), ReadOnly(true)]
public new bool DisplayMoreItemsOnMenu
{
get { return base.DisplayMoreItemsOnMenu; }
private set { base.DisplayMoreItemsOnMenu = true; }
}
[ReadOnly(true)]
public new DockStyle Dock
{
get { return base.Dock; }
}
[Browsable(false), ReadOnly(true)]
public new bool DockTabCloseButtonVisible
{
get { return base.DockTabCloseButtonVisible; }
}
[Browsable(false), ReadOnly(true)]
public new bool FadeEffect
{
get { return base.FadeEffect; }
private set { base.FadeEffect = true; }
}
[Browsable(false), ReadOnly(true)]
public new eGrabHandleStyle GrabHandleStyle
{
get { return base.GrabHandleStyle; }
private set { base.GrabHandleStyle = eGrabHandleStyle.Caption; }
}
[Browsable(false), ReadOnly(true)]
public new eLayoutType LayoutType
{
get { return base.LayoutType; }
private set { base.LayoutType = eLayoutType.DockContainer; }
}
[Browsable(false), ReadOnly(true)]
public new bool MenuBar
{
get { return base.MenuBar; }
}
[Browsable(false), ReadOnly(true)]
public new bool TabNavigation
{
get { return base.TabNavigation; }
private set { base.TabNavigation = true; }
}
[Browsable(false), ReadOnly(true)]
public new bool WrapItemsDock
{
get { return base.WrapItemsDock; }
private set { base.WrapItemsDock = true; }
}
protected override void OnParentChanged(EventArgs e)
{
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
}
public class Items
{
private string _Name = "SimpleItem";
private int _Id = -1;
[Category("TestProperties")]
[DefaultValue(typeof(string), "")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public string Name
{
get
{
return _Name;
}
set
{
_Name = value;
}
}
[Category("TestProperties")]
[DefaultValue(typeof(int), "-1")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public int Id
{
get
{
return _Id;
}
set
{
_Id = value;
}
}
public Items()
{
}
public Items(int Id, string Name)
{
_Id = Id;
_Name = Name;
}
}
public class Tabs : CollectionBase
{
public Items this[int Index]
{
get
{
return (Items)InnerList[Index];
}
set
{
InnerList[Index] = value;
}
}
public bool Contains(Items itemType)
{
return InnerList.Contains(itemType);
}
public int Add(Items itemType)
{
return InnerList.Add(itemType);
}
public void Remove(Items itemType)
{
InnerList.Remove(itemType);
}
public void Insert(int index, Items itemType)
{
InnerList.Insert(index, itemType);
}
public int IndexOf(Items itemType)
{
return InnerList.IndexOf(itemType);
}
public void AddRange(Items[] si)
{
InnerList.AddRange(si);
}
public Items[] GetValues()
{
Items[] si = new Items[InnerList.Count];
InnerList.CopyTo(0, si, 0, InnerList.Count);
return si;
}
protected override void OnInsert(int index, object value)
{
base.OnInsert(index, value);
}
}
public class ItemsCollectionEditor : CollectionEditor
{
private Type[] types;
public ItemsCollectionEditor(Type type)
: base(type)
{
types = new Type[] { typeof(Items) };
}
protected override Type[] CreateNewItemTypes()
{
return types;
}
}
}[/code]
<br/>
<span id="x_precollapse0" style="margin-bottom:0px <br type="_moz
<span>
Furthermore, I add assembly SecurityRulesAttribute to AssemblyInfo.cs file for solve the problem. However, it didnt work for me.<br/>
My AssemblyInfo file code is:
<div id="x_premain1" width="100%" style="display:block
<pre class="prettyprint using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WindowsFormsControlLibrary2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("SSSSSSSSS")]
[assembly: AssemblyProduct("WindowsFormsControlLibrary2")]
[assembly: AssemblyCopyright("Copyright © SSSSSSSSS 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ed5d434c-36e8-4883-a4d3-3eb6459546b3")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the * as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
//[assembly: AssemblyDelaySign(true)]
[assembly: AssemblyKeyFile("Saino.snk")]
[assembly: AssemblyKeyName("")]
[assembly: System.Security.AllowPartiallyTrustedCallers]
[assembly: SecurityRules(SecurityRuleSet.Level2, SkipVerificationInFullTrust = true)]
//[assembly: SecurityRules(SecurityRuleSet.Level1)][/code]
<br/>
<span id="x_precollapse1" style="margin-bottom:0px <br type="_moz
<span><span class="x_code-comment <hr class="sig Regards Mohsen Rostami
View the full article