ogglethorp
ogglethorp

Reputation: 21

Importing .NET assembly into Delphi fails

I am trying to import a .NET assembly into Delphi to create a "_TLB.pas" file, but I am receiving an error:

Screen shot of error

What is causing this error?

Is the .NET assembly not being built with the correct assembly attributes?

Is there a limitation on the .NET version (4.6.1) that XE4 can import?

The .NET assembly shown below was created with VS 2012 on .NET 4.6.1.

Using Delphi XE4, following these steps:

When selecting the assembly, the error occurs.

After building the .NET assembly, I am successfully able to put it in the GAC (gacutil), register it in the assembly (regasm), and add it as a component in a COM+ application.

I have tried creating the .tlb with regasm and importing that, but the same error occurs.

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)]

Upvotes: 0

Views: 1226

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 595402

Run the Assembly through Visual Studio's Tlbexp.exe tool to generate a .tlb file, and then import that file into Delphi.

Otherwise, try using the importer's "Import .NET Assembly" option instead of the "Import a Type Library" option.

Upvotes: 1

Related Questions