question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No Ijwhost.dll when referencing C++/CLR NuGet package from .NET 6 C# app

See original GitHub issue

It’s possible I’m missing something, but I can’t find any clear documentation on how Ijwhost.dll is supposed to work, so I thought I’d ask here.

I have a C++/CLR project targeting .NET 5, and when this is built in Visual Studio, Ijwhost.dll ends up in the bin/ folder alongside the compiled dll. If I reference this from a .NET 6 C# project in the same solution using <ProjectReference>, then Ijwhost.dll ends up copied into the output folder of the C# project as well, and everything works fine. (I don’t know where Visual Studio is sourcing this Ijwhost.dll from, but it clearly knows somewhere to look for it.)

If I reference the C++/CLR as a NuGet <PackageReference> from a .NET 6 C# project in a different solution, however, then no Ijwhost.dll ends up in the output folder. Nothing in the build seems to notice that I’m referencing a C++/CLR project and locate Ijwhost.dll, and if I try running the C# app, it fails to load my C++/CLR dll with a Failed to load file or assembly error. Manually copying an Ijwhost.dll into the output directory (eg, from the C++/CLR project in the other solution) fixes this, so it’s definitely this missing shim dll that’s the problem.

What’s the expected way to get this working? Is there an option I can specify in the .nuspec file or <PackageReference> tag that flags the package as C++/CLR and triggers the inclusion of Ijwhost.dll? Should be bundling Ijwhost.dll into the NuGet alongside the C++/CLR library? Should I be copying it from somewhere else (where?) in the C# csproj build steps?

There are a few other Ijwhost.dll-related issues in this repo already, but as far as I can tell they all seem to be about dynamically loading a C++/CLR dll via LoadLibrary, or about referencing the C++/CLR project as a project reference from elsewhere in the same solution – not about pulling it in as a NuGet dependency.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Qiu233commented, Jun 4, 2022

The ijwhost.dll needs to be part of NuGet when published, after that the rest should work fine. @jkoritzinsky would you know how to make it part of the NuGet package?

Also: moving this to the SDK repo where it belongs.

Well is there any possibility that two NuGet packages use different versions of ijwhost.dll? I think that would lead to something like dll-hell.

0reactions
ellizcommented, Apr 28, 2023

It seems my solution is not working for F# interactive, still searching a new solution! 😐 However, I found a solution to reference the DLL in the target file rather than include the ijwhost.dll in the NuGet package, see AmpScm/SharpProj#25 (comment)

That works for Microsoft.NET.Sdk … but not for Microsoft.NET.Sdk.Web … any idea why, or how to fix?

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# .Net6 - C++/CLI Nuget Package Fails
Net6. It seems strange that direct project references work but not installation from Nuget packages, as the same dlls get copied into the...
Read more >
How to port a C++/CLI project to .NET Core or .NET 5+
This support makes it possible to port Windows desktop applications with C++/CLI interop layers to .NET Core/.NET 5+.
Read more >
Porting a C++/CLI Project to .NET Core - C++ Team Blog
dll will make it impossible to create/consume NuGet packages with anything that uses C++/CLI, because of bug in NuGet (with PackageReference) ...
Read more >
Referencing a dll file using dotnet cli
Type in the csproj <Reference Include=“path to dll” />. Then put this dll in a nuget package and use package references (which is...
Read more >
How to resolve .NET reference and NuGet package version ...
In .NET, this issue is solved. We will usually ship DLL files separately for each application. Alternatively, we can use the GAC for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found