Can't access Microsoft.Xrm namespace

2019-04-04 02:08发布

I've downloaded CRM Dynamics SDK and keep it in a local directory. 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;.

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?)

So, I double check that the reference is made and, very accurately, I see that microsoft.xrm.sdk indeed is in my list. Just to be sure, I've removed it and added it again by pointing to the DLL with the same name. 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).

How do we kill this problem?

11条回答
戒情不戒烟
2楼-- · 2019-04-04 02:49

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.

Just download .Net Framework 4.5.2 Goto Project Properties and change the framework.

Alternate way could be to replace Microsoft.Xrm.Sdk.dll with file from older CRM SDK. I use VS2010, and CRM 2011 SDK file solved all compiler errors.

P.S. Switching project to .NET 3.5 and back to 4.0 did not helped

查看更多
老娘就宠你
3楼-- · 2019-04-04 02:53

Double check in your project settings to see which Target Framework you are using. If it is .NET Framework 4 Client Profile try changing it to .NET Framework 4.

查看更多
等我变得足够好
4楼-- · 2019-04-04 02:55

I was having the same issue with my CRM 2011 Plugin. 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.

查看更多
不美不萌又怎样
5楼-- · 2019-04-04 02:56

I had my framework already set to .NET Framework 4 therefore solution of switching between 4 Client profile and regular 4 did not apply. A trick I did was changing .NET Framework into 3.5 and then back to 4.0. I hope this will help some people.

Thx @Jason Lattimer. Your answer gave me a clue how to solve my problem.

Good luck CRM developers!

查看更多
你好瞎i
6楼-- · 2019-04-04 02:58

I had .NET 4.0 as my target framework and I had this compiler error. I tried changing it back to 3.5 and then back to 4.0 and that didn't fix it.

What did fix the problem for me was deleting the bin, obj and tools folders in my project directory. I don't understand the details of why this worked, but it worked for me.

查看更多
登录 后发表回答