SharePoint 2010 Managed Metadata compiled against .NET 4.0 Framework?
UPDATE: This was corrected in Visual Studio 2010 Release Candidate (which is not under NDA). I don’t see why changing Visual Studio would have any affect (but it does). The dll is the same, so is the target framework. Yet this issue isn’t pervasive across other SP DLLs. Oh well. It seems fixed. Expect a Managed Metatdata blog post soon.
I’m preparing for a Managed Metadata presentation. I began writing code in a Feature Receiver, but for the sake of simplicity of a demo, I started some basic code in a .NET Console Application. Note here: I’m using Visual Studio 2010 Beta 2 and SharePoint Server 2010 Beta 2 on this machine. This is only an issue with a .NET Console application.
To work with the Managed Metadata in .NET, a reference is needed to the Microsoft.SharePoint.Taxonomy.dll. When adding to my console project, I received this error.
So, I need the .NET 4.0 target framework. Odd. I thought SharePoint was compiled against the .NET 3.5 framework. So I click OK and proceed. I’ve added my reference and changed target to 4.0.
I enter in some code like this:
Now, when it build, all seems fine.
But when I step thru the code, all is not well.
Here is the error text:
System.PlatformNotSupportedException was unhandled
Message=Microsoft SharePoint is not supported with version 4.0.21006.1 of the Microsoft .Net Runtime.
at Microsoft.SharePoint.Administration.SPFarm.FindLocal(SPFarm& farm, Boolean& isJoined)
at Microsoft.SharePoint.SPSite..ctor(String requestUrl)
at MossDelight.Samples.ConsoleForSP.Program.Main(String args)
So I stop the debugger, change the target framework, and reload the project. When I build the project, I get this error:
Here is the error text:
The primary reference “Microsoft.SharePoint.Taxonomy, Version=188.8.131.52, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL” could not be resolved because it has an indirect dependency on the framework assembly “System.Web.DataVisualization, Version=184.108.40.206, Culture=neutral, PublicKeyToken=31bf3856ad364e35” which could not be resolved in the currently targeted framework. “.NETFramework,Version=v3.5”. To resolve this problem, either remove the reference “Microsoft.SharePoint.Taxonomy, Version=220.127.116.11, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL” or retarget your application to a framework version which contains “System.Web.DataVisualization, Version=18.104.22.168, Culture=neutral, PublicKeyToken=31bf3856ad364e35”.
Seems I’m a bit stuck. I am hoping this is just a Beta issue. The code works from within a Feature Receiver. I’ll update this when I try it on Visual Studio RC. I don’t have the SP RC yet.