我是學習Dynamics 365插件的開發人員。Dynamics 365插件SDK在沙盒模式下更新強類型實體時拋出異常
問題:在強類型實體上調用Update方法時,我得到一個異常。確切的錯誤信息是:
「System.Runtime.Serialization.SerializationException:Microsoft Dynamics CRM中遇到錯誤,爲管理員或支持參考編號:#1330ADC1」
我的設置: 我的解決方案包含一個簡單的插件。我創建了一個強類型的實體帳戶。插件的隔離模式是沙盒。 Telephone1字段是一個字符串。
我從CRM中檢索帳戶,然後將Telephone1字段更新爲新值並更新帳戶記錄。簡單:)
代碼:
public class PostOperationaccountUpdate: IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
var organisationService = serviceProvider.GetService(typeof (IOrganizationService)) as IOrganizationService;
var context = serviceProvider.GetService(typeof (IPluginExecutionContext)) as IPluginExecutionContext;
var entityAccount = context.InputParameters["Target"] as Entity;
var id = entityAccount.Id;
var account = organisationService.Retrieve("account", id, new ColumnSet("telephone1"));
//Get a strongly typed version of the Account entity
var dbAccount = account.ToEntity<Account>();
//Update the telephone1 field using the "old" way
account["telephone1"] = "1234567890";
try
{
//This will pass
organisationService.Update(account);
//Update the strongly typed Account
dbAccount.Telephone1 = "plop";
//This fails
organisationService.Update(dbAccount);
}
catch (Exception ex)
{
throw;
}
}
}
有什麼我想: - >我已經改變了插件的隔離模式到無 - 這工作!按照最佳做法,不建議
感謝您的幫助 查爾斯
不它在沙箱中工作,如果你遲到了嗎? – Alex
碰巧強類型Account類是不同的DLL嗎?如果是這樣,我相信你將不得不將其插入到插件DLL中。您可以通過直接將Account.cs類添加到您的插件項目中來快速測試。 – Polshgiant
@亞歷克斯:是的。如果我讓它延遲和沙箱它,它確實工作 – h4ck3r8ug5