dSPACE.Runtime.InteropServices
0.7.2
Prefix Reserved
See the version list below for details.
dotnet add package dSPACE.Runtime.InteropServices --version 0.7.2
NuGet\Install-Package dSPACE.Runtime.InteropServices -Version 0.7.2
<PackageReference Include="dSPACE.Runtime.InteropServices" Version="0.7.2" />
paket add dSPACE.Runtime.InteropServices --version 0.7.2
#r "nuget: dSPACE.Runtime.InteropServices, 0.7.2"
// Install dSPACE.Runtime.InteropServices as a Cake Addin #addin nuget:?package=dSPACE.Runtime.InteropServices&version=0.7.2 // Install dSPACE.Runtime.InteropServices as a Cake Tool #tool nuget:?package=dSPACE.Runtime.InteropServices&version=0.7.2
dSPACE COM tools
dscom is a replacement for tlbexp.exe
and TypeLibConverter.ConvertAssemblyToTypeLib
.
The tool consists of a library and a command line tool. The library can be used in net6.0
or in net48
projects.
Fortunately, .NET still supports COM, but there is no support for generating TLBs.
From the Microsoft documentation:
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.
https://docs.microsoft.com/en-us/dotnet/core/native-interop/expose-components-to-com
One main goal is to make dscom
behave like tlbexp.exe
.
Happy IUnknowing and IDispatching 😉
Command Line Client
The command-line interface (CLI) tool dscom
is a replacement for tlbexp.exe
and OleView
(View TypeLib).
It supports the following features:
- Convert an assembly to a type library
- Convert a type library to
YAML
file - Register a type library
- Unregister a type library
Installation
The installation is quite simple. You can use dotnet tool
to install the dscom
binary.
c:\> dotnet tool install --global dscom
Here you can find all available versions:
https://www.nuget.org/packages/dscom/
Usage
c:\> dscom --help
Description:
dSPACE COM tools
Usage:
dscom [command] [options]
Options:
--version Show version information
-?, -h, --help Show help and usage information
Commands:
tlbexport <Assembly> Export the assembly to the specified type library
tlbdump <TypeLibrary> Dump a type library
tlbregister <TypeLibrary> Register a type library
tlbunregister <TypeLibrary> Unregister a type library
dSPACE.Runtime.InteropServices library
If you miss the TypeLibConverter
class and the ConvertAssemblyToTypeLib
method in .NET
, then the dSPACE.Runtime.InteropServices
might help you.
This method should behave compatible to the .NET Framework
method.
public object? ConvertAssemblyToTypeLib(
Assembly assembly,
string tlbFilePath,
ITypeLibExporterNotifySink? notifySink)
https://www.nuget.org/packages/dSPACE.Runtime.InteropServices/
Example:
using dSPACE.Runtime.InteropServices;
// The assembly to convert
var assembly = typeof(Program).Assembly;
// Convert to assembly
var typeLibConverter = new TypeLibConverter();
var callback = new TypeLibConverterCallback();
var result = typeLibConverter.ConvertAssemblyToTypeLib(assembly, "MyTypeLib.tlb", callback);
// Get the name of the type library
var typeLib2 = result as System.Runtime.InteropServices.ComTypes.ITypeLib2;
if (typeLib2 != null)
{
typeLib2.GetDocumentation(-1, out string name, out _, out _, out _);
Console.WriteLine($"TypeLib name: {name}");
}
// The callback to load additional type libraries, if necessary
public class TypeLibConverterCallback : ITypeLibExporterNotifySink
{
public void ReportEvent(ExporterEventKind eventKind, int eventCode, string eventMsg)
{
Console.WriteLine($"{eventCode}: {eventMsg}");
}
public object? ResolveRef(System.Reflection.Assembly assembly)
{
// Returns additional type libraries
return null;
}
}
Migration notes (mscorelib vs System.Private.CoreLib)
Both assemblies are ComVisible=false but lot of .NET Framework types are ComVisible=true.
But this is not the case for .NET (.NET Core and .NET >= 5).
Unlike mscorelib (the good old .NET Framework), no tlb is shipped for .NET.
As example the System.Exception
class:
In case of mscorelib the System.Exception
class is ComVisible=true:
[Serializable]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(_Exception))]
[ComVisible(true)]
public class Exception : ISerializable, _Exception
In case of System.Private.CoreLib
(.NET Core and .NET >=5), the Exception
class is ComVisible=false
[Serializable]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public class Exception : ISerializable
{
The _Exception
class interface (default interface in this case) is not available in .NET (.NET Core and .NET >=5).
Why can I load a .NET Framework library into a .NET application?
The magic is in TypeForwardedFromAttribute
.
If you try to load an .NET Framework assembly inside a .NET (.NET Core and .NET >=5) application, the runtime will forward the original type to
a type defined in the System.Private.CoreLib
assembly.
classextern forwarder System.Exception
{
.assemblyextern System.Private.CoreLib
}
Therefore you should make sure that you do not use any types from the mscorelib
typelib in your .NET project if you are using .NET Framework assemblies!
Limitations
- No imports of the
mscorelib
typelib (are types are VT_UNKNOWN)- _Object not supported
- _EventArgs not supported
- _Delegate not supported
- _Type not supported
- ISerializable not supported
- ICloneable not supported
- IDisposable not supported
- ...
TypeLibExporterFlags
is not supportedITypeLibExporterNotifySink
is not COM visibleTypeLibConverter
is not COM visibleAutoDual
is not supported- LCID only NEUTRAL is supported
- No GAC support
- IEnumerator is converted to
IEnumVARIANT
(stdole) - Guid is converted to
GUID
(stdole) - Color is converted to
OLE_COLOR
(stdole) - No support for
UnmanagedType.CustomMarshaler
- No support for .NET Framework assemblies with
AssemblyMetadataAttribute
value ".NETFrameworkAssembly"
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Framework | net48 is compatible. net481 was computed. |
-
.NETFramework 4.8
- No dependencies.
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on dSPACE.Runtime.InteropServices:
Repository | Stars |
---|---|
dahall/Vanara
A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers.
|
Version | Downloads | Last updated |
---|---|---|
1.11.1 | 88 | 10/29/2024 |
1.11.0 | 88 | 10/3/2024 |
1.10.1 | 158 | 7/1/2024 |
1.10.0 | 490 | 4/30/2024 |
1.9.0 | 103 | 4/19/2024 |
1.8.0 | 146 | 4/15/2024 |
1.7.4 | 438 | 3/4/2024 |
1.7.3 | 199 | 1/9/2024 |
1.7.2 | 130 | 1/8/2024 |
1.7.1 | 187 | 12/12/2023 |
1.7.0 | 150 | 12/1/2023 |
1.6.0 | 262 | 11/20/2023 |
1.5.0 | 110 | 11/16/2023 |
1.4.0 | 119 | 11/15/2023 |
1.3.0 | 173 | 10/16/2023 |
1.2.0 | 314 | 9/18/2023 |
1.1.3 | 254 | 8/31/2023 |
1.1.2 | 174 | 8/10/2023 |
1.1.1 | 344 | 7/16/2023 |
1.1.0 | 169 | 6/20/2023 |
0.23.5 | 177 | 6/12/2023 |
0.23.4 | 177 | 5/8/2023 |
0.23.3 | 261 | 3/22/2023 |
0.23.1 | 293 | 3/17/2023 |
0.23.0 | 249 | 3/10/2023 |
0.22.1 | 279 | 2/24/2023 |
0.22.0 | 323 | 2/20/2023 |
0.21.0 | 339 | 2/16/2023 |
0.20.0 | 393 | 2/7/2023 |
0.19.1 | 413 | 1/19/2023 |
0.19.0 | 366 | 1/18/2023 |
0.18.3 | 403 | 1/5/2023 |
0.18.2 | 397 | 12/19/2022 |
0.18.1 | 407 | 12/19/2022 |
0.18.0 | 454 | 12/15/2022 |
0.17.0 | 430 | 11/29/2022 |
0.16.3 | 325 | 11/9/2022 |
0.16.2 | 334 | 11/3/2022 |
0.16.1 | 406 | 10/24/2022 |
0.16.0 | 441 | 9/20/2022 |
0.15.1 | 430 | 9/6/2022 |
0.15.0 | 453 | 7/29/2022 |
0.14.0 | 386 | 7/28/2022 |
0.13.0 | 446 | 7/18/2022 |
0.12.0 | 435 | 7/18/2022 |
0.11.0 | 459 | 7/18/2022 |
0.10.0 | 459 | 5/11/2022 |
0.9.0 | 462 | 4/5/2022 |
0.8.1 | 453 | 3/15/2022 |
0.8.0 | 467 | 3/15/2022 |
0.7.2 | 442 | 3/13/2022 |
0.7.1 | 447 | 3/13/2022 |
0.7.0 | 432 | 3/11/2022 |
0.6.0 | 455 | 3/10/2022 |
0.5.0 | 451 | 3/8/2022 |
0.4.0 | 457 | 3/7/2022 |
0.3.1 | 442 | 3/6/2022 |
0.3.0 | 421 | 3/4/2022 |
0.2.0 | 447 | 3/4/2022 |
0.1.0 | 486 | 3/3/2022 |