You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Covariant Return crashes on runtime when there is additional abstract class in between not overriding the abstract method. #45053
In net 5.0, windows 10x64, Visual Studio 2019 and C#9 the below code will not run and will produce the following error:
System.TypeLoadException: Return type in method 'Application.TB.GetA()' on type 'Application.TB' from assembly 'Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not compatible with base type method 'Application.T`1[System.__Canon].GetA()'.
publicabstractclassT<TR>{publicabstractTRGetA();}// This abstract causes the error - not overriding the base method cause the runtime to crashpublicabstractclassTA:T<A>{}// This works// public abstract class TA : T<A>// {// // Overriding in between fixes the problem// public override A GetA() => new ();// }// Overriden here, in the grandsonpublicclassTB:TA{publicoverrideBGetA()=>new();}publicclassA{}publicclassB:A{}publicstaticclassProgram{publicstaticvoidMain(string[]args){System.Console.WriteLine((newTB()asT<A>).GetA().GetType().FullName);}}
changed the title [-]Covariant Return fails when there is additional abstract class in between not overriding the base method.[/-][+]Covariant Return fails when there is additional abstract class in between not overriding the abstract method.[/+]on Nov 21, 2020
changed the title [-]Covariant Return fails when there is additional abstract class in between not overriding the abstract method.[/-][+]Covariant Return cruches on runtime when there is additional abstract class in between not overriding the abstract method.[/+]on Nov 22, 2020
changed the title [-]Covariant Return cruches on runtime when there is additional abstract class in between not overriding the abstract method.[/-][+]Covariant Return crashes on runtime when there is additional abstract class in between not overriding the abstract method.[/+]on Nov 22, 2020
This is unfortunately a new issue. With the latest fixes for covariant returns issues that will be released in 5.0.2, it fails with
Unhandled exception. System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (0x8007000B (COR_E_BADIMAGEFORMAT))
at Program.Main(String[] args)
Fortunately, it was just a local issue, I have probably built debug runtime and tested the test with an old checked one. After rebuilding, the test above is passing. Closing this issue now as a dup of #45037.
Activity
[-]Covariant Return fails when there is additional abstract class in between not overriding the base method.[/-][+]Covariant Return fails when there is additional abstract class in between not overriding the abstract method.[/+][-]Covariant Return fails when there is additional abstract class in between not overriding the abstract method.[/-][+]Covariant Return cruches on runtime when there is additional abstract class in between not overriding the abstract method.[/+][-]Covariant Return cruches on runtime when there is additional abstract class in between not overriding the abstract method.[/-][+]Covariant Return crashes on runtime when there is additional abstract class in between not overriding the abstract method.[/+]lambdageek commentedon Nov 23, 2020
(works on mono -
(new TB() as T<A>).GetA().GetType().FullNamereturnsB))pmrogala commentedon Nov 23, 2020
Thanks, I updated the description with your discovery :)
pentp commentedon Dec 22, 2020
@janvorli - This is probably the same issue as #45037, but in reverse (concrete type overriding generic type)?
janvorli commentedon Dec 22, 2020
This is unfortunately a new issue. With the latest fixes for covariant returns issues that will be released in 5.0.2, it fails with
janvorli commentedon Dec 22, 2020
Fortunately, it was just a local issue, I have probably built debug runtime and tested the test with an old checked one. After rebuilding, the test above is passing. Closing this issue now as a dup of #45037.
janvorli commentedon Jan 26, 2021
It turns out the issue wasn't fixed. There must have been some issue in my local process.