✅ Multi-target, wrong version
I am multi-targeting a project for NetFx and Net6/7. Specifically, there are four projects in play here:
Remora.Results - Provides the base Result and ResultError types for Net6/7
Tafs.Activities.Results - Provides the base Result and ResultError types for NetFx
Tafs.Activities.Results.Extensions - Conditionally includes Remora.Results or Tafs.Activities.Results based on framework version.
Tafs.Activities.Serialization - Targets Remora.Results or Tafs.Activities.Results based on target version. Additionally targets Tafs.Activities.Results.Extensions for extra error types.
My SocialSecurityNumber class relies on Tafs.Activities.Results.Extensions.Errors.ValidationError. This is happy on NetFx, but on Net6/7, I get an error saying I cannot implicitly convert it to Remora.Results.Result. I would expect this error if it picked the wrong version of the error to provide.
The source code of the ValidationError is this:
Whether it implements Tafs.Activities.Results.ResultError or Remora.Results.ResultError should in theory depend on the dotnet version, but it does not appear to be behaving as such.
To make things even stranger, this framework comparison extends to the csproj too. So in theory, the Net6/7 version shouldn't even be aware of Tafs.Activities.Results.
Any thoughts as to what might be going on here?
1 Reply
Oh, since it would be helpful- the error I'm getting for Net6.0 and Net7.0 targets is:
"Cannot implicitly convert type 'Tafs.Activities.Results.Extensions.Errors.ValidationError' to 'Remora.Results.Result'.
If I eliminate the explicit conversion and use the generic
Result.FromError<TError>()
method, the error changes to this:
"The type 'Tafs.Activities.Results.Extensions.Errors.ValidationError' cannot be used as type parameter 'TError' in the generic type or method 'Result.FromError<TError>(TError)'. There is no implicit conversion from 'Tafs.Activities.Results.Extensions.Errors.ValidationError' to 'Remora.Results.IResultError'."
This tells me that the Net6/7 version of ValidationError is actually implementing Tafs.Activities.Results.ResultError, even though there should be no way that it actually sees it.
Because Remora.Results.ResultError implements Remora.Results.IResultError, the only way there would not be an implicit conversion would be if one tried to implicitly convert Tafs.Activities.Results.ResultError to Remora.Results.IResultError.