issue using System.Security.Permissions in call to Azure DevOps using API

Copper Contributor
I am running into an unexpected exception when trying to use an Azure DevOps API in C#.

 

What I am trying to do is get a list of SecurityNameSpaces in an Azure DevOps server.


When I get the response from the API, it is a json text response containing a "count" node and a "value" node.
The "value" portion is an array of SecurityNamespaceDescription objects which is what is expected according to the Azure DevOps API documentation at Microsoft.
-- I don't have this issue when deserializing these types of responses for other object types (such as for TeamProjects or Idenities) if I make a response root object to deserialize into. --
My problem only seems to be with this one particular type of object, the  SecurityNamespaceDescription object.

This appears to be a problem with C# being strongly typed, as I can do this operation in Powershell without any issue. 

here is what I am doing, first I make a response root object

 

using System.Security.Permissions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.Framework.Client;

namespace azdosupport.TFSresponseModels
{
    public class SecurityNamespaceDescriptionRoot
    {
        public SecurityNamespaceDescription[] value { get; set; }   
        public int count { get; set; }
    }
}

 

 

This is exactly the same model I use for the other valid response deserializations in my project.

But... when I try to deserialize THIS API response (which I have confirmed is a valid json text response) with this call:

 

SecurityNamespaceDescriptionRoot infoblock = JsonConvert.DeserializeObject<SecurityNamespaceDescriptionRoot>(ResponseBody); 

 

this invariably this brings up the following exception:

System.IO.FileNotFoundException
  HResult=0x80070002
  Message=Could not load file or assembly 'System.Security.Permissions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
  Source=Newtonsoft.Json

 

I have tried using the System.Security.Permissions in my System assembly packages, and also by specifically loading System.Security.Permissions Version=8.0.0.0 in my project using a nuget package.

I don't see anywhere in my project that is calling for version 0.0.0.0...

As I said, since the C# operation is strongly typed, I cannot parse this list without loading and initiating the base classes, but it is failing to load them because of the version issue. In PowerShell, the Json conversion just builds a generic object corresponding to the json structure and there is no problem. I don't seem to be able to do that in C#.

Does anyone have an idea how to resolve this issue?

 

0 Replies