Skip to content

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

Closed

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'

Activity

  1. added a commit that references this issue on Mar 25, 2026
    3f05df6
  2. linked a pull request that will close this issuefix: #893 #894on Mar 25, 2026
  3. added a commit that references this issue on Mar 25, 2026
    e06d96a
  4. DocSvartz commented on Mar 25, 2026

    @DocSvartz
    Contributor
  5. DocSvartz commented on Mar 26, 2026

    @DocSvartz
    Contributor

    This should have been fixed in new release version.
    If your issue is still active, please reopen it or create new issue.
    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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