CallerLineNumberAttribute' exists in both 'System.Runtime' and 'mscorlib'

Mr Edge 221 Reputation points
2023-01-24T09:21:12.7166667+00:00

Running Visual Studio 2022 + all updates.

I have an old version of a Class Library running on .Net 4.7.

Im attempting to upgrade it to the new SDK style so

I first run the command

dotnet tool install --global Project2015To2017.Migrate2019.Tool

then

dotnet migrate-2019 wizard pathToProject

It asks to modernize the app and all questions that pop up i select Y.

I attempt to rebuild the project and get a package error (Microsft.Bcl) so search for this under the NuGet package options and install again. The next error that im presented with is

The type 'CallerLineNumberAttribute' exists in both 'System.Runtime, Version=2.6.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

Ive tried making different amendments to the .csproj file (removing <PackageReference Include="System.Runtime" Version="4.3.1" /> changing other values) but no matter what i try the above error remains.

What could i do to stop that error and build the project? If you require more info please advise and i can post any configs i have.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,919 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,193 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,010 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 66,706 Reputation points
    2023-01-24T18:25:33.3433333+00:00

    if you mix <4.5 and 4.6+ projects then you need the bcl nuget package. you will probably also need binding mappings.

    your best bet is to first update all the projects to 4.6+. and upgrade the nuget packages in the projects to a version that support net46 or netstandard20.

    if this is a solo 4.7 library project, then the nuget packages are the issue. you should upgrade them first and remove the bcl requirement.

    i'd also convert the project to netstandard 2.0 if the nuget packages allow, so you do not need runtime entires in the project file.

    0 comments No comments

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.