开发者

F# Script SharePoint 2010 API doesn't work

开发者 https://www.devze.com 2023-04-09 13:00 出处:网络
I am trying something really simple in F# to try and test interaction with the SharePoint 2010 API.I think I am running into a general problem with F#.Is there anyway that an F# script can access the

I am trying something really simple in F# to try and test interaction with the SharePoint 2010 API. I think I am running into a general problem with F#. Is there anyway that an F# script can access the SharePoint 2010 API?

I think my problem is due to the F# scripts running 32bit, and the SharePoint API is in 64bit.

An example of the code I'm trying to run is as follows:

#r "C:\Program Files\Common Files\Microsoft Shared\We开发者_运维知识库b Server Extensions\14\ISAPI\Microsoft.sharepoint.dll"
#r "System.ServiceModel.dll"

open System
open Microsoft.SharePoint

let GetListByUrl (listUrl:string) =
    use site = new SPSite(listUrl)
    use web = site.OpenWeb()
    let list = 
        if not (web = null) then web.GetList(listUrl)
    list

In the visual studio editor it says the following error: The Type System.ServiceModel.ChannelFactory`1 is required here and is unavailable. You must add a reference to assembly ...

When the script is ran it gives the message: System.IO.FileNotFoundException: The Web application at... could not be found. Verify that you have typed the URL correctly...

Which is the error message I get if I try to access the SharePoint 2010 API from a 32bit c# console program. If I change the c# console program to Any CPU that message doesn't appear.

However I'm trying to do this in an F# script which I guess is 32bit, so how would I work around that?

Also since this is probably a general problem with F# scripts and 64bit dlls, how would you work around the problem of needing to reference 64bit dlls in F# scripts?

Edit I used corflags.exe in the visual studio cmd prompt to modify the fsi.exe to 64bit. I followed this guide: http://ig2600.blogspot.com/2010/05/making-fsharp-interpreter-fsi-run-in.html. That seemed to work, though the F# interactive window seemed slower. However when I ran the code above in the now 64bit fsi it said sharepoint does not work with .net 4.0. How would you run the F# interactive window in .net 3.5?

Edit Because of the answer posted by F.Aquino in which he said I needed to add a reference to System.ServiceModel I have updated the code to add that.

That fixes the visual studio editor complaints that keep appearing with red squiggly lines everywhere. When the script is ran the results are the same, the script cannot access the sharepoint 2010 API which is the problem I am having.


You need to add a reference to System.ServiceModel

0

精彩评论

暂无评论...
验证码 换一张
取 消