我正在使用 .NET 的官方 API 并尝试在应用程序中添加新项目。这段代码曾经工作过一次,但后来发生了一些变化(不在代码中),它不再工作了。这是代码:
{
var podio = new Podio(clientId, clientSecret);
podio.AuthenticateWithApp(appId, appSecret);
Item myNewItem = new Item();
var namefield = myNewItem.Field<TextItemField>("applicants-name");
if (model.Name != null)
{
namefield.Value = model.Name;
}
else
{
namefield.Value = "/";
}
var jobfield = myNewItem.Field<AppItemField>("related-job-opening");
jobfield.ItemIds = new List<int> { model.RelatedJob };
var addressfield = myNewItem.Field<TextItemField>("address");
if (model.Address != null)
{
addressfield.Value = model.Address;
}
else
{
addressfield.Value = "/";
}
var emailfield = myNewItem.Field<TextItemField>("email-address");
if (model.Email != null)
{
emailfield.Value = model.Email;
}
else
{
emailfield.Value = "/";
}
if (model.Linkedin != null)
{
var embed = podio.EmbedService.AddAnEmbed(model.Linkedin);
var linkedin = myNewItem.Field<EmbedItemField>("linkedin-profile2");
linkedin.AddEmbed(embed.EmbedId);
}
var phone = myNewItem.Field<TextItemField>("contact-phone-number");
if (model.Phone != null)
{
phone.Value = model.Phone;
}
else
{
phone.Value = "/";
}
if (model.Attachment != null)
{
var fileName = Path.GetFileName(model.Attachment.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
model.Attachment.SaveAs(path);
string extension = Path.GetExtension(model.Attachment.FileName);
FileAttachment podioFile = podio.FileService.UploadFile(path, "user-cv" + extension);
myNewItem.FileIds = new List<int> { podioFile.FileId };
System.IO.File.Delete(path);
int itemId = podio.ItemService.AddNewItem(appId, myNewItem);
}
else
{
int itemId = podio.ItemService.AddNewItem(appId, myNewItem);
}
return "OK";
}
}
这是抛出错误的代码行:
int itemId = podio.ItemService.AddNewItem(appId, myNewItem);
错误提示:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:“无法对空引用执行运行时绑定”
实际上抛出了错误,但该项目已成功添加到跑道中。可能出了什么问题?
尝试更新您的 Podio .Net API 包,在上次更新中,有一些更改,例如修订 ID 数据类型从 int 更改为 long。如果您仍在使用旧库,这将导致错误。