none
WCF service reference can read data but not write it RRS feed

  • Question

  • I have a WCF service reference in a windows universal application. 

    It simply exposes a entity framework data model. I can retrieve data without any trouble but when I try to save data to the service I get the following exception: 

    Inheritance security rules violated while overriding member: 'System.Data.Entity.Utilities.TaskExtensions+CultureAwaiter`1<T>.UnsafeOnCompleted(System.Action)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.

    The service works fine locally, it only causes trouble when it's deployed. Any ideas?

    I've checked and my local and server are both running the same version of .NET. 

    What information might be helpful? Here's my web.config: 

    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <system.web>
        <customErrors mode="Off" />
      </system.web>
      <system.serviceModel>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
              <serviceDebug includeExceptionDetailInFaults="True" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
      <connectionStrings>
        <add name="GMesEntities" connectionString="***" providerName="System.Data.EntityClient" />
      </connectionStrings>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
      </entityFramework>
    </configuration>

    Friday, December 4, 2015 7:58 AM

Answers

  • https://www.google.com/?gws_rd=ssl#q=Security+accessibility+of+the+overriding+method+must+match+the+security+accessibility+of+the+method+being+overriden.

    I think you may find your answer as it is being talked about and using <Trust Level>

    And Bing and Google are your friends. 

    • Proposed as answer by MDeero Monday, December 7, 2015 8:16 AM
    • Marked as answer by Carbaholic Tuesday, December 15, 2015 3:21 AM
    Friday, December 4, 2015 5:28 PM

All replies

  • https://www.google.com/?gws_rd=ssl#q=Security+accessibility+of+the+overriding+method+must+match+the+security+accessibility+of+the+method+being+overriden.

    I think you may find your answer as it is being talked about and using <Trust Level>

    And Bing and Google are your friends. 

    • Proposed as answer by MDeero Monday, December 7, 2015 8:16 AM
    • Marked as answer by Carbaholic Tuesday, December 15, 2015 3:21 AM
    Friday, December 4, 2015 5:28 PM
  • This exception is happening from within the Entity Framework .DLLs. Please take note that the service works fine when run locally but not when published. 

    Friday, December 4, 2015 9:33 PM
  • Hi Carbaholic,

    According to the error message, it looks like an Entity Framework issue. You said that 

    your server works fine locally. So that means your service is correctly. In my opinion,

    perhaps that method didn't add some security attributes, then caused  this issue.

    So, maybe we can try add this attribute to that method. Mark UnsafeOnCompleted with

    SecurityCriticalAttribute, because it's applied to Exception.GetObjectData. An overridden

    member should have the same security accessibility.

    For more information, please refer to the following articles:

    1.Security Changes in the .NET Framework 4

    2.Security Transparent Code, Level 2

    Best Regards,

    WanDong


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Monday, December 7, 2015 8:07 AM
    Moderator
  • It's funny how searching the web is way under-used by "software developers".

    It is an issue with trust level, The EF is not instaklled in GAC so it needs to be trusted to override Methods which are marked with [SecurityCritical] Attributes. EF does that as it seems, may be related to Login via WindowsAccounts that they do it, or due to Impersonation.

    Also... not only google gives an answer, but if you search in this forums you will find answers too:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/dd8ba5a6-8668-478d-8f2c-aebee79690ac/the-security-accessibility-of-the-overriding-method-must-match-the-security-accessibility-of-the?forum=clr

    Cheers

    Monday, December 7, 2015 8:20 AM
  • MDeero, Your insults are not helpful. I have spent a number of hours searching through google and through this forum. I am not very experienced using WCF and so don't always know what key words to search for. 

    How would you feel if you were new to the forum and someone answered your question the way you answered mine? Has anyone ever made fun of you in your past? How did that make you feel?

    If the members of this forum can't manage friendliness I expect to at least be treated with professionalism.

    • Edited by Carbaholic Monday, December 7, 2015 8:24 PM
    Monday, December 7, 2015 8:20 PM
  • If I mark the method with the SecurityCriticalAttribute will I need to register entity framework in the GAC? I don't think I will be able to do that because I am deploying the service onto GoDaddy and so don't have administrative privileges on the server.

    I haven't done any work with WCF for 7 years and so I'm starting from scratch and I've never deployed to a server where I wasn't an administrator so please be patient with my ignorance. 

    Eric


    • Edited by Carbaholic Monday, December 7, 2015 8:38 PM
    Monday, December 7, 2015 8:37 PM
  • I appologize... I was not making fun of you in particular,

    I just really find that funny. If I insulted you, I really regret that.

    The other lines I wrote still apply.

    You know I see a lot of duplicate questions cause the Users don't use the search function in this forum. It should just have been a hint, that it can also be used like an search engine, only specialized on Microsofts Software Development products.

    Sincerely

    MDeero

    "software developers" is in quotes not to mock, but to refer to hobbiists too. I can see how that would look like an insult
    • Edited by MDeero Tuesday, December 8, 2015 7:37 AM
    Tuesday, December 8, 2015 7:35 AM
  • You may be able to solve your issue through using this
    Tuesday, December 8, 2015 7:42 AM
  • This is my entire service: 

        public class GMesDataService : IGMesDataService
        {
            public List<HejMessage> GetHejMessages()
            {
                GMesEntities dataContext = new GMesEntities();
                return dataContext.HejMessages.ToList();
            }
    
            public void SaveHejMessage(HejMessage msg)
            {
                GMesEntities dataContext = new GMesEntities();
                dataContext.HejMessages.Add(msg);
                dataContext.SaveChangesAsync();
            }
        }

    The only one that fails is the SaveHejMessage method...but it doesn't inherit from or override anything. Does it need to be trusted?

    Tuesday, December 15, 2015 2:49 AM
  • Thanks for the lead to trust issues gentlemen. f

    It turns out that I host on GoDaddy and their hosting does run in a trusted environment, but you have to put the following in your web config to make that happen. 

        <system.web>
            <trust level="Full" />
        </system.web>

    I'll go ahead and mark the first trust-related answer as the answer. 

    Regards


    • Edited by Carbaholic Tuesday, December 15, 2015 3:31 PM
    Tuesday, December 15, 2015 3:21 AM
  • Hi Carbaholic

    Thanks for sharing your solution.

    Best Regards,

    Wanjun Dong


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Tuesday, December 15, 2015 3:30 AM
    Moderator