【问题标题】:Error: Inheritance security rules violated by type ItemsCollectionEditor in C#错误:C# 中的 ItemsCollectionEditor 类型违反了继承安全规则
【发布时间】:2012-10-04 05:33:00
【问题描述】:

当我想将自定义控件程序集 (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)]

【问题讨论】:

  • 首先你应该找出基类程序集(DevComponents 或类似的东西)的安全属性,例如使用 ilasm。
  • Tnx 米卡莱。我检查一下。

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


【解决方案1】:

谢谢米卡莱。你的评论对我有线索。我可以解决我的问题。我从您的评论中了解到,可能是我的代码是正确的,而其他方面的问题。根据您的评论,我找到了问题并解决了,我将解决方案描述如下:

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

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

另一个必须考虑的技巧是删除或注释 AssemblyInfo.cs 文件中的以下代码行:

[assembly: System.Security.AllowPartiallyTrustedCallers]

现在,它可以正常工作了。

【讨论】:

  • 很高兴看到。如果您现在了解该案例,为了社区的利益,最好重新表述您现在看到的描述问题的初始问题(没有源代码,如果它与这里无关)。
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 2021-05-16
    • 2018-04-23
    • 1970-01-01
    • 1970-01-01
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多