简体   繁体   English

无法访问Microsoft.Xrm命名空间

[英]Can't access Microsoft.Xrm namespace

I've downloaded CRM Dynamics SDK and keep it in a local directory. 我已经下载了CRM Dynamics SDK并将其保存在本地目录中。 In my code, I'm using EntityCollection (amongst other classes related to Xrm namespace), which means that I need to add using Microsoft.Xrm.Sdk; 在我的代码中,我正在使用EntityCollection (在与Xrm名称空间相关的其他类中),这意味着我需要using Microsoft.Xrm.Sdk;添加using Microsoft.Xrm.Sdk; .

The problem is that during compilation I get errors saying that: 问题是在编译期间我得到错误说:

The type or namespace name 'Xrm' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) 命名空间“Microsoft”中不存在类型或命名空间名称“Xrm”(您是否缺少程序集引用?)

So, I double check that the reference is made and, very accurately, I see that microsoft.xrm.sdk indeed is in my list. 所以,我仔细检查参考已经作出,非常准确,我看到microsoft.xrm.sdk的确我的列表中。 Just to be sure, I've removed it and added it again by pointing to the DLL with the same name. 只是为了确定,我已经删除它并通过指向具有相同名称的DLL再次添加它。 To no avail, though... The flabbergasting thing is that my colleague uses the same code and it compiles on his machine (the only difference being that he's on Win 7 and I'm on Win 8). 但无济于事......令人讨厌的事情是,我的同事使用相同的代码并在机器上编译(唯一的区别是他在Win 7上,我在Win 8上)。

How do we kill this problem? 我们如何解决这个问题?

Double check in your project settings to see which Target Framework you are using. 仔细检查项目设置以查看您正在使用的Target Framework。 If it is .NET Framework 4 Client Profile try changing it to .NET Framework 4 . 如果是.NET Framework 4 Client Profile,请尝试将其更改为.NET Framework 4

I received this when replacing my crm 2013 dlls with the new 2015 ones. 我用新的2015款dt替换我的crm 2013 dlls时收到了这个。

None of the above solutions worked for me. 上述解决方案均不适合我。 But what eventually led me on the right track was this warning (it was listed as a warning below the namespace errors): 但最终导致我走上正轨的是这个警告(它被列为命名空间错误下面的警告):

The primary reference "Microsoft.Xrm.Client, Version=5.0.9689.2166, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" could not be resolved because it was built against the ".NETFramework,Version=v4.5.2" framework. 无法解析主要参考“Microsoft.Xrm.Client,Version = 5.0.9689.2166,Culture = neutral,PublicKeyToken = 31bf3856ad364e35,processorArchitecture = MSIL”,因为它是针对“.NETFramework,Version = v4.5.2”框架构建的。 This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5.1" 这是比当前目标框架“.NETFramework,Version = v4.5.1”更高的版本

And when I checked I only had .Net 4.5.1 installed so after installing .Net 4.5.2 Developper pack and switching the target framework of my projects to this everything worked again. 当我检查时,我只安装了.Net 4.5.1,因此在安装.Net 4.5.2开发并将我的项目的目标框架切换到这一切后,一切都工作了。

The regular 4.5.2 update is not enough to get this version of .net in VS, you need the developper pack 常规的4.5.2更新不足以在VS中获得此版本的.net,您需要开发者包

Source: http://www.syntaxwarriors.com/2015/using-crm-2015-sdk-gives-error-that-xrm-does-not-exist-in-the-namespace/ 资料来源: http//www.syntaxwarriors.com/2015/using-crm-2015-sdk-gives-error-that-xrm-does-not-exist-in-the-namespace/

I had my framework already set to .NET Framework 4 therefore solution of switching between 4 Client profile and regular 4 did not apply. 我的框架已经设置为.NET Framework 4,因此在4 Client Client和regular 4之间切换的解决方案不适用。 A trick I did was changing .NET Framework into 3.5 and then back to 4.0 . 我做的一个技巧是将.NET Framework更改为3.5,然后再更改为4.0 I hope this will help some people. 我希望这能帮助一些人。

Thx @Jason Lattimer. Thx @Jason Lattimer。 Your answer gave me a clue how to solve my problem. 你的答案给了我一个如何解决我的问题的线索。

Good luck CRM developers! 祝CRM开发者好运!

