Cannot add reference to C++ dll project

Heiko 1,291 Reputation points
2023-05-04T15:52:47.8766667+00:00

Hi,

I have a WPF desktop bridge solution (VS 2017). In the main project (WPF app in C#) I could add a reference to a C++/CLR project. Now I created a C++ dll project without CLR support. In it I use functions from the namespace Microsoft::WRL and it's not allowed to use this namespace in a dll with CLR support. I set the project dependencies and want to add the C++ dll project to the references of the main project. But I get the following error:

AddReference

Why is it? What can I do?

Developer technologies Windows Presentation Foundation
Developer technologies Visual Studio Other
Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Hui Liu-MSFT 48,676 Reputation points Microsoft External Staff
    2023-05-05T08:46:55.6566667+00:00

    Hi,@Heiko. Welcome Microsoft Q&A.

    The error message A reference to '*' could not be added. The method or operation is not implemented" usually indicates a problem with the project reference you are trying to add.

    Here are some things you could try to fix this problem:

    1. Check the path to the C++ project: Make sure the path to the C++ project is correct and exists. If the path is incorrect or the project does not exist, the reference will not be added.
    2. Check your Visual Studio version: Make sure you are using a version of Visual Studio that supports adding C++ project references. Not all versions of Visual Studio support this feature.
    3. Check C++ project compatibility: Make sure your C++ project is compatible with the .NET Framework version used in your WPF project. If the C++ project is not compatible, you will not be able to add references.
    4. Try adding references manually: Instead of using the Add Reference dialog, try adding references manually by editing the .csproj file. You can do this by opening the .csproj file in a text editor and adding a reference to the C++ project. Here's an example of what a reference might look like:
    <ProjectReference Include="[path to your C++ project .vcxproj file]">
      <Project>{[C++ project GUID]}</Project>
      <Name>[C++ project name]</Name>
    </ProjectReference>
    
    

    Make sure to replace the path and GUID with the correct values for your C++ project.

    5.Restart Visual Studio: Sometimes simply restarting Visual Studio resolves issues with adding project references.

    You can also try to see if the solution here helps you.


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.