Can't access Microsoft.Xrm namespace - c#

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?

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.

I received this when replacing my crm 2013 dlls with the new 2015 ones.
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. This is a higher
version than the currently targeted framework
".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.
The regular 4.5.2 update is not enough to get this version of .net in VS, you need the developper pack
Source: 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. 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!

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.
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'".
Adding the "Microsoft.CrmSdk.Extensions" NuGet package fixed my compilation issues.

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.
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.dll file

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.

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!).
Downloaded CRM 2013 SDK version, changed the assembly references to that version and the problem was gone.

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.

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.

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

Updating NuGet Package helped me to solve the problem

Related

Cannot change Target Framework on Several Projects From v4.0 to V4.5 or 4.5.1

I have several projects in a large solution that won't convert to V4.5.1 (or even V4.5). Most did, but obviously I need to get all of them converted. The GUI in Visual Studio says that it did it and reloads the project, but if you go back into the properties it still says V4 and it won't compile because of dependencies that converted properly and are V4.5.1
I tried manually updating the .csproj files and it says 4.5.1 as the target framework, and I even updated the app.config/web.config to point to the right version, however Visual Studio's property page still says .NET 4 and is throwing compile errors because it can't access the ones that successfully updated to 4.5.1
What am I missing in the process to get these updated? I've tried VS.net 2012 and 2013 and both do the same thing.
In hopes that this helps others:
In our case, the issue was that we were referencing a custom targets file that was created for the entire solution. even though the project was getting updated, the custom targets file was overriding it thus preventing the project from getting updated.
Updated the targets file to point to .net 4.5 and everything was fine.
For me, the solution was to remove all the extraneous <PropertyGroup> sections from the .csproject file - except the first one.
VS 2015 was setting the <TargetFramework> to 4.5.1 on only one of them (not the first one).
After two days of suffering, I have created a new project, targeted .NET 4.5 and then manually copied all files from the existing project. Made sure new project compiles. Removed old project. Moved new project into the directory of the old project so that I can reverse merge into trunk. Job done.
Project I was upgrading was an old WPF project with thousands (no kidding) XAML files in a single project. It also had a release preview of MvvmLight (years old) and an older version of Prism along with a range of other libraries. All and all the project is a mess and somebody must have done something really stupid to make targeting .NET 4.5 this difficult.
I had a similar issue. Turns out the DLLs were built for target framework 4.5.1, but the project I was working in was built for 4.5 only. There were some suppressed warning messages when I compiled. When I showed compile warnings, that was the hint that told me what was going on.
I recompiled the DLLs for framework 4.5, and then the DLLs copied automatically without needing additional references to the assemblies.
In my case I was working with projects designed for SharePoint 2010. Apparently the project template restricts the .NET target framework version which can be selected.
As I was trying to compile a SharePoint 2016 server, once I got the beta templates downloaded for 2016, Visual Studio automatically prompted me to upgrade these projects when trying to open the solution again. Hope this helps someone.
Preview bits for SharePoint 2016 are available here: https://www.microsoft.com/en-us/download/details.aspx?id=49972

Targeted my project in Visual 2010 to .Net 4.0 but the system still looks for the dll 'System.Core version 2.0.5.0'

My project targets .Net 4.0 Client profile but it crashes as soon as it starts by displaying a file load exception stating that System.Core version= 2.0.5.0 . How can I change that?
Edit: Forgot to add, it's a WPF project.
This is mainly for future me, who will at some point come back to this question, and none of the current answers will solve your problem (hey future me!)
My issue was a nuget package referencing System.Core 2.0.5.0 so I had no control over the reference.
To get System.Core 2.0.5.0 installed on the machine, which already had .NET 4.0 installed and patched, I installed the Portable Class Library.
To install the Portable Class Library tools on a build machine without installing Visual Studio 2012, download the Portable Library Tools, and save the download file (PortableLibraryTools.exe) on your computer. Run the installation program from a Command Prompt window, and include the /buildmachine switch on the command line.
I had a problem similar to this that only occurred on windows XP/Server 2003 while Windows 7/Server 2008 and later worked fine. After a long time of looking I ran into this article:
http://code.google.com/p/autofac/wiki/FrequentlyAskedQuestions
It suggested downloading the following hotfix
http://support.microsoft.com/kb/2468871
After installing that everything worked fine! Maybe give that a try and see if it helps.
Probably you included reference to some libraries belonging to .Net 2.0 and they depends on System.Core 2.0. So you need to check every reference's version number included in your project.
Make sure that System.Core in References targets version 4. Also, make sure Specific Version is false. You could also try to remove the reference to System.Core and then add it again.
Open the references section in solution explorer, delete the System.Core
Right click on the References and add a new one, locate System.Core v4.0 and add that one.
I was able to fix a similar error by installing Framework 4.0 UPDATE kb2468871
Direct link: http://www.microsoft.com/en-us/download/details.aspx?id=3556
Info Link: http://support.microsoft.com/kb/2468871

Visual Studio loses reference when attempting to build

