I register COM object from .Net 6 DLL using following script .\regsvr32.exe .\MyLibrary.comhost.dll
In addition, in the DLL, it registers itself in ROT via [DllImport("oleaut32.dll")] internal extern static int RegisterActiveObject([MarshalAs(UnmanagedType.IUnknown)] object punk, ref Guid rclsid, uint dwFlags, ref int pdwRegister);
After I can get this object using Marshal.GetActiveObject("MyLibrary.MyClassName"), I can get the object, but
System.Runtime.InteropServices.COMException: 'Typelib export: Type library is not registered. (Exception from HRESULT: 0x80131165)' exception is thrown when I try to call a method from this object. Could you help to resolve the issue, please?
Registration and retrieving COM object from .Net 6 DLL (Typelib export: Type library is not registered. (Exception from HRESULT: 0x80131165))
224 Views Asked by Serhii At
1
There are 1 best solutions below
Related Questions in C#
- Passing arguments to main in C using Eclipse
- kernel module does not print packet info
- error C2016 (C requires that a struct or union has at least one member) and structs typedefs
- Drawing with ncurses, sockets and fork
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- Configured TTL for A record(s) backing CNAME records
- Allocating memory for pointers inside structures in functions
- Finding articulation point of undirected graph by DFS
- C first fgets() is being skipped while the second runs
- C std library don't appear to be linked in object file
- gcc static library compilation
- How to do a case-insensitive string comparison?
- C programming: Create and write 2D array of files as function
- How to read a file then store to array and then print?
- Function timeouts in C and thread
Related Questions in .NET
- file download method in visual studio 2017
- Repository manager receives the wrong connection string in .net core
- MongoDb not connecting C#
- The current .NET SDK does not support targeting .NET Core 6.0. Brand new WPF Project VS Community 2022 17.9.5
- Why Scanning GSI on DynamoDb doesnt work as fast as expected when using CONTAINS?
- Are "blittable types" really unmanaged types for StructLayout Sequential
- Failed to fetch dynamically imported module on Blazor JS Interop
- Problem to upload several images per one request
- Implementing Azure AD B2C Authentication in .NET 8 Blazor Project (RenderMode: InteractiveAuto)
- Stripe connect payout - throws exceptions
- 'IOException: The cloud file provider is not running', when trying to delete 'cloud' folder
- Azure Application Insights Not Displaying Custom Logs for Azure Functions with .NET 8
- Convert C# DateTime.Ticks to Bigquery DateTime Format
- Socket.io nodejs server .NET connection
- Producer Batching Service Bus Vs Kafka
Related Questions in VISUAL-STUDIO
- The current .NET SDK does not support targeting .NET Core 6.0. Brand new WPF Project VS Community 2022 17.9.5
- Dotnet Run is not working but the application is running in Visual Studio
- Is there a way to support Tailwind @apply in Visual Studio?
- How can I eliminate compile warnings using ZLib in Visual Studio
- C++(or Visual Studio) saving the file will not preserve the original file contents
- VS Community 2022 cannot install dotnet-ef when i try to publish
- Visual Studio 2022 convert spaces to tabs on checkout and back to spaces on checkin
- What should I do if Visual Studio has a restriction on creating files with a long name or a long path to these files?
- Command line error D8036 - not allowed with multiple source files with node-gyp and VS2022
- Migrate Old VS 2015 .suo file to the New VS 2022 DocumentLayout.json
- How to make one executable visual studio, that users can run?
- Use tabs instead of spaces in .csproj file in Visual Studio 2022
- Unity - scrollview/dragging breaks after specific scene inactivity
- How to make Visual Studio 2022 project launch Windows Terminal instead of PowerShell?
- Why is 'EDITBIN /STACK:2097152 w3wp.exe' cmd is giving me an LNK1342 error?
Related Questions in COM
- How to program a COM object with an IEnumerator, IEnumerable interface inside
- WinAPI - right mouse drag & drop and IContextMenu
- Function Returning Excel COM Objects Unexpectedly
- Windows ContextMenuHandler names - Document conflict?
- How to publish a console application with COM interop and trim unused code
- IContextMenu Handler - Should ShellExecute or CreateProcess be used to InvokeCommand?
- Windows Explorer Conditional Context Menu Item for Drive?
- How do I fix an error while trying to send email using Outlook with COM?
- ITypeLib2.GetLibStatistics() always throws AccessViolationException in C#
- Directwrite is not always able to query font
- How can I pass a C++ struct to a C# DLL method using COM interop
- VBA PowerPoint Run-time error '-2147467259' (80004005): Presentation.Close: Failed
- PHP using a dll with COM + dotnet
- d3d11 triangle rendering failure despite everything being properly initialized
- COM context menu InvokeCommand not being called
Related Questions in TYPELIB
- ITypeLib2.GetLibStatistics() always throws AccessViolationException in C#
- Registration and retrieving COM object from .Net 6 DLL (Typelib export: Type library is not registered. (Exception from HRESULT: 0x80131165))
- Unable to register a 3rd party type library for use in Delphi
- ITypeInfo and fast searching for function signature
- Move Typelib into a C# custom action code
- Register a COM library without copying exe file to the installation directory and execute custom action before registering it
- How to make a typedef struct in ODL OLE compatible?
- How does a COM client parses Type Library from a EXE COM server?
- Visual Studio 2022 generates invalid syntax from typelib
- Windows Script Host cannot reference type library with version number in hexadecimal notation
- How do I create WIALib_TLB.dcu in Delphi?
- How to digitally sign .tlb(type library) files?
- Replacement for TypeLibFunc in .NET Standard
- WIX Candle.exe CNDL0047 : The TypeLib element is non-advertised and therefore requires a parent File element
- VBA EXCEL VBA How to enable (check) specific Type Library in Tools/References programmatically?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
What happens is Microsoft has removed support for ITypeInfo from the COM Callable wrapper implementation in .NET Core (all versions), the object which also implements IDispatch. This is briefly discussed here https://github.com/dotnet/runtime/issues/86751 and in fact mentioned in documentation:
Contrary to what the github discussion seems to imply, this is a big breaking change that causes lots of trouble, which is difficult to diagnose, and has no easy solution.
The
ITypeInforeference is retrieved by thedynamiccode using IDispatch::GetTypeInfo when you try to call any member by a name (such asmyadd) on your object:Now, to add to the problem, your calling code is .NET Framework, and the
dynamicimplementation is different between the two:.NET Framework (throws even if type info count = 0):
This is what ultimately causes the
System.Runtime.InteropServices.COMException: 'Typelib export: Type library is not registered. (Exception from HRESULT: 0x80131165)'error.NET Core (more recent, less stupid):
There are multiple solutions:
IDispatch based: If you want to continue using
dynamic, you can either use a .NET Core client or use the "old" reflection way, like this (doesn't usesITypeInfo, goes directly toIDispatchGetIDsOfNamesandInvoke):IUnknown based: Since you have defined a dual
ICalculatorinterface (IDispatch+IUnknown-derived), you can use it instead of using a late-bound (IDispatch) approach.For that, the system must know the details of that interface to be able to marshal it across threads/processes/machines, ie: it needs a .TLB (also make sure you stick to already known data types or you'll need a proxy / stub .dll which is out of .NET reach). So you must 1) export a
.TLB(a Type Library file, you can also embed it in a .dll or a .exe) from the .NET Code and 2) register it, using for example dscom, an unofficial tool which does work fine with this sample code (Microsoft has also removed the .TLB generation and registration facility that existed inregasmfor .NET Framework). Make sure you build everything in x64 and use dscom for x64 too (not x86), something like this:and then change your calling .NET Framework code like this:
PS: There's another solution more complex which is to expose a wrapper on the object, on the .NET Core host side, instead of the object itself, that would reimplement
IDispatchw/o reporting any error when .NET Framework callsIDispatch::GetTypeInfoand internally calls the object'sIDispatchimplementation