net6.0-android generated sources compile error(don't support covariant for return value )
See original GitHub issueDescription
I found some compile error when I reference the package “Microsoft.ML.OnnxRuntime” and compile the net6.0-android project, the compiler come from the generated sources in path “.\obj\Debug\net6.0-android\generated\src”;
it is caused by that CSharp don’t support covariant for return value: for example, below java sources:
interface IName {
public Object getName();
}
public class Maui implements IName {
@Override
public String getName() {
return "Maui";
}
}
and maui will convert above java sources to below CSharp sources
interface IName
{
public object Name { get; }
}
public class Maui : IName
{
public string Name => "Maui";
}
you can see the return value type “string” of the property “Name” is just copied from java sources in class “Maui”, it will lead to a compile error(reference Relevant log output section).
Steps to Reproduce
1.create a maui project; 2.add the package “Microsoft.ML.OnnxRuntime” from NuGet Package Manager; 3.compile the project; 4.you will receive some compile error message, reference log section;
Version with bug
Preview 11
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
all version
Did you find any workaround?
No response
Relevant log output
---------------------------------
Severity Code Description Project File Line Suppression State
Error CS0738 'OnnxMap' does not implement interface member 'IOnnxValue.Info'. 'OnnxMap.Info' cannot implement 'IOnnxValue.Info' because it does not have the matching return type of 'IValueInfo'. MauiApp1 (net6.0-android) C:\Work\Solutions\MauiApp1\obj\Debug\net6.0-android\generated\src\AI.Onnxruntime.OnnxMap.cs 10 Active
Error CS0738 'OnnxMap' does not implement interface member 'IOnnxValue.Value'. 'OnnxMap.Value' cannot implement 'IOnnxValue.Value' because it does not have the matching return type of 'Object'. MauiApp1 (net6.0-android) C:\Work\Solutions\MauiApp1\obj\Debug\net6.0-android\generated\src\AI.Onnxruntime.OnnxMap.cs 10 Active
Error CS0738 'OnnxSequence' does not implement interface member 'IOnnxValue.Info'. 'OnnxSequence.Info' cannot implement 'IOnnxValue.Info' because it does not have the matching return type of 'IValueInfo'. MauiApp1 (net6.0-android) C:\Work\Solutions\MauiApp1\obj\Debug\net6.0-android\generated\src\AI.Onnxruntime.OnnxSequence.cs 10 Active
Error CS0738 'OnnxSequence' does not implement interface member 'IOnnxValue.Value'. 'OnnxSequence.Value' cannot implement 'IOnnxValue.Value' because it does not have the matching return type of 'Object'. MauiApp1 (net6.0-android) C:\Work\Solutions\MauiApp1\obj\Debug\net6.0-android\generated\src\AI.Onnxruntime.OnnxSequence.cs 10 Active
Error CS0738 'OnnxTensor' does not implement interface member 'IOnnxValue.Info'. 'OnnxTensor.Info' cannot implement 'IOnnxValue.Info' because it does not have the matching return type of 'IValueInfo'. MauiApp1 (net6.0-android) C:\Work\Solutions\MauiApp1\obj\Debug\net6.0-android\generated\src\AI.Onnxruntime.OnnxTensor.cs 10 Active
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6

Top Related StackOverflow Question
This currently allows it to compile, have not tested it at runtime.
Hi @zhangzifang1. We have added the “s/try-latest-version” label to this issue, which indicates that we’d like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.
You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.
This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.