2014-05-25 46 views
0

我有得到相關的實體從CRM的一個問題。異常而檢索相關實體

以下代碼:

var conn = CrmConnection.Parse("my connection string"); 
var orgService = new OrganizationService(conn); 
var context = new MyServiceContext(orgService); 

... 
var myEntity = context.CreateQuery<new_myentity>().First(p => p.new_name == "some name"); 
myEntity.GetRelatedEntities(context, "relation name").ToList(); 

引發以下異常在HTE最後一行:

值 'Microsoft.Xrm.Client.Configuration.CrmConfigurationProvider,Microsoft.Xrm.Client' 是未被識別爲有效的類型或不是類型的「Microsoft.Xrm.Client.Configuration.CrmConfigurationProvider」。

+0

聽起來像是你缺少一個參考。 http://dotnetinside.com/en/type/Microsoft.Xrm.Client/CrmConfigurationManager/6.0.0.0 –

+0

我有參考Microsoft.Xrm.Client.dll – filip

+0

我敢肯定,我們遇到了類似的錯誤,唯一的解決方案是安裝所引用的DLL到GAC(本機[s]的運行SSIS包上)。 – mwardm

回答

0

試試這個......我無法測試,因爲我沒有在這臺機器上的早期綁定類DLL,但我認爲這可能會訣竅。請告訴我。

CrmConnection connection = CrmConnection.Parse("my connection string"); 
  
var proxy = new Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy(
connection.ServiceUri, 
connection.HomeRealmUri, 
connection.ClientCredentials, 
connection.DeviceCredentials); 
  
proxy.EnableProxyTypes(); 

IOrganizationService service = (IOrganizationService)proxy; 
var context = new CrmOrganizationServiceContext(service); 

var myEntity = context.CreateQuery<Entity>().First(p => p.new_name == "some name"); 
myEntity.GetRelatedEntities(context, "relation name").ToList(); 
+0

nope,同樣的問題。也許我應該提到如果這有什麼區別,我在SSIS包腳本任務中運行這個 – filip

0

當使用CRM SDK從SSIS自定義組件中獲取相關實體時,我遇到了同樣的問題。

說,從一個控制檯應用程序,如果你不爲microsoft.xrm.client裝配在VS設置「複製本地」爲True引用的程序集的屬性也可以得到這個錯誤。

對於SSIS,要解決該錯誤,您需要將microsoft.xrm.client程序集複製到: {DriveLetter}:\ Program Files \ Microsoft SQL Server \ 110 \ DTS \ Binn目錄(或{DriveLetter}: \ Program Files(x86)\ Microsoft SQL Server \ 110 \ DTS \ Binn(如果適用))。