IronPython çağrıları için bir C# ile bazı C# ile IronPython kullanarak bir Excel-DNA eklentisi geliştirmeye başladım. Excel-DNA geliştiricisinin cömert yardımı ile, bir örnek alma ve çalıştırmanın ilk kinks'undan bazılarıyla çalıştım, ancak şimdi SharpDevelop'taki eklenti hatalarını ayıklamaya çalışıyorum ve bazı sorunlara rastlıyorum. Bunun çoğu için tamamen yeni olduğumdan, SharpDevelop, .NET, Excel-DNA veya IronPython ile ilgili bir sorun olup olmadığından emin değilim.IronPython Excel-Dna Eklentisi - Microsoft.Dynamics referansıyla ilgili istisna
Tek bir çözümde iki proje oluşturdum, biri bir C# sınıfı kitaplığı. Diğeri ise bir python sınıf kütüphanesidir. Bir blogda bulduğum bir tutorial takip ederek hata ayıklama projesini kurdum. O ilerleme yani, C# kodunun ilk birkaç satır adım adım mümkün, ama ben şu hattına olsun:
"yüklenemedi:
pyEngine.Runtime.LoadAssembly(myclass);
istisna almak dosya veya montaj 'Microsoft.Dynamic, Sürüm = 1.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35' veya bağımlılıklarından biri. bulunduğu derlemenin bildirim tanımı derleme başvurusuyla eşleşmiyor. (İstisnaHRESULT: 0x80131040) "
Ancak, projeme Microsoft.Dynamics başvurusunu eklediğime eminim. Bu 1.1.0.20 sürümüdür. Bu, IronPython dağıtımında, ancak bilgisayarımdaki başka bir konumda da bulunur. Referansı her ikisine de ayarlamayı denedim, ancak her ikisinin de aynı sürüm numarası var ve aynı dosya boyutunda görünüyorlar. Hiçbiri işe yaramaz. Sürüm 1.0.0.0'a mı ihtiyacım var yoksa başka bir şey mi yapıyorum? Neden pEngine (Python.CreateEngine() tarafından döndürülen ScriptEngine), dağıtıma dahil olandan farklı bir sürümü yüklemeye çalışacaklarını anlamıyorum.
Kod aşağıda verilmiştir. Başka bilgiye ihtiyacınız olursa haberim olsun.
MyAddin.cs
/*
Added these references all as Local Copies - probably not necessary?
System.Windows.Forms
Microsoft.CSharp
ExcelDna.Integration (from Excel-DNA distribution folder)
IronPython (from IronPython folder)
IronPython.Modules (from IronPython folder)
Microsoft.Dynamic (from IronPython folder)
Microsoft.Scripting (from IronPython folder)
Microsoft.Scripting.Metadata (from IronPython folder)
mscorlib (I don't really know why I added this, but it was one of the references in my IronPython class library)
MyClass (this is the reference to my IronPython class - I checked to see that it gets copied in every time I rebuild the solution and it does)
These were automatically added by SharpDevelop when I created the project.
System
System.Core
System.Windows.Forms
System.Xml
System.Xml.Linq
*/
using System;
using System.IO;
using System.Windows.Forms;
using ExcelDna.Integration;
using System.Reflection;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
public class MyAddIn : IExcelAddIn
{
public void AutoOpen()
{
try
{
string xllDirectory = Path.GetDirectoryName(@"C:/Users/myname/Documents/SharpDevelop Projects/IronPythonExcelDNATest/MyAddIn/bin/Debug/");
string dllPath = Path.Combine(xllDirectory,"MyClass.dll");
Assembly myclass = Assembly.LoadFile(dllPath);
ScriptEngine pyEngine = Python.CreateEngine();
pyEngine.Runtime.LoadAssembly(myclass);
ScriptScope pyScope = pyEngine.Runtime.ImportModule("MyClass");
object myClass = pyEngine.Operations.Invoke(pyScope.GetVariable("MyClass"));
IronTest.AddSomeStuff = pyEngine.Operations.GetMember<Func<double, double,double>>(myClass, "AddSomeStuff");
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
public void AutoClose()
{
}
}
public class IronTest
{
public static Func<double, double, double> AddSomeStuff;
public static double TestIPAdd(double val1, double val2)
{
try
{
return AddSomeStuff(val1, val2);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
return double.NaN;
}
}
}
MyClass.py Kişisel IronPython şeyler muhtemelen .NET 4 çalışma zamanı altında çalıştırmak gerekiyor
class MyClass:
def __init__(self):
pass
def AddSomeStuff(self,x,y):
return x + y