-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C# 9 covariant return types: Still can get System.TypeLoadException when using generics #45344
Comments
This also happens in 5.0.100 if you just return T directly, rather than a type that uses T, e.g.
|
Hi, in the meantime before this fix is released, I am trying to continue developing my app on machines with 5.0.101 installed (I didn't experience the error on 5.0.100 for some reason, it only appeared when 5.0.101 was installed). Is there any way to force usage of 5.0.100 for running it with a global.json? When I attempt this, |
Would setting the runtime version property in the csproj file to 5.0.100 work as a workaround?
|
Trying this I get "Unable to find package Microsoft.NETCore.App.Host.win-x64 with version (= 5.0.100)" (seems only 5.0.1 exists at https://www.nuget.org/packages/Microsoft.NETCore.App.Host.win-x64/?). Using 5.0.1 instead the issue is still present I assume as this still instructs it to use the latest patch version. |
I am sorry for the confusion, I meant 5.0.0. |
Ah ok, using 5.0.0 unfortunately the TypeLoadException is still present. My full csproj is:
|
Still can reproduce with small code modifications: using System;
var c = new AChild<string>();
Console.WriteLine("Hello World!");
public abstract class A<T>
{
public abstract B<T> GetB();
}
public class AChild<T> : A<T>
{
public override BChild<T> GetB() => null;
}
public class B<T>
{
}
public class BChild<T> : B<T>
{
} |
@ASolomatin what version of runtime have you reproed it with? The latest fix is not in any released .NET 5 versions, it will be part of 5.0.2. |
Sorry. ) I thought, it's already released because the original issue stops to reproduce on 5.0.1 |
@ASolomatin I'll verify it with the latest version to make sure this is not yet another problem. |
I can confirm that your test above passes with runtime from the master branch, which means that it should pass with the 5.0.2 once it is out. |
@janvorli I have the same bug with 5.0.2 |
Just one next code modification to reproduce on 5.0.2 somesing look likes the same: using System;
var c = new AChild<string>();
Console.WriteLine("Hello World!");
public abstract class A<T1, T2>
{
public abstract B<T1, T2> GetB();
}
public class AChild<T> : A<T, string>
{
public override BChild<T> GetB() => null;
}
public class B<T1, T2>
{
}
public class BChild<T> : B<T, string>
{
} alex@nout-1:~/Projects/DummyTests/N5$ dotnet --version
5.0.102
alex@nout-1:~/Projects/DummyTests/N5$ dotnet run
Unhandled exception. System.TypeLoadException: Return type in method 'AChild`1[T].GetB()' on type 'AChild`1[T]' from assembly 'N5, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not compatible with base type method 'A`2[T,System.__Canon].GetB()'. |
@ASolomatin thank you for the repro. I have tested it with my pending fix for the #47007 and the issue is gone with that fix. |
Description
This looks like dotnet/core#5319 but with generics.
The C # 9.0 overridden virtual function works fine when the return type is a covariant derived type, continues to work if the return type is a covariant derived type that contains the overridden function. But System.TypeLoadException is thrown at runtime if you add some generics. As before, everything builds without errors and warnings.
Code to reproduce
Error:
Versions
5.0.100-rc.2.20479.15
5.0.100
Originally posted by @ASolomatin in dotnet/core#5319 (comment)
The text was updated successfully, but these errors were encountered: