-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Description
It is possible to get MissingMethodException exception for init-only properties in some build configurations (see below)
Ready-to-run code:
ConsoleApp48.zip
Reproduction Steps
To use records in code, built against pre-net5.0 TFMs we need to define IsExternalInit class manually in those projects.
To reproduce issue we need at least two TFMs:
- one that doesn't have
IsExternalInit, we will usenetstandard2.0as example - one with
IsExternalInit, let's usenet7.0
Solution configuration:
project Awith both TFMs, record andIsExternalInitwrapped in#if !NET5_0_OR_GREATER(that's important part!)project Bwithnetstandard2.0TFM, record modification code usingr with { Prop = new value}and refence toproject A(for record definition)project Cwithnet7.0TFM calling modification code fromproject Bwith references to bothproject Aandproject B(another importand part!)
When we build project C we also get:
netstandard2.0binary fromproject Bnet7.0binary fromproject A(if we don't have direct reference toA, it will benestandard2.0transitive build)
Trying to run project C binary will result in MissingMethodException exception which looks to me like some unnecessary (or not?) strict modreqs verification
Expected behavior
It just works (C) Todd Howard
Actual behavior
Unhandled exception. System.MissingMethodException: Method not found: 'Void TestRecord.set_Test(System.String)'.
at Test.TestRecord()
at Program.Main()
Regression?
No response
Known Workarounds
Workaround is actually easy - don't use conditional compilation when adding IsExternalInit to project so all TFM artifacts will use same class. Fortunatelly because this is internal class, it is possible to do without conflicts if you don't use InternalsVisibleTo
Configuration
No response
Other information
No response