我期待建立一個相當簡單的插件,計算剩餘使用的「單位」數量&。 我有兩個自定義實體bc_learninglicences
& bc_llbalance
,插件在創建bc_llbalance
時觸發,另一個用於更新。客戶關係管理2011年:插件 - 無法加載文件或程序集'Microsoft.Xrm.Client'
bc_llbalance: Contains
bc_learninglicense (Look up field on bc_learninglicences/bc_name)
bc_units (units that are used by this record)
bc_learninglicences: Contains
bc_name
bc_unitsquantity (This is set to the total qty of units)
bc_unitsused (this needs to inherit the sum of "bc_units" on "bc_llbalance")
bc_unitsremaining (simply bc_unitsquantity - bc_unitsused)
好了,所以我已經包括這正如我剛纔一直在試圖找出如何讓bc_unitsused
繼承的總和顯然沒有完成的代碼... 這個代碼生成沒有錯誤。然而CRM錯誤:LearningLicenses.LearningLicenses:
從插件(執行)意外異常System.IO.FileNotFoundException:未能加載文件或程序集「Microsoft.Xrm.Client,版本= 5.0.9690.2165
我有一個短的期限內建立這個作爲系統是由於住淳去,但我不能與這個錯誤,我不明白前進......
要麼錯誤或代碼幫助/解決方案將讚賞在這一點上,因爲我在這個項目的時間框架後面。
p.s我是新開發的CRM 2011,只有幾周/幾個項目經驗。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Messages;
using System.Text.RegularExpressions;
using System.ServiceModel;
namespace LearningLicenses
{
public class LearningLicenses : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
try
{
// Obtain the execution context from the service provider.
Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parmameters.
Entity entity = (Entity)context.InputParameters["Target"];
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
EntityReference a = (EntityReference)entity.Attributes["bc_learninglicense"];// ((EntityReference)targetEntity.Attributes["bc_learninglicense"]).Id;
if (entity.LogicalName == "bc_llbalance")
try
{
//fetchxml to get the sum total of estimatedvalue
string value_sum = string.Format(@"
<fetch distinct='false' mapping='logical' aggregate='true'>
<entity name='bc_llbalance'>
<attribute name='bc_units' alias='units_sum' aggregate='sum' />
<filter type='and'>
<condition attribute='bc_learninglicense' operator='eq' value='{0}' uiname=''
</filter>
</entity>
</fetch>", a.Id);
FetchExpression fetch = new FetchExpression(value_sum);
EntityCollection value_sum_result = service.RetrieveMultiple(fetch);
var TotalValue = "";
// decimal TotalValue = 0;
foreach (var c in value_sum_result.Entities)
{
TotalValue = ((string)((AliasedValue)c["value_sum"]).Value);
}
Entity llc = new Entity("bc_learninglicences");
llc.Id = a.Id;
llc.Attributes.Add("bc_unitsused", TotalValue);
service.Update(llc);
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
}
}
THE ERROR :
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Unexpected exception from plug-in (Execute): LearningLicenses.LearningLicenses: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Xrm.Client, Version=5.0.9690.2165, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.Detail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
<ErrorCode>-2147220956</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<Message>Unexpected exception from plug-in (Execute): LearningLicenses.LearningLicenses: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Xrm.Client, Version=5.0.9690.2165, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.</Message>
<Timestamp>2013-01-22T10:09:22.0275105Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText>
[LearningLicenses: LearningLicenses.LearningLicenses]
[c1b35170-c563-e211-8c6d-b499bafd5e5b: LearningLicenses.LearningLicenses: Create of bc_llbalance]
</TraceText>
</OrganizationServiceFault>
當我刪除了ref時,我在使用CrmSvcUtil.exe生成的Xrm.cs中獲得了超過2000個錯誤...也許我生成了錯誤類型的代碼類? –
您生成的早期綁定上下文應該最終從Microsoft.Xrm.Sdk.Client.OrganizationServiceContext繼承。需要考慮的另一件事是您的發佈代碼似乎沒有使用任何早期綁定的實體類,因此您可以只刪除您生成的Xrm.cs類(如果其他位置不需要)。 –
好吧擺脫Xrm.cs工作良好謝謝:)我一直有一種印象,這總是必須被包括在內,其實很高興聽到它沒有。我現在仍然在實際的代碼中出現錯誤,但正如我所說的,它沒有完成,因爲我被Xrm.client問題阻擋了。謝謝你的幫助。有關邏輯和代碼的任何建議,以便我如何更有效地實現功能?再次感謝 –