C#外部库(Lua)调用问题
我刚开始使用C#(VS2010).Net(4.0)编程,我遇到了自己无法解决的问题,因为已经有几天了 我在C#代码中使用了外部脚本语言(Lua) 为此,我使用为.NET4.0构建的LuaInterpreter 第一次尝试: 该项目是一个控制台应用程序->当我尝试调用Lua类时,该程序运行良好 第二次尝试: 该项目是一个从Excel->类库compile fine使用的类库Librrary COM,我的用户定义函数在Excel中运行良好。但是当我试图调用Lua类时,它崩溃了,说Lua程序集丢失了C#外部库(Lua)调用问题,c#,.net-4.0,lua,excel-2007,luainterface,C#,.net 4.0,Lua,Excel 2007,Luainterface,我刚开始使用C#(VS2010).Net(4.0)编程,我遇到了自己无法解决的问题,因为已经有几天了 我在C#代码中使用了外部脚本语言(Lua) 为此,我使用为.NET4.0构建的LuaInterpreter 第一次尝试: 该项目是一个控制台应用程序->当我尝试调用Lua类时,该程序运行良好 第二次尝试: 该项目是一个从Excel->类库compile fine使用的类库Librrary COM,我的用户定义函数在Excel中运行良好。但是当我试图调用Lua类时,它崩溃了,说Lua程序集丢失了
Could not load file or assembly 'lua51, Version=0.0.0.0, Culture=neutral, PublicKeyToken=1e1fb15b02227b8a' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
要重现问题,请执行以下操作:
1-您需要从获取LuaInterface.Net 4.0
2-在项目中添加LuaInterface作为参考
3-复制建筑物目录中的Lua51 DLL(我也将Excel表放在那里)
4-复制类库的代码
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using Excel = Microsoft.Office.Interop.Excel;
using LuaInterface;
namespace POC
{
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class Functions
{
public int test()
{
Lua lua = new Lua();
return 0;
}
#region Class in Excel
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type type)
{
Registry.ClassesRoot.CreateSubKey(
GetSubKeyName(type, "Programmable"));
RegistryKey key = Registry.ClassesRoot.OpenSubKey(
GetSubKeyName(type, "InprocServer32"), true);
key.SetValue("",
System.Environment.SystemDirectory + @"\mscoree.dll",
RegistryValueKind.String);
}
[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type type)
{
Registry.ClassesRoot.DeleteSubKey(
GetSubKeyName(type, "Programmable"), false);
}
private static string GetSubKeyName(Type type,
string subKeyName)
{
System.Text.StringBuilder s =
new System.Text.StringBuilder();
s.Append(@"CLSID\{");
s.Append(type.GUID.ToString().ToUpper());
s.Append(@"}\");
s.Append(subKeyName);
return s.ToString();
}
#endregion
}
}
崩溃的函数是从Excel调用时的测试函数
我愿意接受任何帮助
谢谢因为它似乎已经签署,请尝试将Lua51放入GAC,看看它是否有效。您甚至可以尝试将Lua15.dll放在excel.exe的同一路径中。在64位机器上运行.NET、LuaInterface和Lua5.1时,我遇到了很多问题。Lua5.1只编译32位,这需要(我相信)将LuaInterface项目构建为32位。尝试将.NET项目中的“项目->属性->构建->平台目标”更改为“x86” 谢谢你的建议。我无法将DLL放入GAC,因为gacutil未能说出“未知错误”。而将dll放入Excel.exe目录则可以正常工作。这证明Dll和程序运行良好,但这不是一个长期的解决方案。。。当我调用我的类时,你知道如何跟踪搜索dll的文件夹吗?要可视化:Excel->User DLL(我的程序集)->LuaInterface.DLL->Lua51.DLL需要在Excel目录中的是Lua51.DLL