1

I'm trying to integrate the Google Sheets API with a C# project on .NET 4.6 but am running into issues.

Initially my issues were that my project uses a more recent version of NewtonSoft.JSON than the Sheets API, so I had to pull the code for the Sheets API, update the NewtonSoft reference and republish it. In doing this I also had to update the Sheets API projects to .NET 4.6.

Unfortunately in doing this I now get this exception when running my C# project:

Inheritance security rules violated while overriding member: 'Google.GData.Client.GDataRequestException.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'.
Security accessibility of the overriding method must match the security accessibility of the method being overriden.

Following a post on StackOverflow I added the SecurityCritical attribute to the method GetObjectData.

Post: Inheritance security rules violated while overriding member - SecurityRuleSet.Level2

(As a note, this function already had the attribute SecurityPermissionAttribute(SecurityAction.Demand, SeralizationFormatter=true) attached to it)

Doing this allowed me to build my C# project and use the Google Client to perform OAuth2, but when attempting to access the Sheets API I was presented with this error:

Attempt by security transparent method 'Google.GData.Client.Utilities.DecodedValue(System.String)' to access LinkDemand protected method 'Google.GData.Client.HttpUtility.HtmlDecode(System.String)' failed.  
Methods must be security critical or security safe-critical to satisfy a LinkDemand.

I am unsure if these two things are related but am not familiar with security in C# projects and so have included both in case they are.

Has anyone else run into similar problems / gotten Google Sheets API to run in a .NET 4.6 project?

Community
  • 1
  • 1
Harold
  • 1,068
  • 4
  • 14
  • 35

0 Answers0