Click here to Skip to main content
15,881,281 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: Text Editor color setting Pin
trønderen29-Dec-21 1:51
trønderen29-Dec-21 1:51 
PraiseRe: Text Editor color setting Pin
Oscar K.29-Dec-21 23:21
Oscar K.29-Dec-21 23:21 
QuestionAny learning materials specifically on porting WPF to MAUI? Pin
greatoceansoftware26-Nov-21 6:02
greatoceansoftware26-Nov-21 6:02 
AnswerRe: Any learning materials specifically on porting WPF to MAUI? Pin
Gerry Schmitz26-Nov-21 8:08
mveGerry Schmitz26-Nov-21 8:08 
GeneralRe: Any learning materials specifically on porting WPF to MAUI? Pin
greatoceansoftware26-Nov-21 9:07
greatoceansoftware26-Nov-21 9:07 
QuestionNew to ASP.NET. Which one should I start with? Pin
Master PC 24-Nov-21 14:56
Master PC 24-Nov-21 14:56 
AnswerRe: New to ASP.NET. Which one should I start with? Pin
Richard Deeming24-Nov-21 21:29
mveRichard Deeming24-Nov-21 21:29 
QuestionCreating a COM component in .NET 5 Pin
Gaston Verelst19-Nov-21 3:53
Gaston Verelst19-Nov-21 3:53 
Hi,

I'm trying to create a simple COM component in .NET 5. I have gotten this far:
  • I have created an interface with the right attributes:
    C#
    [ComVisible(true)]
    [Guid("12345678-3e60-4c56-abcd-13d4098434f7")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IConvertor
    {
        string ConvertPatient(string s);
    }
  • I have created a class that implements this interface:
    C#
    [ComVisible(true)]
    //[ClassInterface(ClassInterfaceType.None)]
    public class Convertor : IConvertor
    {
        public Convertor()
        { }
    
        public string ConvertPatient(string s)
        {
            return "Hello, " + s;
        }
    }
I tried with and without the ClassInterface and Guid attributes.
  • In the .csproj file I added these:
    XML
    <Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>net5.0</TargetFramework>
        <!-- Indicate the assembly is providing a COM server -->
        <EnableComHosting>true</EnableComHosting>
        <EnableRegFreeCom>true</EnableRegFreeCom>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
      <PlatformTarget>x86</PlatformTarget>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Hl7.Fhir.R4" Version="3.6.0" />
    </ItemGroup>
    </Project>
I compiled for x86 and I got these files (and some more):
xxx.comhost.dll
xxx.dll

The problem is that I don't manage to register this component.
tlbexp xxx.InterOp.dll gives me this error:
Quote:
TlbExp : error TX0000 : Type library exporter encountered an error while processing 'hdmpcloud.ehealth.FhirTools.InterOp.Convertor, hdmpcloud.ehealth.FhirTools.InterOp'. Error: Type library exporter cannot load type 'hdmpcloud.ehealth.FhirTools.InterOp.Convertor' (error: Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. (Exception from HRESULT: 0x80070002)).


regasm /tlb xxx.InterOp.comhost.dll gives me
Quote:
RegAsm : error RA0000 : Failed to load 'C:_projects\HDMP\hdmpcloud.ehealth.FhirTools\InterOp\hdmpcloud.ehealth.FhirTools.InterOp\bin\Debug\net5.0\hdmpcloud.ehealth.FhirTools.InterOp.comhost.dll' because it is not a valid .NET assembly


I want to call this component from a Delphi program (unmanaged code).

The documentation ( Interoperating with unmanaged code - .NET Framework | Microsoft Docs ) is not very clear on a couple of things:
  • Is COM still possible in .NET 5?
  • The documentation is for .NET in general, but they don't specify a version.
Any help or pointers in the right direction would be much appreciated. And before you ask... yes, this will become an article Smile | :)

Gaston
Check out my blog at http://msdev.pro/

AnswerRe: Creating a COM component in .NET 5 Pin
Gerry Schmitz19-Nov-21 7:54
mveGerry Schmitz19-Nov-21 7:54 
GeneralRe: Creating a COM component in .NET 5 Pin
Gaston Verelst19-Nov-21 20:29
Gaston Verelst19-Nov-21 20:29 
GeneralRe: Creating a COM component in .NET 5 Pin
Gerry Schmitz20-Nov-21 8:18
mveGerry Schmitz20-Nov-21 8:18 
GeneralRe: Creating a COM component in .NET 5 Pin
Gaston Verelst22-Nov-21 1:38
Gaston Verelst22-Nov-21 1:38 
GeneralRe: Creating a COM component in .NET 5 Pin
Gerry Schmitz22-Nov-21 4:58
mveGerry Schmitz22-Nov-21 4:58 
PraiseRe: Creating a COM component in .NET 5 Pin
Gaston Verelst22-Nov-21 5:34
Gaston Verelst22-Nov-21 5:34 
GeneralRe: Creating a COM component in .NET 5 Pin
Gerry Schmitz22-Nov-21 5:42
mveGerry Schmitz22-Nov-21 5:42 
GeneralRe: Creating a COM component in .NET 5 Pin
Gaston Verelst22-Nov-21 19:57
Gaston Verelst22-Nov-21 19:57 
GeneralRe: Creating a COM component in .NET 5 Pin
Gaston Verelst26-Nov-21 1:18
Gaston Verelst26-Nov-21 1:18 
GeneralRe: Creating a COM component in .NET 5 Pin
Gerry Schmitz30-Nov-21 10:12
mveGerry Schmitz30-Nov-21 10:12 
GeneralRe: Creating a COM component in .NET 5 Pin
Gaston Verelst30-Nov-21 19:33
Gaston Verelst30-Nov-21 19:33 
Suggestionany resources for learning porpuses Pin
lv1115-Nov-21 18:21
lv1115-Nov-21 18:21 
GeneralRe: any resources for learning porpuses Pin
Richard MacCutchan15-Nov-21 20:57
mveRichard MacCutchan15-Nov-21 20:57 
JokeRe: any resources for learning porpuses Pin
Richard Deeming16-Nov-21 22:41
mveRichard Deeming16-Nov-21 22:41 
GeneralRe: any resources for learning porpuses Pin
lv1118-Nov-21 14:27
lv1118-Nov-21 14:27 
GeneralRe: any resources for learning porpuses Pin
lv1118-Nov-21 17:12
lv1118-Nov-21 17:12 
GeneralRe: any resources for learning porpuses Pin
Eddy Vluggen20-Nov-21 14:01
professionalEddy Vluggen20-Nov-21 14:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.