派生类型必须与基本类型的安全性可访问性匹配,或者在非常基本的情况下不可访问性 [英] Derived types must either match the security accessibility of the base type or be less accessible in very basic case

查看:263
本文介绍了派生类型必须与基本类型的安全性可访问性匹配,或者在非常基本的情况下不可访问性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

构建示例代码,然后运行任何测试。 (我尝试过 abs 。)



每次执行此操作,都会得到 TypeLoadException


Jurassic.dll中发生类型'System.TypeLoadException'的异常,但未在用户代码中处理



其他信息:继承类型为'Jurassic.Compiler.WhiteSpaceToken'的继承安全规则。派生类型必须与基本类型的安全性可访问性匹配,或者必须较不易于访问。


问题是 WhiteSpaceToken 是一个简单的类, Token 是其基础。因此,看起来异常实际上并未提供有关类名的准确信息,并且该错误可能是由其他代码引起的。



在这种情况下,我的理解几乎为0 。我唯一能想到的解释是,您不能从可移植库中继承一个抽象类,但我从未听说过这种限制。



任何想法为什么会这样?



PS根据评论中的要求添加一些有关代码结构的快速信息


  1. 令牌类是面向.NET 4的可移植库中的公共抽象类。 ,Silverlight 5,Windows 8和Windows Phone8。它仅与 mscorlib 中的字符串类一起使用。

  2. WhiteSpaceToken 在常规程序集中,定位于.NET4。它继承自 Token 。也仅适用于 int string

  3. 这两个类都没有任何属性

  4. 单元测试程序集是针对目标4.0的MSTest的常规单元测试程序。


解决方案

您的问题和答案对我有很大帮助,谢谢!!!!!!!!!!!!!!!!!!属性,然后在安全性标签中取消选中启用ClieckOnce安全性设置。


Build the sample code, and run any test. (I tried abs.)

Each time I do it, I get TypeLoadException:

An exception of type 'System.TypeLoadException' occurred in Jurassic.dll but was not handled in user code

Additional information: Inheritance security rules violated by type: 'Jurassic.Compiler.WhiteSpaceToken'. Derived types must either match the security accessibility of the base type or be less accessible.

The problem is WhiteSpaceToken is a simple class, as so is Token, its base. So it looks like exception is not actually providing accurate information about the class name, and the error is probably caused by some other code.

My understanding is nearly 0 at this case. The only explanation I could possibly imagine is that you can't inherit an abstract class from portable library, but I've never heard about this kind of restriction.

Any ideas why is this happening?

P.S. Adding some quick info about code structure, as requested in comment

  1. Token class is a public abstract class in a portable library targeted to .NET 4, Silverlight 5, Windows 8, and Windows Phone 8. It only works with string class from mscorlib.
  2. WhiteSpaceToken is in a normal assembly, targeted to .NET 4. It inherits from Token. Also only works with int and string.
  3. Neither class has any attributes in its code.
  4. The unit test assembly is a normal unit test assembly on MSTest targeted 4.0

解决方案

your question and answer helped me a lot, thanks!!!

I've solved my issue by opening the project properties and in the Security tab I've unchecked the "Enable ClieckOnce security settings".

这篇关于派生类型必须与基本类型的安全性可访问性匹配,或者在非常基本的情况下不可访问性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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