我试图导入一个.NET程序集到德尔福创造“_TLB.pas”的文件,但是我收到一个错误:导入.NET程序集到德尔福失败
是什么原因造成这个错误?
.NET程序集是不是使用正确的程序集属性构建的?
XE4可以导入的.NET版本(4.6.1)有限制吗?
下面显示的.NET程序集是使用VS 2012在.NET 4.6.1上创建的。
用Delphi XE4,按照下列步骤:
- 组件 - >导入组件 - >导入类型库
- 点击
- 浏览 '添加' 到.NET程序集。
选择装配体时,发生错误。
构建.NET程序集后,我成功地将它放入GAC(gacutil),将其注册到程序集(regasm)中,然后将其作为组件添加到COM +应用程序中。
我已经尝试创建.tlb
与regasm
并导入,但同样的错误发生。
ObjectCache.cs:
using System;
using System.EnterpriseServices;
using System.Runtime.InteropServices;
namespace TestObjectCache
{
[Guid("7B1FEFFD-1569-404F-B7EB-6AAB903B8779")]
[ComVisible(true)]
public interface IObjectCache
{
Boolean GetTrue();
}
[Guid("80C986C4-6B1F-4E3C-9B5E-13943DD1E1FD")]
[ComVisible(true)]
[ProgId("ProgId.ObjectCache")]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class ObjectCache:ServicedComponent, IObjectCache
{
public ObjectCache()
{
}
public Boolean GetTrue()
{
return true;
}
}
}
的AssemblyInfo.cs:
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationName("Object Cache")]
[assembly: Description("Caches commonly used objects")]
[assembly: ApplicationAccessControl(false)]
我不能肯定地说,但对此的“直觉”感觉是.NET命名空间'EnterpriseServices'阻止Delphi能够导入其类型库。如果未使用“EnterpriseServices”,则仍然使用InteropServices,然后可以将类型库导入到Delphi中。可能是由于Windows API无法通过“EnterpriseServices”获得。如果我有时间来验证这一点,我会更新这篇文章。 – ogglethorp
我刚刚使用InteropServices而不是EnterpriseServices来推进。 – ogglethorp