问题
I've created a batch job that running in 32bit mode as it using 32bit COM objectes, this need to connect to SharePoint to make updates to list. It works in my development environment as it is full 32bit. But in my test and prodution environment we use 64bit SharePoint and this is what I get from SPSite:
System.IO.FileNotFoundException:
The Web application at http://<my sp host>/ could not be found.
Verify that you have typed the URL correctly.
If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.
at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri req...
this is what I do
using (SPSite site = new SPSite(_url))
{
using (SPWeb web = site.OpenWeb())
{
try
{
SPList list = web.Lists[new Guid(_listID)];
SPListItem item = list.GetItemById(id);
item[field] = value;
item.SystemUpdate(false);
}
catch (Exception x)
{
log.Error(x);
}
}
}
回答1:
You simply need to run your batch job in a 64-bit process. The problem is that SharePoint has many COM objects under the hood which are compiled for 64-bit in your test and production environment. The SPSite and SPWeb objects actually wrap the COM objects which is why they fail in your 32-bit process.
One work-around could be to interact with SharePoint through its Web Services instead of the object model.
回答2:
I don't think this is a 32/64bit issue as I am in the same situation as far as developing on 32bit and deploying to 64bit. (Actually, we are running a 32bit and 64bit WFE'S)
Since the exception is being thrown from the SPSite constructor, I would investigate further, as to whether the machine you are running you code on (the SP box) actually recognizes that URL.
来源:https://stackoverflow.com/questions/250335/using-spsite-from-32bit-application-to-access-64bit-sharepoint