سؤال

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;

[assembly: AssemblyTitle("WindowsFormsControlLibrary2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("SSSSSSSSS")]
[assembly: AssemblyProduct("WindowsFormsControlLibrary2")]
[assembly: AssemblyCopyright("Copyright © SSSSSSSSS 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(false)]   
[assembly: Guid("ed5d434c-36e8-4883-a4d3-3eb6459546b3")]

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

[assembly: AssemblyKeyFile("Saino.snk")]
[assembly: AssemblyKeyName("")]
[assembly: System.Security.AllowPartiallyTrustedCallers]

[assembly: SecurityRules(SecurityRuleSet.Level2, SkipVerificationInFullTrust = true)]
هل كانت مفيدة؟

المحلول

Thank you mikalai. Your comment has a clue to me. And I could solve my problem. I understand from your comment that may be my code is correct and problem from other things. Based on your comment, 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.

نصائح أخرى

I removed the below line of code from MVcMembership.cs file under App_Startand. It worked fine for me.

[assembly: WebActivator.PreApplicationStartMethod(typeof(CaWorkCompCoverage.App_Start.MvcMembership), "Start")]
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top