This may not match this specific problem, but I'll add this as something to check for others in case Google directs them here like it did for me. 这可能与此特定问题不符,但我会将此添加为检查其他人的情况,以防Google将其指向此处,就像它对我一样。

In my case, I was getting a lot of errors like, "error CS0234: The type or namespace name 'Client' does not exist in the namespace 'Microsoft.Xrm'". 就我而言,我遇到了很多错误,例如“错误CS0234:名称空间'Microsoft.Xrm'中不存在类型或命名空间名称'Client'”。

Adding the "Microsoft.CrmSdk.Extensions" NuGet package fixed my compilation issues. 添加“Microsoft.CrmSdk.Extensions”NuGet包修复了我的编译问题。

After changing to .NET Framework 4 and changing .NET Framework into 3.5 and then back to 4.0, my poject was still not working. 在更改为.NET Framework 4并将.NET Framework更改为3.5然后再更改为4.0之后,我的项目仍然无效。

It didn't work when I selected the option given by the "add Reference" window. 当我选择“添加引用”窗口给出的选项时,它不起作用。

What worked for me was to click on the browse button in the "add Reference" window and look for the Microsoft.Xrm.Sdk. 对我有用的是单击“添加引用”窗口中的浏览按钮,然后查找Microsoft.Xrm.Sdk。 dll file DLL文件

I had .NET 4.0 as my target framework and I had this compiler error. 我有.NET 4.0作为我的目标框架,我有这个编译错误。 I tried changing it back to 3.5 and then back to 4.0 and that didn't fix it. 我尝试将其更改回3.5然后再回到4.0并且没有修复它。

What did fix the problem for me was deleting the bin, obj and tools folders in my project directory. 为我解决问题的是删除项目目录中的bin,obj和tools文件夹。 I don't understand the details of why this worked, but it worked for me. 我不明白为什么这样有效的细节,但它对我有用。

I had this error and in my case, after trying all the above solutions and others on the web with no success, finally I came to a solution. 我有这个错误,在我的情况下,在尝试了所有上述解决方案和其他网络上没有成功之后,我终于找到了解决方案。

The problem was in the version of CRM SDK that I was using: 2015 (don´t wanna know why!). 问题出在我使用的CRM SDK版本:2015年(不想知道为什么!)。

Downloaded CRM 2013 SDK version, changed the assembly references to that version and the problem was gone. 下载的CRM 2013 SDK版本,更改了该版本的程序集引用,问题就消失了。

Reason for it is CRM 2015 SDK was built on .Net 4.5.2 Framework and the Visual studio does not support 4.5.2. 原因是CRM 2015 SDK建立在.Net 4.5.2 Framework上,Visual Studio不支持4.5.2。

Just download .Net Framework 4.5.2 Goto Project Properties and change the framework. 只需下载.Net Framework 4.5.2转到项目属性并更改框架。

I was having the same issue with my CRM 2011 Plugin. 我的CRM 2011插件遇到了同样的问题。 In my case none of the above solution worked. 就我而言,上述解决方案均无效。

In my code I am using early bound class. 在我的代码中,我使用早期绑定类。 When generating this class file i was using following line along with other settings which was causing the error. 生成此类文件时,我使用了以下行以及导致错误的其他设置。

/codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration"

Once I added this new class file without codeCustomization, it removed all errors. 一旦我添加了这个没有codeCustomization的新类文件,它就删除了所有错误。

As mentioned before, 正如先前所说,

Reason for it is CRM 2015 SDK was built on .Net 4.5.2 Framework and the Visual studio does not support 4.5.2. 原因是CRM 2015 SDK建立在.Net 4.5.2 Framework上,Visual Studio不支持4.5.2。

Just download .Net Framework 4.5.2 Goto Project Properties and change the framework. 只需下载.Net Framework 4.5.2转到项目属性并更改框架。

Alternate way could be to replace Microsoft.Xrm.Sdk.dll with file from older CRM SDK. 替代方法可能是用旧CRM SDK中的文件替换Microsoft.Xrm.Sdk.dll。 I use VS2010, and CRM 2011 SDK file solved all compiler errors. 我使用VS2010,CRM 2011 SDK文件解决了所有编译器错误。

PS Switching project to .NET 3.5 and back to 4.0 did not helped PS切换项目到.NET 3.5并回到4.0没有帮助

更新NuGet包帮助我解决了这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM