Error reading App reference field from items using .NET API
My local .NET API automation workflow programs have been working perfectly since September 2011, until 2 days ago when all my programs are throwing exception while reading app reference field alone in multiple podio apps-
An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll Additional information: Object of type 'Newtonsoft.Json.Linq.JArray' cannot be converted to type 'System.Collections.Generic.List`1[Podio.API.Model.FileAttachment]'.
Here is the code -
string sValue = "";
switch (field.Type)
{
case "app":
var appref = podItem.Field<AppItemField>(field.ExternalId);
var apprefitems = appref.Items;
foreach (var item in apprefitems)
{
if (!string.IsNullOrEmpty(sValue)) sValue += ";";
sValue += item.ItemId;
}
break;
Has Podio changed something internally with respect to object layout? Please let me know.
-
Official comment
I've investigated some more, and yes, we have changed something internally so that file attachments are now included in the data for items referenced in app ref fields. We didn't expect adding more data to break any client, but the .NET client is unfortunately not very flexible.
The current .NET client is user contributed and as such not officially supported or maintained by us. We are working on a new .NET client that will be released shortly. For that reason we are not going to provide a fix for the current client, but you are much welcome to fix it yourself and submit a pull request to get the fix merged into the client.
Comment actions -
Hi Casper,
My objective is to read the item ids from the app reference field of each item.
The key issue is in line number 7 and 8. “appref” all these days had an enumerable member (appref.Items) which would have a list of each “ItemId” in that field.
The code below worked perfectly fine since September 2013, but started throwing exceptions until last week.1 private string GetStringValueforField(Podio.API.Model.Item podItem, ItemField field)
2 {
3 string sValue = "";
4 switch (field.Type)
5 {
6 case "app":
7 var appref = podItem.Field<AppItemField>(field.ExternalId);
8 var apprefitems = appref.Items;
9 foreach (var item in apprefitems)
10 {
11 if (!string.IsNullOrEmpty(sValue)) sValue += ";";
12 sValue += item.ItemId;
13 }
14 break;
. . .
. . .
. . .Here is the stack and the exception that is thrown-
System.ArgumentException was unhandled
_HResult=-2147024809
_message=Object of type 'Newtonsoft.Json.Linq.JArray' cannot be converted to type 'System.Collections.Generic.List1[Podio.API.Model.FileAttachment]'.
1[Podio.API.Model.FileAttachment]'.
HResult=-2147024809
IsTransient=false
Message=Object of type 'Newtonsoft.Json.Linq.JArray' cannot be converted to type 'System.Collections.Generic.List
Source=mscorlib
StackTrace:
at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
at ObjectExtensions.objectFromDict(Object someObject, IDictionary2 source)
2 source)
at ObjectExtensions.As[T](IDictionary
at Podio.API.Model.ItemField.valueAsT
at Podio.API.Model.ItemField.valuesAsT
at Podio.API.Utils.ItemFields.AppItemField.get_Items()
at LCMMetrics.PodioAppSvc.GetStringValueforField(Item podItem, ItemField field) in c:\Users\shivakumark\Documents\Visual Studio 2012\Projects\LCMMetrics\LCMMetrics\PodioAppSvc.cs:line 304
at LCMMetrics.PodioAppSvc.ConvertItemtoNameValuePairs(Item podItem) in c:\Users\shivakumark\Documents\Visual Studio 2012\Projects\LCMMetrics\LCMMetrics\PodioAppSvc.cs:line 388
at LCMMetrics.TaskManager.RunMetrics() in c:\Users\shivakumark\Documents\Visual Studio 2012\Projects\LCMMetrics\LCMMetrics\LCMMetrics.cs:line 254
at LCMMetrics.LCMMetrics.Main(String[] args) in c:\Users\shivakumark\Documents\Visual Studio 2012\Projects\LCMMetrics\LCMMetrics\LCMMetrics.cs:line 501Thanks for helping with this.
-Shiva
-
You still haven't told me what API call you make. I understand that the error does not happen when the API is made, but later when you try to work with the app ref data. But it's important to find out what API call it is, to find out what changed.
Is it GetItem, GetItemBasic, GetItems or something else? As I already said, please tell me exactly what API call you make to get the data and the id of the app or item that you supply to the call.
-
As of now simple fix to make it work is:
Exception: Create Item Exception :Object of type 'Newtonsoft.Json.Linq.JArray' cannot be converted to type 'System.Collections.Generic.List`1[Podio.API.Model.FileAttachment]'.
Description: Now Podio is processing files , But old Podio .net api is not having supported code.
solution: Need to change below file code , as per instruction.
class: Resthelper.cs
method: private static object objectFromDict(object someObject, IDictionary<string, object> source)
Replace (1) : if ( propertyMap.ContainsKey(item.Key))
Replace above code (1) with below one.
bool file = true;
if (item.Key == "files")
{
file = false;
}
if (file && propertyMap.ContainsKey(item.Key))Note: Its worked for me.
Please sign in to leave a comment.
Comments
13 comments