✅ Multi-targeting NetFx and NetCore - Targeting wrong version?
History
My last post was a bit of a mess so I've come here to help clean it up a bit.
I have a project called Tafs.Activities.Finance. It multi-targets net461, net462, net6.0, and net7.0. In the project file, I have a few conditional includes. If we're working with NetFx, it includes a reference to Tafs.Activities.Results. If we're working with Net6/7, it instead includes a reference to Remora.Results. These two libraries provide the same types, though for NetFx and Net6.0+ respectively.
In the Finance library, I have a type called SocialSecurityNumber which references a ValidationError. ValidationError exists in a third library: Tafs.Activities.Results.Extensions. The extensions library is set up very similarly to the finance library in its conditional includes.
The ValidationError type implements ResultError, which is provided by either Tafs.Activities.Results or Remora.Results depending on the target.
Intellisense on ResultError does update properly between Tafs.Activities.Results and Remora.Results based on the selected build target.
The Error
When consuming ValidationError in my Finance project, I do so by assigning it to a Result type. The source of the Result type should likewise correspond to the selected build target, and Intellisense does confirm this. NetFx should only be aware of Tafs.Activities.Results and Net6/7 should only be aware of Remora.Results. This assignment operation relies on an implicit converter which handles anything of type ResultError:
I get two exceptions on the return statement when targeting net461 or net462:
Adding a reference to Remora.Results as suggested, even though NetFx can't use it, does resolve the second error, but I think that's a fake error anyways so I'm ignoring that.
What I think is happening is that when the Finance library is referencing Tafs.Activities.Results.Extensions, it's somehow grabbing the Net6/Net7 target, even though the Finance library itself is targeting net461 or net462. If I change the target selector for the finance library to Net6 or Net7, the error goes away and the Result type changes to Remora.Results.Result. I have tried doing a project clean, then building the projects one at a time, but this does not have any effect on the issue. Does anyone have any ideas as to what might be happening here or how to fix it?
5 Replies
Tagging @Jax since your library is involved, though likely not complicit in the error. I think this is probably some weird language thing
Why are you using a different library when on netfx?
Remora.Results does not support net461 or net462
Wait, Jax is targeting NetStandard 2.0, which supports Net461 and 462
That solves my issues right there. No more multi-targeting!
yeah i was gonna say
Glad I found that