Kai
Kai

Reputation: 790

Call function in C# lib that return in IEnumerable in X++ gives unclear error

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?

Upvotes: 0

Views: 257

Answers (0)

Related Questions