title: How do I call a .NET Core 6.0 DLL in Delphi?
body: <h1>Initial situation</h1>
  <p>I made use of the <strong>C</strong>omponent <strong>O</strong>bject <strong>M</strong>odel (COM) in the .NET Framework before in order to use my C# class library in Delphi as shown in this <a href="https://www.youtube.com/watch?v=ZutlhThQJ5s" rel="nofollow noreferrer">YouTube tutorial</a>, which worked surprisingly well. However, I now want to use .NET Core 6 instead.</p>
  <p>Following the official tutorial from Microsoft <a href="https://docs.microsoft.com/en-us/dotnet/core/native-interop/expose-components-to-com" rel="nofollow noreferrer">&quot;Expose .NET Core components to COM&quot;</a>, I created this interface</p>
  <pre class="lang-cs prettyprint-override"><code>using System.Runtime.InteropServices;
  
  [ComVisible(true)]
  [Guid(6775d93d-cf14-42b9-83db-425bac0acf4d)]
  [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  public interface IServer
  {
      public string getHelloWorld();
  }
  </code></pre>
  <p>and this class.</p>
  <pre class="lang-cs prettyprint-override"><code>using System.Runtime.InteropServices;
  
  [ComVisible(true)]
  [Guid(d62bf794-d29e-4fcd-8637-994490264a93)]
  public class Server : IServer
  {
      public string getHelloWorld()
      {
          return &quot;Hello World&quot;;
      }
  }
  </code></pre>
  <p>After building the project, I executed this command to register all of my exposed .NET objects with COM.</p>
  <pre><code>regsvr32 MyProjectName.comhost.dll
  </code></pre>
  <p>The command executed successfully. I now tried to import the created <code>.dll</code> file in Delphi, like I did before with the class libraries written in .NET Framework (See <a href="https://youtu.be/ZutlhThQJ5s?t=196" rel="nofollow noreferrer">timestamp of YouTube tutorial</a>). However, Delphi runs into an error because it can't load the type library.</p>
  <hr />
  <h1>Edit 1: Godzilla-type breaking change</h1>
  <p>According to the <a href="https://docs.microsoft.com/en-us/dotnet/core/native-interop/expose-components-to-com#embedding-type-libraries-in-the-com-host" rel="nofollow noreferrer">official documentation</a>...</p>
  <blockquote>
  <p>Unlike in .NET Framework, there is no support in .NET Core or .NET 5+ for generating a COM Type Library (TLB) from a .NET assembly. The guidance is to either manually write an IDL file or a C/C++ header for the native declarations of the COM interfaces. If you decide to write an IDL file, you can compile it with the Visual C++ SDK's MIDL compiler to produce a TLB.</p>
  </blockquote>
  <p>... there is no support in .NET Core for generating a typelib.</p>
  <hr />
  <h1>Edit 2: MIDL compiler</h1>
  <p>However, there is still a way to  manually produce a TBL file by using the MIDL compiler. As you can read up in the <a href="https://docs.microsoft.com/en-us/windows/win32/com/midl-compiler" rel="nofollow noreferrer">official documentation</a>, the MIDL compiler processes an IDL file to generate a type library. With that beeing said, I created this IDL file by using <a href="https://docs.microsoft.com/en-us/previous-versions/windows/desktop/automat/creating-a-type-library" rel="nofollow noreferrer">this guide</a>.</p>
  <pre><code>[
      uuid(a93d03e0-9adf-4a2d-93e3-0ccfc2d8e1a6),
      lcid(0x0409),
      version(1.0),
  ]
  library MyProjectName
  {
      importlib(&quot;stdole.tlb&quot;); 
      [
          uuid(16292ce5-ccd1-405d-9a70-ace42152bb15),
          oleautomation,
          dual
      ]
      interface IServer: IUnknown {
          HRESULT getHelloWorld([out, string] IServer** string);
      };
  };
  </code></pre>
  <p>However, I get an error when I execute the following command to generate the <code>.tlb</code> file.</p>
  <pre><code>midl myProjectName.idl /tlb myProjectName.tlb
  
  &gt; midl : command line error MIDL1005 : cannot find C preprocessor cl.exe
  </code></pre>
  <p><strong>Issue:</strong> I searched for <code>cl.exe</code> on my Computer but couldn't find anything.</p>
  <p><strong>Q.:</strong> Does anybody have an idea on how I could solve my problem? I highly appreciate any kind of help, cheers!</p>