0

I have taken over a project that is targeting .net4.

One of the projects within the solution is using System.Runtime.CompilerServices.CallerMemberNameAttribute from the System.Runtime.dll that is installed when you are using the Microsoft BCL Portability Pack.

I have checked and the project is currently using version 1.1.3.

When the solution is build on local dev machines, everything compliles with no problems.

I am now trying to get the solution built in teamcity, but when TeamCity attempts to compile the solution I am getting this error. error CS0246: The type or namespace name 'CallerMemberName' could not be found (are you missing a using directive or an assembly reference?) error CS0433: The type 'System.Runtime.CompilerServices.CallerMemberNameAttribute' exists in both 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll' and 'c:\apps\teamcity\buildAgent\work\bb8aacaa9fabeac8\packages\Microsoft.Bcl.1.1.3\lib\net40\System.Runtime.dll'

I have read Jon Skeets answer to this question: Using CallerMemberName attribute in a portable library But I am already using the BCL library.

Community
  • 1
  • 1
Darren Guy
  • 1,123
  • 2
  • 13
  • 39
  • 1
    Using the assemblies in c:\windows\microsoft.net is a very, very grave mistake. They are no longer suitable to act as proper reference assemblies since they cannot target a specific .NET 4.x version. You **must** use the ones in c:\program files\reference assemblies, picking the proper set that matches your target framework version. Failure to do so produces all kind of havoc, the build and runtime errors can be very hard to diagnose. Particularly .NET 4.5.x is very incompatible with .NET 4.0 – Hans Passant Jun 09 '14 at 10:53
  • Thats part of the problem. This proejct is still targeting .net 4. After installing Microsoft.Bcl, I have checked, and the link to System.Runtime.dll is referencing D:\Projects\website\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Runtime.dll. I am not referencing any dll directly in c:\windows\microsoft.net folder. So I do not understand why when TeamCity is compiling the project it is giving me the error – Darren Guy Jun 18 '14 at 09:20
  • @DarrenGuy I had a similar error; in my packages.config file the Microsoft.Bcl version was 1.1.10, but if I checked the file path of the project reference it was actually using an earlier version of Bcl. Removing and restoring the NuGet package fixed the error. Unfortunately I don't know how the project reference got confused in the first place so I don't want to post this as a possible answer. – GrahamMc Dec 07 '16 at 09:41

1 Answers1

0

After spending some time on this, I found another question answered by Jon Skeet that resolved this issue. When must we use extern alias keyword in C#?

Within my project, after getting the links to the Package, for each dll I had to change the name of the alias. ie from global to newglobal

Then in the classes that where using the CallerMemberName, had to do the following At the top of the page, above the using statements

extern alias newglobal;

And then when referencing CallerMemberName, enter the code as

[newglobal::System.Runtime.CompilerServices.CallerMemberName]

This allows the code to be successfully built on teamcity where .net 4.5 has been installed.

Community
  • 1
  • 1
Darren Guy
  • 1,123
  • 2
  • 13
  • 39