错误:C#中的ItemsCollectionEditor类型违反了继承安全规则 [英] Error: Inheritance security rules violated by type ItemsCollectionEditor in C#

查看:136
本文介绍了错误:C#中的ItemsCollectionEditor类型违反了继承安全规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我要将自定义控件程序集(DLL)文件添加到Visual Studio工具箱时,遇到以下错误:
从程序集我的程序集文件"中加载类型时出错.
类型违反的继承安全规则:ItemsCollectionEditor.派生类型必须与基本类型的安全可访问性匹配,或者不可访问.
此外,我将程序集SecurityRulesAttribute添加到AssemblyInfo.cs文件中以解决该问题.但是,它对我不起作用.
我的AssemblyInfo文件代码为:

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

推荐答案

我知道这可能是我的代码正确,并且是其他原因造成的问题.基于此,我发现问题并解决了,我将解决方案描述如下:
如果在GAC中注册了程序集文件,并且程序集文件代码再次更改,并且程序集文件重新编译,并且我们要将新的重新编译的程序集文件添加到Visual Studio工具箱中,则会发生此错误.发生此错误的原因是,之前在GAC中注册的新的重新编译的程序集文件和在GAC中注册的新的程序集文件与此不同.因此,必须在GAC中再次注册新的重新编译的程序集文件. 现在,如果将GAC中已注册的程序集文件或新的重新编译的程序集文件添加到Visual Studio工具箱中,将永远不会发生此错误.
必须考虑的另一个技巧是删除或注释AssemblyInfo.cs文件中的以下代码行:
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.


这篇关于错误:C#中的ItemsCollectionEditor类型违反了继承安全规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