The C# class library project I created contains some some simple code below:
namespace IPY_PublishDLL
{
public class FormPublisher
{
public static void publish(string path)
{
SPFarm localFarm = SPFarm.Local;
if (localFarm == null)
{
Console.WriteLine("localFarm is null");
return;
}
Console.WriteLine("localFarm is not null");
}
}
}After successfully compiling the class library project, I tried to call the publish method in anothe console project and the code is also quite simple:
using IPY_PublishDLL;
static void Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("arguments error!");
Console.Write("Press Enter to Continue");
Console.ReadLine();
return;
}
FormPublisher.publish(args[0]);
}The console application runs well with the outcoming "localFarm is not null"
However, what I need to do is invoking the dll in a ironpython project.
Here is the ironpython code:
import clr
clr.AddReferenceToFile("IPY_PublishDLL.dll")
from IPY_PublishDLL import FormPublisher
path = "C:\\Users\\Administrator\\Desktop\\ipyForm.xsn"
FormPublisher.publish(path)I ran it with ipy64.exe and what I got is "localFarm is null"
It confused me a lot.
I have set the Platform target to x64
below is the list of my environment:
windows server 2008 r2
sharepoint 2010,
ironpython,
.net framework 3.5.1