错误:C#中的ItemsCollectionEditor类型违反了继承安全规则

时间:2012-10-04 05:33:00

标签: c# winforms custom-controls design-time dotnetbar

当我想将自定义控件程序集(DLL)文件添加到Visual Studio工具箱时,遇到以下错误:

从程序集“我的程序集文件”加载类型时出错。

类型违反的继承安全规则:ItemsCollectionEditor。派生类型必须与基类型的安全可访问性匹配,或者不易访问。

此外,我将程序集SecurityRulesAttribute添加到AssemblyInfo.cs文件以解决问题。但是,它对我不起作用。

我的AssemblyInfo文件代码是:

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

2 个答案:

答案 0 :(得分:1)

谢谢mikalai。你的评论对我有所了解。我可以解决我的问题。我从你的评论中了解到,我的代码可能是正确的,也可能来自其他方面的问题。根据您的评论,我发现问题并解决它我描述的解决方案如下:

如果汇编文件在GAC中注册并且汇编文件代码再次更改,并且汇编文件重新编译,并且我们要将新的重新编译的汇编文件添加到Visual Studio工具箱,则会发生此错误。发生此错误的原因是之前在GAC中注册并在GAC中注册了程序集文件的新重新编译的程序集文件与它不同。因此,必须在GAC中再次注册新的重新编译的程序集文件。

现在,如果在GAC中添加已注册的程序集文件或将新重新编译的程序集文件添加到Visual Studio工具箱,则永远不会发生此错误。

必须考虑的另一个提示是删除或评论AssemblyInfo.cs文件中的以下代码行:

[assembly: System.Security.AllowPartiallyTrustedCallers]

现在,它将正常工作。

答案 1 :(得分:1)

我从MVcMembership.cs下的App_Startand文件中删除了以下代码行。它对我来说很好。

[assembly: WebActivator.PreApplicationStartMethod(typeof(CaWorkCompCoverage.App_Start.MvcMembership), "Start")]