Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8289269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:28:12+00:00 2026-06-08T12:28:12+00:00

I am working on a web application in silverlight. I have overloaded the WebClient.GetWebRequest

  • 0

I am working on a web application in silverlight. I have overloaded the WebClient.GetWebRequest method as given below:-

public class WebClientWithCookies : WebClient
    {
        [SecurityCritical]
        protected override WebRequest GetWebRequest(Uri address)
        {
            string cookieContent = HtmlPage.Document.Cookies;

            WebRequest request = base.GetWebRequest(address);
            HttpWebRequest webRequest = request as HttpWebRequest;
            if (webRequest != null && cookieContent != null && cookieContent != string.Empty)
            {
                CookieContainer cookieContainer = new CookieContainer();
                cookieContainer.Add(address, new Cookie() { Value = HtmlPage.Document.Cookies });
                webRequest.CookieContainer = cookieContainer;
            }
            return request;
        }
    }

But I am getting the following exception:

System.TypeInitializationException was unhandled by user code
Message=The type initializer for ‘SigmaWC.Utility.RestCommunicator’
threw an exception. TypeName=SigmaWC.Utility.RestCommunicator
StackTrace:
at SigmaWC.Utility.RestCommunicator..ctor()
at SigmaWC.App..ctor() InnerException: System.TypeLoadException
Message=Inheritance security rules violated while overriding member: ‘SigmaWC.Utility.WebClientWithCookies..ctor()’. Security
accessibility of the overriding method must match the security
accessibility of the method being overriden.
StackTrace:
at SigmaWC.Utility.RestCommunicator..cctor()
InnerException:

Can anyone help in how to elevate the security settings in silverlight.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:28:13+00:00Added an answer on June 8, 2026 at 12:28 pm

    Documentation about this is scarce to say the least. However, there are a couple of resources which are useful:

    MSDN Indicates that you cannot use framework members with a SecurityCriticalAttribute.

    Types and members that have the SecurityCriticalAttribute cannot be used by Silverlight application code. Security-critical types and members can be used only by trusted code in the .NET Framework for Silverlight class library.

    In the case of WebClient, the GetWebRequest method does not have this attribute, however the constructor does.

    This MSDN Security blog Implies that if the default constructor has any Security attribute, the class cannot be used for inheritance in a Silverlight client.

    Further to that, the aforementioned MSDN blog implies that Security attributes are ignored in Silverlight assemblies which are not part of the core framework. This may however only apply to Assembly level attributes.

    Anyway, to cut a long story short. You cannot derive from WebClient because of the SecuritySafeAttribute on the constructor.
    To illustrate the point, this also causes an exception at runtime:

    public class MyWebClient : WebClient
    {
    
    }
    

    The alternative is to roll your own WebClient. It takes a little work, but the following example does work with the following handler:

    public class MyHandler : IHttpHandler
    {
    
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write("Hello World");
            foreach (Cookie cookie in context.Response.Cookies)
            {
                //Cookies from the client - there will be 1 in this case
            }
        }
    

    …

    public class MyWebClient
    {
        public MyWebClient()
        {
    
        }
    
        public void InvokeWebRequest(Uri address)
        {
            //Set the cookie you want to use.
            string cookieContent = "I like cookies";
    
            // Register a http client - without this the following webRequest.CookieContainer setter will throw an exception
            WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
    
            //This bit you know, but dont forget to set Name on your new Cookie.
            HttpWebRequest webRequest = WebRequest.Create(address.AbsoluteUri) as HttpWebRequest;
            if (webRequest != null && !String.IsNullOrWhiteSpace(cookieContent))
            {
                webRequest.CookieContainer = new CookieContainer();
                webRequest.CookieContainer.Add(address, new Cookie() { Value = cookieContent, Name = "MyCookie" });
            }
    
            //Invoke the async GetResponse method.
            webRequest.BeginGetResponse(o =>
                {
                    HttpWebResponse response = (HttpWebResponse)webRequest.EndGetResponse(o);
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        //Read the result
                        string result = reader.ReadToEnd();
                    }
    
                    foreach (Cookie cookie in response.Cookies)
                    {
                        //The cookies returned from the server.
                    }
                }, null);
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working in Silverlight 4.0 and have created a web application which is
I'm currently working on web application using VB in ASP.NET. Right now I have
Im working on a Web-Application (MyWebApp). I have a Service-Reference to a WCF-Webservice. The
I am working on a web application (asp.net mvc3) I have a Main div.
I'm working on a web application. I have entities that are supposed to be
I'm working on a web application written on php. I have some objects (represented
I am working on a Silverlight application that uses WCF. I need to have
I have a WCF web service for a silverlight application that doesn't seem to
I'm working with a XAML file in a Silverlight Web application. I'm using JavaScript
I am fairly new to Silverlight. I have an application I'm working on that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.