SecurityCritical on overriden function InitializeLifetimeService has not affect

老子叫甜甜 提交于 2020-01-15 08:05:11

问题


I'm running into some Medium trust issues with a few libraries. I'm able to reproduce the error with a sample and referencing that in my MVC probject. I'm trying to get pass this problem but don't understand what I'm missing.

I keep getting this error:

Inheritance security rules violated while overriding member: 'Temp.Class1.InitializeLifetimeService()'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.

I think understand the security transparency error above, and I make sure my method is the same as the overriding method. Here is my class:

public class Class1 : MarshalByRefObject
{

    [SecurityCritical]
    public override object InitializeLifetimeService()
    {
        return null;
    }

}

And I am still getting the same error as above.

Have been adding and removing this line with no effect:

[assembly: AllowPartiallyTrustedCallers()]

Reading other articles all I have to do is to add the SecurityCritical attribute to the method, but it does not seem to have any affect.

Any ideas, or something that I'm missing?


回答1:


In a Medium trust web application, only GACed binaries are granted full trust permissions. If your binary is bin-deployed, it is partial-trust and transparent. MSDN has a good write-up of what transparent code can and cannot do. Importantly, declaring a [SecurityCritical] member is a full-trust only operation. If your bin-deployed library contains a member annotated with [SecurityCritical], the CLR will ignore that annotation.

If your library is designed to be bin-deployed and runnable in Medium trust, you cannot override or otherwise access a [SecurityCritical] member. Consider reworking your library so as not to call these methods.



来源:https://stackoverflow.com/questions/4713123/securitycritical-on-overriden-function-initializelifetimeservice-has-not-affect

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