Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
When I want to add my custom control assembly (DLL) file to the Visual Studio Toolbox, I encounter with following error:
There was an error loading types from assembly "my assembly file."
Inheritance security rules violated by type: ItemsCollectionEditor. Derived types must either match the security accessibility of the base type or be less accessible.
Furthermore, I add assembly SecurityRulesAttribute to AssemblyInfo.cs file for solve the problem. However, it didn't work for me.
My AssemblyInfo file code is:
C#
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)]
Posted
Updated 24-Oct-19 6:10am
v2
Comments
Kenneth Haugland 4-Oct-12 5:08am    
That was a massive code dump... If you want an answer you should focus on your specific problem, and not dump your entire code here.
MRS1989 4-Oct-12 5:14am    
In title of my Question, ItemsCollectionEditor has come. So, I guess that error may be from following section, but I'm not sure:

public class ItemsCollectionEditor : CollectionEditor
{
private Type[] types;

public ItemsCollectionEditor(Type type)
: base(type)
{
types = new Type[] { typeof(Items) };

}

protected override Type[] CreateNewItemTypes()
{
return types;
}
}

For this reason, I add all my codes in here.

I understand that may be my code is correct and problem from other things. Based on that, I find the problem and solve it that I describe solution as follows:
If the assembly file is registered in the GAC and assembly file codes change again, and assembly file re-compiles, and we want to add new recompiled assembly file to Visual Studio toolbox, this error will occur. The reason of occurring this error is that new recompiled assembly file, registered in GAC before and registered assembly file in GAC is different with it. So, new recompiled assembly file must be registered again in GAC.
Now, If add registered assembly file in GAC or new recompiled assembly file to the Visual Studio toolbox, this error will never occur.
Another tip that must be considered, is deleting or commenting following line of code in AssemblyInfo.cs file:
C#
[assembly: System.Security.AllowPartiallyTrustedCallers]

And now, it will work correctly.
 
Share this answer
 
Comments
vijaymodi_81 11-Apr-13 8:34am    
Good one. Thanks
Member 10041736 12-Sep-14 3:18am    
Thank you sooooooo much ... Its saves my time
I was facing this error "inheritance security rules violated by type" in a Windows Service that used WCF components.

The same service worked on other server, but in a specific one, it didn't.

What fixed this error was commenting the following line in the app.config file.

<NetFx40_LegacySecurityPolicy enabled="true" />


We took a lot to figure it out, hope it helps somebody.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900