0

In the header file, Encrypt.h, I have the following:

#pragma once

using namespace System;

namespace NSpace
{
    namespace Encryption
    {
        [System::Runtime::CompilerServices::Extension]
        public ref class EncryptionExtensions abstract sealed
        {
        public:
            [System::Runtime::CompilerServices::Extension]
            static String^ ExtractEncrypt(String^ value, int length)
            {
                return value->Substring(0, length);
            }
        };
    }
}

In a VS 2015 project that I set up for testing, this builds without errors or warnings. In my original project, ported from VS 2010, above will not build: error C2337: 'Extension' : attribute not found error C2337: 'Extension' : attribute not found error C2337: 'Extension' : attribute not found error C2337: 'Extension' : attribute not found

Note two errors for each offending use of [Extension].

The project is C++/CLI (Properties->General->Common Language Runtime Support is set (/clr)). The Platform Toolset is Windows7.1SDK - the test project started out with "Visual Studio 2015 (v140)", but I changed it to emulate the failing project, and it didn't make any difference in the test project, it still builds.

The project Properties->C/C++->General->Common Language Runtime Support is also set (/clr).

The original build environment is VS 2010, version 10.0.40219.1 SP1Rel. The original and ported projects are both targeting .Net 4.0 (for C# projects).

Any ideas why this won't build (in the original project)?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • I'm building on Windows 7, 64-bit OS, 32-bit build (for C++). – user6745188 Aug 22 '16 at 21:34
  • 1
    You are, somehow, using old reference assemblies. Programmers went pretty nutty at VS2010 to try to build projects to target .NET 3.5. That cannot work, the C++/CLI runtime always targets .NET 4 and still building for older runtimes requires using VS2008. Open the .vcxproj files in Notepad and compare, crystal ball says that there is a stray `` element in the one that doesn't build. – Hans Passant Aug 22 '16 at 23:45
  • The is set to "v4.0". However, when I set the in my test project to "v4.0" (it was "v4.5.2"), and rebuild, it fails with identical errors. – user6745188 Aug 23 '16 at 14:17
  • 1
    Setting the to "v4.5.2" causes the build to complete with no errors. – user6745188 Aug 23 '16 at 15:19
  • If that works then you probably have a different problem, it is very nasty. You must use the [correct reference assemblies](http://stackoverflow.com/a/13750130/17034). – Hans Passant Aug 28 '16 at 07:59

0 Answers0