locked
CA2122: Do not indirectly expose methods with link demands. , Why and How to fix in my code?

    Question

  • CA2122: Do not indirectly expose methods with link demands.

    My code is as follows: 

     

     public void LoadPage(Uri url)

            {

                webBrowser1.Url = url;

                webBrowser1.Refresh();

            }

    Fxcop produced the warning "CA2122: Do not indirectly expose methods with link demands."

     

    1. Why this warning appeared on my code?

    2. How to fix it?

    Wednesday, March 24, 2010 12:14 PM

Answers

  • You're seeing this warning because the System.Windows.Forms.WebBrowser (which is what I'm guessing "webBrowser1" represents) has a LinkDemand for full trust.  A partially trusted caller could potentially bypass that demand by invoking your public method.

    The simplest way to address this problem is to mark your assembly with SecurityTransparentAttribute.  This will prevent if from satisfying any link demands on behalf of its callers.

    Wednesday, March 24, 2010 4:27 PM

All replies

  • You're seeing this warning because the System.Windows.Forms.WebBrowser (which is what I'm guessing "webBrowser1" represents) has a LinkDemand for full trust.  A partially trusted caller could potentially bypass that demand by invoking your public method.

    The simplest way to address this problem is to mark your assembly with SecurityTransparentAttribute.  This will prevent if from satisfying any link demands on behalf of its callers.

    Wednesday, March 24, 2010 4:27 PM
  • You're seeing this warning because the System.Windows.Forms.WebBrowser (which is what I'm guessing "webBrowser1" represents) has a LinkDemand for full trust.  A partially trusted caller could potentially bypass that demand by invoking your public method.

    The simplest way to address this problem is to mark your assembly with SecurityTransparentAttribute.  This will prevent if from satisfying any link demands on behalf of its callers.

    • Proposed as answer by Cabadam Wednesday, October 19, 2011 10:20 PM
    • Unproposed as answer by Cabadam Wednesday, October 19, 2011 10:20 PM
    Wednesday, March 24, 2010 4:27 PM
  • Thanks Nicole , It worked . Now I do not have warnings in Fxcop. 

    Can you please suggest few good links/articles for CAS ,

    I am little confused on how to give permission to code/Assembly to meet the request of CAS attribute. i.e How can I make my code Full trusted?

    Thanks,

    Mansoor Mehmood 

    Thursday, March 25, 2010 5:19 AM