2

I have a namespace written in a C# solution that outputs a DLL. This DLL is an External Dependency for a C++ project in another solution. Previously I was using VS2013 but I've since began migrating to VS2017, and I'm getting

C2871 'Foo': a namespace with this name does not exist.

Here's a basic interpretation of my C++ code. "ExUtil" is a class within the FooExceptionUtil namespace.

    #include "FooExUtil.hh"

    using namespace Foo::ExceptionUtil;

    extern "C" {
    void FooExUtilWriteMiniDump (int Option) 
       {
          ExUtil::WriteMiniDump ((ExUtil::Option) Option);
       }
    }

My C# namespace looks like this:

    using System;
    using System.Diagnostics;
    using System.IO;
    using System.Runtime.InteropServices;

    namespace Foo.ExceptionUtil
       {
       static public class ExUtil
          {
          //Option enum and WriteMiniDump routine defined here
          }
       }

My C# solution outputs a DLL that is externally referenced by my C++ solution. And like I said, I had no issues with this using VS2013. Did VS2017 change the way external references work? I can view the namespace in the object browser of the C++ solution, and I can see all the way down to the individual Option enum and WriteMiniDump routines even. By all means, the namespace is defined.

-Thanks

jmcox
  • 86
  • 1
  • 7
  • I've had some issues like yours after upgrading to 2017. The way I fixed it was simply removed the custom dll references and re-added them again, then I checked the other classes inside the solution and made sure that the Build Action is compile. Then I clean, rebuild the solution and everything went back to normal. – iSR5 Sep 27 '18 at 14:52
  • Sorry, how exactly would I remove and re-add? It's an external dependency which as far as I know I can't manually add or remove. I did try adding the DLL to the solution as an "Existing Item" and did a clean/rebuild but that didn't do the trick. Also, are you referring to Build Action for the C# project or the C++ project? – jmcox Sep 27 '18 at 15:05
  • for the build action, in the C# project, and for the external dependency, https://stackoverflow.com/questions/16420595/how-to-add-external-native-dependency-dll .. also check the namespace and make sure it's correct. – iSR5 Sep 27 '18 at 16:41

1 Answers1

2

Alright so I figured out the problem. The C# DLL I was trying to access was built targeting a .NET 4.5 framework. VS Platform Toolset v141 is not compatible with .NET 4.5

I upgraded my C# application to .NET 4.7.1, but my C++ project still reported the same errors. I ended up having to manually edit the .vcxproj file, look for the section, and add a TargetFrameworkVersion tag, like so:

      <PropertyGroup Label="Globals">
         <ProjectGuid>{B21965FA-2013-4309-92CB-9282FFAEC9E2}</ProjectGuid>
         <RootNamespace>c2tcore</RootNamespace>
         <Keyword>MFCProj</Keyword>
         <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
         <TargetFrameworkVersion>4.7.1</TargetFrameworkVersion>
      </PropertyGroup>

After this I unloaded my C++ project, reloaded it, cleaned and rebuilt and it was finally successful. Hope this helps someone else down the road.

jmcox
  • 86
  • 1
  • 7