Thanks for the response. I am trying to setup the addin so I can
debug in SharpDevelop. I have created two projects in one solution,
one is a C# class library. The other is my python class library from
before. I apologize if this is just a noob .NET/C# issue and not
related to Excel-DNA at all, so feel free to tell me if it isn't
related, and I'll try to ask on stackoverflow.
MyAddIn.cs:
/*
Added these references all as Local Copies - probably not necessary?
1.System.Windows.Forms
2.Microsoft.CSharp
3.ExcelDna.Integration (from Excel-DNA distribution folder)
4.IronPython (from IronPython folder)
5.IronPython.Modules (from IronPython folder)
6.Microsoft.Dynamic (from IronPython folder)
7.Microsoft.Scripting (from IronPython folder)
8.Microsoft.Scripting.Metadata (from IronPython folder)
9.mscorlib (I don't really know why I added this, but it was one of
the references in my IronPython class library)
10.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.
11.System
12.System.Core
13.System.Windows.Forms
14.System.Xml
15.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
{
//I've added the MyClass.dll reference to this
project so it does exist in the //Debug folder of this
project
string xllDirectory = Path.GetDirectoryName(@"C:\Users
\jeff.holman\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;
}
}
}
And here is my python project, MyClass.py:
class MyClass:
def __init__(self):
pass
def AddSomeStuff(self,x,y):
return x + y
I actually setup the project to debug following the instructions here:
http://www.blog.methodsinexcel.co.uk/2010/10/15/debugging-a-dna-solution/
I am able to step through the first few lines of C# code, so that is
progress! When I get to the following line:
pyEngine.Runtime.LoadAssembly(myclass);
I get an exception:
"Could not load file or assembly 'Microsoft.Dynamic, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)"
But I have added the Microsoft.Dynamic reference to my project. It is
version 1.1.0.20. This is included in the IronPython distribution but
also in another location on my computer. I have tried setting the
reference to both, but they both have the same version number and
appear to be the same file size. Neither one works. Do I need
version 1.0.0.0 or am I doing something else wrong?
"Could not load file or assembly 'Microsoft.Dynamic, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)"
> > > > > I then...
>
> read more »