Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm testing some code here, trying to get it to work with CAS. I have a configuration file at a file location with some WCF definitions. I load this code with:

var config = ConfigurationManager.OpenExeConfiguration(@"C:\path\client.config");

which works just fine. I can also load it with File.ReadAllText(...), as I've added the CAS permissions to read the file. However when I call:

ConfigurationSection section = config.GetSection("system.serviceModel/client");

I get a security exception that I'm not allowed to read the section. Is there a way around this without modifying machine.config. The config class is passed to a WCF proxy class.

My other option is to recreate the WCF proxy class, reading the .config file as xml and manually set all the properties A lot more work.

Or I'll give up and just GAC it instead. But I hate to give up.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I just reflectored the ConfigSection class for the client section of the servicemodel section. The GetSection method of this class has the SecurityCriticalAttribute applied to it. This means (according to the msdn page):

The SecurityCriticalAttribute is equivalent to a link demand for full trust. A type or member marked with the SecurityCriticalAttribute can be called only by fully trusted code; it does not have to demand specific permissions. It cannot be called by partially trusted code.

share|improve this answer
    
Thanks Coling! As I've spent all day in Reflector, how on earth did I miss this :) And guess it would be pretty hard to omit this even with reflection trickery. –  Mikael Svenson Jun 21 '11 at 19:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.