Quantcast
Channel: NAV Three Tier — mibuso.com
Viewing all articles
Browse latest Browse all 10032

dotnet interop : serialize

$
0
0
Hello all ! :)

I'm just making an app that will contact a JSON webservice and return an odject to NAV 2013 R2.

But an issue is occuring when i try to use it in NAV : unable to serialize an instance of the object .NET Framework....

My assembly is in the GAC, and in the Add-in folder, signed.

I don't have this issue while trying to debug in VS2012.

I think the problem comes from my NAV C/AL Code... but can't find a solution :(

I hope someone will be able to help me :)

I'm using a dotnet component which one returns a collection of spécific objects created in the dev :

Objects :

public class Trade
{
public string time { get; set; }
public int type { get; set; }
public string price { get; set; }
public string amount { get; set; }
public string total { get; set; }
}

public class Trades
{
public int count { get; set; }
public List<Trade> trades { get; set; }
//public TradeList trades{get;set;}
public Trade GetTradeItem(int P_Index)
{
return trades[P_Index];
}
}


Method that return the Trade collection object after JSON serialization :

public class Stat
{
public Trades GetMarket()
{
try
{
string url = GetURL();
WebRequest request = WebRequest.Create(url);
request.Method = "GET";
WebResponse ws = request.GetResponse();

Stream s = ws.GetResponseStream();

DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(Trades));
Trades retour = (Trades)jsonSerializer.ReadObject(s);

//DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(StatItem));
//StatItem retour = (StatItem)jsonSerializer.ReadObject(s);

return retour;
}
************************ (others methods not described here) *************
}
}

NAV Code :

/////// Vars /////
Stat ==> My C# Stat Class
Item ==> My C# Trade Class
ListItem ==> My C# Trades Class

//// End var ////

Stat := Stat.Stat;
Item := Item.Trade;
ListItem := ListItem.Trades;


ListItem := Stat.GetMarket;
FOR I:=0 TO (ListItem.count-1) DO
BEGIN
Item := ListItem.GetTradeItem(I);
MESSAGE(Item.amount);
END;


But always receive the same error message :

Unable to serialize an instance of this .NET Framework object : Assembly : tradetest ......... , type Tradetest.Trades

Many thanks to my future helpers :)

PS : apologize for my english... it could be better :)

Viewing all articles
Browse latest Browse all 10032

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>