Using C # dll (built using Microsoft.bcl) in an interop project (C ++)

We have a C # DLL in .net4.0, but built using Microsoft.bcl, Microsoft.bcl.async, Microsoft.bcl.build, Microsoft.net.http. These libraries got from nuget. We have reasons not to upgrade to .net4.5, but you want to use async, expect these bcl libs. Everything works fine in C # projects, but we could not add this DLL to our C ++ interaction projects, we will get this error:

We get this error when we try to add this link to the project.

Despite the fact that clr interop project is also in .net4.0 and the DLL that we add is also in .net4.0, we get this error. Is there any way to resolve this?

Error in text format: --------------------------- Microsoft Visual Studio --------------------------- Could not add a reference to: C:\xxx\xxx\xx\xxxHelper.dll For one of the following reasons: - Targets a higher version of the .NET Framework - Not a .NET assembly - Not a registered ActiveX control --------------------------- OK --------------------------- 

to reproduce this problem: https://dl.dropboxusercontent.com/u/1967630/BCL_Problem/oAuth2_SDK_consumer_DLL/BCL_Problem_projects.zipx

+5
source share
2 answers

I repeat, it certainly looks like a mistake. Judging by the error message in your screenshot, you are using VS2013. A very useless message, it softened in VS2015, but still fails. An odd btw error, it looks like it is considering a reference to the Microsoft.Threading.Task assembly, which your C # project uses as a structure assembly. No preliminary SO questions on this issue that I know of, most programmers get this right without having to fight the machine.

You should consider how to do this to avoid this error. This does not happen if you use the Browse button in the Add Link dialog box. But it works fine when you use the project link, as most programmers prefer to customize their solution. So use File> Add> Existing Project, select your C # project. Then add the link again, but this time select the C # project from the Solution> Projects list, rather than the Browse button.

If for some reason this is undesirable, you can work around it in another way. Open your .vcxproj in a text editor, Notepad is fine. Find this item:

  <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> 

And change the version number to v4.5 . Now add the link, as you did before, using the "Browse" button, this time no complaints. And go back to Notepad and change the version number to v4.0

+3
source

If nothing else helps, you can try decompiling your dll. .Net easy to configure.

Compiling again may solve the problem (for example, your dll from nuget might seem 4.5, not 4.0).

0
source

Source: https://habr.com/ru/post/1258811/


All Articles