I started using Thrift about a week ago. I got the latest source from SVN and built the C# library (Thrift.dll). I used the library to prototype a TCP client/server with the data types that my team will be using. This worked with no problem, I just followed the example code in the SVN repo.
Yesterday, I wanted to run the same test but over HTTP instead. I searched around online some and found out that from the time I got the code last week until yesterday patch "THRIFT-322" https://issues.apache.org/jira/browse/THRIFT-322
Was applied to the trunk. So I updated my thrift source from SVN and saw the new THttpHandler class. I rebuilt the Thrift.dll so I can use the THttpHandler class but now whenever I reference the new dll Visual Studio 2010 gives me an error at compile time: "The type or namespace "Thrift" could not be found (are you missing a using directive or an assembly reference?)". When I replace the reference with the old Thrift.dll that I have I do not get this error.
I can't figure out what I'm doing wrong, I just recompiled the Thrift.dll from the SVN source and I can no longer link to the Thrift.dll. When I first add the reference it seems like it's going to work fine. Visual Studio gives me the correct intellisense, etc. Once I try to build it's like there is no longer a reference to the Thrift.dll. Any ideas?
I also submitted this to the Thrift Users Mailing List, I just thought maybe this was more general and someone here may be able to help.
Thanks,
-Sean
Since you mentioned using VS 2010... I have seen this error/behavior sometimes when I am compiling a .NET 4.0 project and my target framework for the project is set to ".NET Framework 4.0 Client Profile" instead of ".NET Framework 4.0". So you might want to check that and see if it helps.
I had a similar problem I had to switch from '.NET Framework 4.0 Client Profile' to '.NET Framework 4.0' and it worked because a referenced dll is compiled using the '.NET Framework 4.0'
One Suggestion I have is to check for a file with 'refresh' in the extension E.g. Thrift.dll.refresh or something similar. This file is usually added on adding a refernce. Try removing this file, replace the dll and try builtign and running again.

The primary reference "Microsoft.CSharp", which is a framework assembly, could not be resolved in the currently targeted framework

I started a new winforms project, fairly simple, has a few labels, text boxes, and a button. All code is running fine. I forgot to change the framework version from 4 (using VS 2010) to 3.5 before I created the app and when I changed it to 3.5 or 3.5 client profile I get the following warning:
The primary reference "Microsoft.CSharp", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v3.5". To resolve this problem, either remove the reference "Microsoft.CSharp" or retarget your application to a framework version which contains "Microsoft.CSharp".
It's not a huge amount of trouble to recreate this with a 3.5 setting from the start and I'm fairly sure I'm not using anything from the 4 framework that I need.
In most/all project templates in VS 2010 for .NET 4, the Microsoft.CSharp assembly reference is added. So when you created the project you were given this assembly reference automatically. You shouldn't have any problems just removing the reference.
I just wish to add my experience too. In my case, removing the Microsoft.CSharp reference was enough just to take the warnings away and compile the solution, however while using the console I got some errors still referring to the missing frameworks reference.
I then created an empty new console project; by default the ".NET FrameWork 4 Client Profile" was set, so I immediately replaced it with the ".NET Framework 3.5 Client Profile" option and saved. Then I copy&paste all my code from the original project and add all the references I used in the project. Then I renamed the solution, namespace, assembly name, etc, like my original project and compiled it. No warnings/errors and everything was OK.
I then tried to use the console application (on an environment with just the .NET 3.5) and everything worked flawless ^_^ (instead, just changing the .NET reference from 4 to 3.5 in the project proprieties, I got the errors I said above).
Hope this may help those having problems while just changing the "targeted framework" and removing the Microsoft.CSharp reference in an existing project.

Can't find System.Workflow assembly in .NET. How do I get it?

I've installed a complete SharePoint Server (MOSS) 2007 on my dev box + the latest Visual Studio (SP1) + the latest full Windows SDK. According to the Windows Workflow Foundation page http://msdn.microsoft.com/en-us/netframework/dd980558.aspx, that is all I should need to do to be able program against the .NET Workflow APIs.
And yet, all of the projects I build from the standard Workflow templates refer to the assembly System.Workflow and VS complains that that assembly isn't available. I've searched around on my hard drive, and I can't find a file for that assembly anywhere obvious on my disk.
I do find some files that look like they might be that assembly, but they're buried down in wacky places below particular applications like they are runtime support for that app. They don't seem to be what I'm supposed to point VS at.
Can anyone tell me how to fix this problem? Do I need to install something else that I have yet to come across? Are these assemblies already on my system and I just need to know how to point VS at them? I'm stumped.
BTW: I was going to try uninstalling and reinstalling VS, but the installer fails with some very cryptic error message when I try to uninstall.
TIA for any help, and Happy Holidays to all!!!
I did a Repair using the .NET 3.5 SP1 SDK distributable, and I believe that this solved the problem. I thought at first that it didn't (as I say in prior comments) because I was looking for the files to show up in the v3.5 assembly directory. The missing files actually go in the v3.0 assembly directory. I later brought up one of the sample projects in VC and noticed that the symbols were now resolving, and sure enough, the missing .dll files were now present.
So I guess that the .NET SDK installer that ships with VS somehow didn't install these .dll files. It took doing a Repair on the SDK to fix the problem.
I'm a happy camper now!
In addition to change the target framework to 4.0, you also need to:
Add a reference to System.Workflow.Runtime
Add a reference to System.Workflow.ComponentModel
There's no assembly named System.Workflow in .NET 3.x: the WF assemblies (in 3.x) are:
System.Workflow.Runtime
System.Workflow.ComponentModel
System.Workflow.Activities
System.WorkflowServices (3.5)
You should be able to find all these assemblies in the GAC, and reference them via the Add Reference dialog, .NET tab.
It's possible System.Workflow is a (badly named) SharePoint-specific DLL, in which case, sorry, the above won't help... try the SharePoint install directory or SharePoint SDK install directory. Are the project templates you're using SharePoint templates, or the ones from File > New Project > Visual C# > Workflow?
I have a same problem, and solved it. The reason is your project's target .net framework not include this assembly (it's maybe .net 3.5 client profile or 4.0 client profile). The solution is very simple: set the target framework of your project to .NET Framework 3.5 or 4.0.
It work for me.
Please find it in C:/Windows/Assembly/GAC_MSIL
All the DLLs are Present there..
Also If U donot Find it then do the Following
Right Click Project->Application->Target Framework-> .Net Framework 4.0
It should show Up then.

Categories

Resources