Derived types must either match the security accessibility of the base type or be less accessible in very basic case

谁都会走 提交于 2019-12-08 12:38:58

问题


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

回答1:


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".




回答2:


I found source of the problem: it was System.Security.AllowPartiallyTrustedCallers set on the non-portable assembly, which contains WhiteSpaceToken. After I removed it, issue was gone. Looks like portable code had transparent model, which caused WhiteSpaceToken to be more loose in the sense of security, than Token, which in turn caused the problem as described in exception message.

Wish I those messages be more specific.



来源:https://stackoverflow.com/questions/20767216/derived-types-must-either-match-the-security-accessibility-of-the-base-type-or-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!