Search code examples
c#visual-studiodllregeditregasm

Receiving an error while try to register DLL with RegAsm.exe: "Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral ,..."


I try to register DLL with RegAsm.exe but I receive this error:

RegAsm : warning RA0000 : Registering an unsigned assembly with /codebase can cause your assembly to interfere with other applications that may be installed on the same computer. The /codebase switch is intended to be used only with signed assemblies. Please give your assembly a strong name and re-register it.> RegAsm : error RA0000 : Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=...' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)

Lately I have upgraded my project to latest .net8. I have installed ASP.NET Core Runtime 8.0.1 and .NET Desktop Runtime 8.0.1.

I use in one of my files the library "System.Runtime.InteropServices". I can see under dependency frameworks the "System.Runtime" library under the framework "Microsoft.NETCore.App". The dll exists in the directory "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.1\ref\net8.0\System.Runtime.dll"

I need to register this DLL in order to use it locally for another product that requires it. what can I do?

I want to register the DLL so it will be added to Computer\HKEY_CLASSES_ROOT and use the DLL globally. I try to use also GACUTIL but it requires "strong name" which can take long time to produce.


Solution

  • As Hans Passant provided the link:

    Open an elevated command prompt and run regsvr32 ProjectName.comhost.dll. That will register all of your exposed .NET objects with COM.

    For details, please refer to: https://learn.microsoft.com/en-us/dotnet/core/native-interop/expose-components-to-com#register-the-com-host-for-com