none
Error: Inheritance security rules violated by type ItemsCollectionEditor in C#

    Question

  • 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)]



    Regards Mohsen Rostami


    • Edited by MRS1367 Sunday, October 07, 2012 6:15 AM
    Thursday, October 04, 2012 8:51 AM

Answers

  • 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.

    Regards Mohsen Rostami

    • Marked as answer by MRS1367 Saturday, October 06, 2012 9:33 AM
    Saturday, October 06, 2012 9:30 AM

All replies

  • Hi MRS1367,

      Welcome to MSDN Forum Support.

      We're doing research on this issue. It might take some time before we get back to you.

      Sincerely,

      Jason Wang




    Jason Wang [MSFT]
    MSDN Community Support | Feedback to us

    Friday, October 05, 2012 4:11 AM
    Moderator
  • Hi Jason Dot Wang

    Tnx 4 ur help and attention.


    Regards Mohsen Rostami

    Friday, October 05, 2012 6:02 AM
  • 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.

    Regards Mohsen Rostami

    • Marked as answer by MRS1367 Saturday, October 06, 2012 9:33 AM
    Saturday, October 06, 2012 9:30 AM