Skip to content

CS0433 Compiler Error: 'NotNullWhenAttribute' exists in both 'Mapster' and 'System.Runtime' #893

@RainbowWolfer

Description

@RainbowWolfer

Description

When using Mapster (v10.0.4) in a .NET 7 project, a CS0433 compilation error occurs because the NotNullWhenAttribute is exposed publicly by the Mapster package, which collides with the built-in attribute in System.Runtime.

Steps to Reproduce

  1. Create a minimal csproj file targeting net7.0:
<Project Sdk="Microsoft.NET.Sdk">

	<PropertyGroup>
		<TargetFramework>net7.0</TargetFramework>
	</PropertyGroup>

	<ItemGroup>
		<PackageReference Include="Mapster" Version="10.0.4" />
	</ItemGroup>

</Project>
  1. Add a simple test class utilizing the attribute:
using System.Diagnostics.CodeAnalysis;

namespace MapperTest;

public class Tests
{
	public Tests()
	{

	}

	protected virtual bool TryLoadAssembly(
		string filePath,
		[NotNullWhen(true)] out string assembly
	)
	{
		assembly = null;
		return false;
	}
}
  1. Build the project.
    Observed Behavior
    The build fails with the following compiler error:
error CS0433: The type 'NotNullWhenAttribute' exists in both 'Mapster, Version=10.0.4.0, Culture=neutral, PublicKeyToken=2f39883af23c29a8' and 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions