Skip to content

InvalidCastExceptions on generic types from different ALCs can be unhelpful. #80526

Open
@teo-tsirpanis

Description

@teo-tsirpanis

I got this error in my build:

System.InvalidCastException:

[A]System.Runtime.CompilerServices.StrongBox`1[Microsoft.Build.Tasks.Git.GitRepository] cannot be cast to [B]System.Runtime.CompilerServices.StrongBox`1[Microsoft.Build.Tasks.Git.GitRepository].

Type A originates from 'System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' in the context 'Default' at location 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.2\System.Private.CoreLib.dll'.
Type B originates from 'System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' in the context 'Default' at location 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.2\System.Private.CoreLib.dll'.

Types A and B are the same (and cannot be different since only one SPC can be loaded), which means by process of elimination that the GitRepositoryies in the generic parameters are from different ALCs. But the error message does not indicate that. It can be improved by more deeply analyzing the types to see what doesn't fit.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions