0

As practice assignment I made a simple C# project which calls an external API, deserializes the resulting JSON to an IEnumerable of my class and sends it back:

public static IEnumerable<TmdbMovie> CallRestService(string uri, string method)
{
        try 
        { 
            dynamic result;
            var req = HttpWebRequest.Create(uri);
            req.Method = method;
            req.ContentType = "application/json";
            using (var resp = req.GetResponse())
            {
                 var results = new StreamReader(resp.GetResponseStream()).ReadToEnd();
                 result = JObject.Parse(results);
                 var test = JsonConvert.SerializeObject(result);
                 return JsonConvert.DeserializeObject<ApiData>(test).results.AsEnumerable();
            }
       }
       catch (Exception ex)
       {
           return null;
       }
 }

 public class ApiData
 {
      public IEnumerable<TmdbMovie> results { get; set; }
 }

When I call this method as a test within the C# project it works and correctly returns an IEnumerable of TmdbMovie.

I then added the DLLs to my C# project and to newtonsoft and then created a simple class in my Dynamics 365 FO project. I then called this function:

internal final class FM_RetrieveMovieData
{        
    public static void get()
    {
        str search = "test";
        str url = strFmt("https://api.themoviedb.org/3/search/movie?query=%1&api_key=xxxxxxxxxxxx", search);
        System.Collections.Generic.IEnumerable = MovieRentalService.Program::CallRestService(url, "GET");
    }
}

I keep getting the following error: enter image description here

I tried adding a reference to this lib in my project, but cannot even find it in the list of available .NET libs. Does someone know what causes this error?

FH-Inway
  • 4,432
  • 1
  • 20
  • 37
Kai
  • 732
  • 1
  • 7
  • 23
  • 2
    What is the Net version Dynamics expects and what Net version you used to create your library? – Ralf Sep 07 '22 at 13:34
  • @gunr2171 All right, completely understandable. I added code instead of images for the issue! – Kai Sep 07 '22 at 13:35
  • 1
    What version of Dynamics do you use and what .NET version does your C# project use? Dynamics is very picky about what .NET version it works with. – FH-Inway Sep 07 '22 at 17:05
  • It was indeed the version (it was a core project). Once I recreated the app as a class library with .NET 2.2, the code worked! – Kai Sep 22 '22 at 13:08

0 Answers0