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.

MSBuild Reference tag to pull over the ijwhost.dll if it can detect the assembly is a C++/CLI assembly

See original GitHub issue

I want to make a c++/cli wrapper to use c++ in c# and then pack it into a NuGet package. I tried it with a c# project in the solution first by project referencing the c++/cli project. -> (this worked) Then I tried packing it into a NuGet (which I am really new to) but when adding the NuGet and executing the project I got the BadImageFormatException. Later I found out that this exception is also thrown by just simply referencing the c++/cli project as a assembly.

Summary:

My main issue is that I can’t load my c++/cli wrapper in form of a dll, but only as a project reference. Upon loading it as an assembly I get the BadImageFormatException. (As already mentioned above)

For more info to my main issue see dotnet/runtime#57642 or look at the demo of my project https://github.com/wwelias/demo_core.git.

Under the first issue I created @AaronRobinsonMSFT said the following things (I hope I understood them correctly and ain’t saying wrong stuff now):

  • Problem with how SDK copies dependencies upon doing a Reference

  • Probably has to do with the ijwhost.dll missing I tried moving the ijwhost.dll to various locations e. g. the folder of the demo_cs.exe but the outcome was the same.

  • As a potential fix he recommended to include a MSBuild Reference tag to pull over the ijwhost.dll if it can detect that the assembly is a C++/CLI assembly and to create a new issue here.

Maybe anyone can help me?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jnyrupcommented, Sep 12, 2021

Thanks for the snippets, that’s also how I currently workaround the problem. Just wanted to make sure I hadn’t missed a better solution.

0reactions
wweliascommented, Sep 12, 2021

@jnyrup this is the .tragets-File I used: <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <None Include="$(MSBuildThisFileDirectory)Ijwhost.dll"> <Link>Ijwhost.dll</Link> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> </ItemGroup> </Project>

It basically copies the Ijwhost.dll into the OutputDirectory which is exactly what we need. But don’t forget to add the the Ijwhost.dll to your files in the .nuspec because otherwise it won’t be included in the .nupkg and it has nothing to copy. <file src="build\Ijwhost.dll" target="build\Ijwhost.dll" /> <?xml version="1.0" encoding="utf-8"?> <package> <metadata> ... </metadata> <files> <file src="build\Ijwhost.dll" target="build\Ijwhost.dll" /> ... </files> </package>

Hope this kind of inserting code is okay to look at… don’t know how I can make it better bcs I am new to github. And I hope this helped.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MSBuild doesn't copy references (DLL files) if using project ...
You have two options to solve this problem, both of which will result in assembly B being copied to project Y's bin directory:....
Read more >
C++/CLI libraries may fail to load due to `ijwhost.dll` not ...
This means that, depending on how a host application loads the C++/CLI library, the C++/CLI library may fail to load due to ijwhost....
Read more >
ResolveAssemblyReference Task - MSBuild
Learn how MSBuild uses the ResolveAssemblyReference task to determine all assemblies that depend on the specified assemblies.
Read more >
msbuild does not copy dll references that are already in the ...
When I build my project, msbuild does not copy the referenced DLL to the output directory even with CopyLocal=True because it is already...
Read more >
MSBuild forum - RSSing.com
Can anyone explain why that happens and how can I force the build menu to build under .net core platform? If I remove...
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