IronPython 호출을 래퍼로 사용하여 IronPython을 사용하여 Excel-DNA 추가 기능을 개발하는 중입니다. Excel-DNA 개발자의 풍부한 도움을 받아 샘플을 만들고 실행하는 초기 kinks을 통해 작업했지만 지금은 SharpDevelop에서 addin을 디버깅하려고합니다. 몇 가지 문제가 있습니다. 필자는이 새로운 기능에 완전히 익숙하지 않기 때문에 SharpDevelop, .NET, Excel-DNA 또는 IronPython과 관련된 문제인지는 잘 모르겠습니다.IronPython Excel-Dna 추가 기능 - Microsoft.Dynamic 관련 예외
하나의 솔루션으로 두 개의 프로젝트를 만들었습니다. 하나는 C# 클래스 라이브러리입니다. 다른 하나는 파이썬 클래스 라이브러리입니다. 내가 블로그에서 찾은 tutorial 다음에 디버깅 할 프로젝트를 설정했다. 나는이 진행하므로, C# 코드의 처음 몇 줄을 단계별로 할 수 있어요,하지만 난 다음 줄에 도착하면 :
"로드 할 수 없습니다 :
pyEngine.Runtime.LoadAssembly(myclass);
나는 예외가 에서 파일 또는 어셈블리 'Microsoft.Dynamic, 버전 = 1.0.0.0, 문화 = 중립, PublicKeyToken = 31bf3856ad364e35'또는 해당 종속성 중 하나. 찾아낸 어셈블리의 매니페스트 정의가 가 어셈블리 참조와 일치하지 않습니다. (예외HRESULT : 0x80131040) "
그러나 저는 Microsoft.Dynamic 참조를 프로젝트에 추가 한 것으로 확신합니다. 버전 1.1.0.20입니다. 이것은 IronPython 배포판에 포함되어 있지만 내 컴퓨터의 다른 위치에도 포함되어 있습니다. 두 가지 모두에 대한 참조 설정을 시도했지만 둘 다 동일한 버전 번호를 가지며 동일한 파일 크기 인 것으로 보입니다. 어느 쪽도 작동하지 않습니다. 버전 1.0.0.0이 필요한가요? 아니면 다른 일을하고 있습니까? pyEngine (Python.CreateEngine()에 의해 반환 된 ScriptEngine)이 배포판에 포함 된 것과 다른 버전을로드하려고 시도하는 이유는 무엇인지 이해가되지 않습니다.
코드는 다음과 같습니다. 다른 정보가 필요한 경우 알려주십시오.
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 귀하의 IronPython의 물건은 아마도 .NET 4 런타임에서 실행하는 데 필요한
class MyClass:
def __init__(self):
pass
def AddSomeStuff(self,x,y):
return x + y