1

I have a C# project that I'd like to use as a .NET Standard 2.0 library for other .NET assemblies and as a COM component for native code. I could create the COM object just fine when I targeted the full .NET Framework, but when I created a new project targeting .NET Standard, I got this error when I tried register it:

regasm /codebase /tlb MyLib.dll

RegAsm : error RA0000 : Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.

How can I build and register a DLL that is compatible with both .NET Standard and COM?

Edward Brey
  • 40,302
  • 20
  • 199
  • 253
  • i can't reproduce the issue. If I build a .netstandard ClassLibrary from scratch and run `C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm classlibrary1.dll /tlb /codebase`, it works fine. I have VS 201715.5.2 (the latest). – Simon Mourier Dec 20 '17 at 06:51
  • 1
    Regasm.exe will look in the GAC for dependent assemblies. Verify it is there, I have it in the C:\Windows\Microsoft.NET\assembly\GAC_MSIL\netstandard\v4.0_2.0.0.0__cc7b13ffcd2ddd51 directory. Update to .NET 4.7.1 if necessary. – Hans Passant Dec 20 '17 at 08:51

1 Answers1

1

Ensure that .NET 4.7.1 is installed. Even then, since Visual Studio doesn't copy NuGet packages to the output directory, expect to get a similar "Could not load file or assembly" error for one of those.

If you can live with a single project but two DLLs, this is an alternative: In your .csproj, remove the TargetFramework line and replace it with multiple targets, according to what your code needs, for example:

<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>

Then use the net461 DLL for use by COM and the netstandard2.0 for use by .NET.

Edward Brey
  • 40,302
  • 20
  • 199
  • 253