Use Microsoft Solver Foundation in C# - c#

I'm trying to use Microsoft Solver Foundation in my C# application in VS2010 Ultimate. I've installed MSF (64 bit version) and as far as I understand I should be able to use the services after declaring:
using Microsoft.SolverFoundation;
However, I get the error "The type or namespace name 'SolverFoundation' does not exist in the namespace 'Microsoft'".
I see that there's Microsoft.Solver.Foundation.dll located in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0
Initially I thought the 64 bit version might be the problem so I uninstalled and switched to the 32 bit version. But no success either.
How can I integrate MSF into my C# application?

I'm trying to use Microsoft Solver Foundation in my C# application in VS2010 Ultimate. I've installed MSF (64 bit version) and as far as I understand I should be able to use the services after declaring:
using Microsoft.SolverFoundation;
How can I integrate MSF into my C# application?
At no point did you mention that you added a reference to this library to your project, and the behavior you are describing is consistent with not having added a reference. Therefore, you also need to add a reference to this library to your project.

I've already tried adding the references before but it wouldn't work. Now I've noticed something in the warnings (which I probably didn't see before):
"The referenced assembly "Microsoft.Solver.Foundation, Version=3.0.1.10599, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project."
I fixed this by setting Application Properties -> Application -> Target Framework from ".Net Framework 4 Client Profile" to ".Net Framework 4".

Does "Microsoft Solver Foundation" show up when you go to Add Reference...?
If it does not perhaps you are not using the correct framework, try Project -> Properties.. -> Compile -> Advanced Compile Options... and certify you are NOT using .NET 4 Framework Client Profile (uses to be default for new projects). If it is, change it to .NET 4 Framework.
If that also fails... have you downloaded and installed the solver?

You need to add a reference to that DLL you found to your project.

Related

In Linux , The reference assemblies for framework ".NETFramework,Version=v4.5" were not found

I have made a setup of Visual studio to compile C# code in my Ubuntu Machine .
I loaded the workspace/my code to VS and I could see the below error.
The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
Please help me on resolving this issue as am a beginner in Visual studio.
Thanks
If project is heavy, you can follow
this procedure
If your project is lightweight, create a new .netcore project using VS and move your code (and dependencies references)into that new project. then let VS telling you potential errors and correct them.
Looking at the procedure, you can firstly retargeting your actual project in dotnet 4.6.2 framework in order to "ensures that you can use API alternatives for .NET Framework-specific targets in the cases where .NET Core can't support a particular API."
I would recommend running the portability tool in Visual Studio 2017 if you have it. This will give you an idea if you will have a hard time moving it over.
As for your error with the csproj, that's because that file has paths within it, which are pointing to locations using windows paths, instead of Linux paths.

C# "System" version update

I'm in C# in Visual Studio running 2015 Update 3.
I'm using a dll that I made myself for the backend of a system, and in the references of the project, one shows the "System" as Version 2.0.5 and the project being used as a dll shows it as 4.0.0. I believe this is the cause of a conflict that is preventing me from running this app. How do I update just the system version or even specify it so I can make them the same?
I think you should go to the references of your project containing the old reference, remove System and add it with version 4.0.0.0. However, you should also check that target .NET framework versions match (maybe the older dll is obtained compiling against .NET framework 2.0 and the newest one against .NET framework 4.0).
In order to find out the cause that is preventing you from running the application (you should provide what is happening), an useful tool is Assembly Binding Log Viewer which will show the exact assemblies that the application is trying to load (fully qualified assembly names).

Could not load file or assembly - Framework .NET 3.5

I'm facing a compatibility issue for .NET project.
I have 2 projects:
1st project: Libary project. Target: windows Phone 7.0 OS version
project
2nd project: Console Appplication project. Refers/use the previous
library. Target: Framework .NET 3.5
When I try to run the 2nd project, I have an exception that happens when I call a function from the 1st library:
...Could not load file or assembly 'System, Version=2.0.5.0,
Culture=neutral, PublicKeyToken=7xxxxxxxx or one of its dependencies.
The system cannot find the file specified...
If I change the target for 2nd project to Framework .NET 4.0, it works well, no more crash.
Is my error really due to the different target versions ?
How can I make the 1st project to be compatible with framework 3.5 ?
As I said, 1st project was targeting framework 3.5 .NET and 2nd project was targeting Windows Phone 7.0.
Work around: change 2nd project to target framework 3.5 .NET. (in my case, I add to create a new project in my solution, which in fact was the same as the old one but targeting framework 3.5 .NET. Same sources used.)
Kindly rough but works.
I had excactly same issue. Installing Portable Class Library helped me.
https://msdn.microsoft.com/en-us/library/gg597391.aspx
There are links to downloads for different visual studio versions.

Can't access Microsoft.Xrm namespace

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

Back port .NET 4 to 3.5 SP1 in VS2010

I wrote a simple VS2010 WPF application which targeted .NET Framework 4 Client Profile. (In fact, my app does not use any .NET 4 features, but VS2010 just by default started my project targeting .NET 4 so I didn't bother to check it)
I found all XP system and even a few Window 7 of various languages failed to start the app. I decided to back port my app to target .NET Framework 3.5 or .NET Framework 3.5 Client Profile, by changing the Target Framework in solution's properties. But the app does not compile or build with the following error on System.Xaml and Microsoft.CSharp:
Warning 1 Could not resolve assembly System.Xaml. The target framework required by this assembly (4.0) is higher than the project target framework. If this reference is required by your code, you may get compilation errors. test1
Warning 2 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". test1
Warning 3 The referenced component 'Microsoft.CSharp' could not be found.
Warning 4 The referenced component 'System.Xaml' could not be found.
Is it possible to back port (or back target) a VS2010 app to .NET 3.5? If so, how?
[EDIT]
I found there was one Control - DataGrid - that is designed to use for .NET 4. I have to install WPF Tool Kit to back port the controls to 3.5. Hope someone find this helpful.
Just remove them. Tested it and works for me. I believe those assemblies were only introduced in .NET 4. The types in System.Xaml, for example, are defined some place else in .NET 3.5 (like PresentationCore for example). See this article for more info.
Remove these references altogether. If you still need them, re-add them through the UI in Visual Studio. You should see the 3.5 versions or 2.0 versions of those assemblies. By using those older versions, your app should compile.
You have to remove those references at the references folder and readd them with the 3.5 version.

Categories

Resources