Click here to Skip to main content
Sign Up to vote bad
good
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:
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 3 Oct '12 - 22:48
Edited 6 Oct '12 - 20:15

Comments
Kenneth Haugland - 4 Oct '12 - 5:08
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.
Mohsen Rostami - 4 Oct '12 - 5:14
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.

1 solution

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:
[assembly: System.Security.AllowPartiallyTrustedCallers]
And now, it will work correctly.
  Permalink  
Comments
vijaymodi_81 - 11 Apr '13 - 8:34
Good one. Thanks

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 208
1 OriginalGriff 203
2 Rohan Leuva 195
3 Abhinav S 168
4 Mahesh Bailwal 145
0 Sergey Alexandrovich Kryukov 8,474
1 OriginalGriff 6,714
2 CPallini 3,603
3 Rohan Leuva 2,853
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 7 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid