question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

net6.0-android generated sources compile error(don't support covariant for return value )

See original GitHub issue

Description

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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

2reactions
jdluzencommented, Feb 27, 2022

This currently allows it to compile, have not tested it at runtime.

namespace AI.Onnxruntime
{
    public partial class OnnxMap : Java.Lang.Object, IOnnxValue
    {
        IValueInfo IOnnxValue.Info
        {
            get => Info;
        }

        Java.Lang.Object IOnnxValue.Value
        {
            get => (Java.Lang.Object)Value;
        }
    }

    public partial class OnnxSequence : Java.Lang.Object, IOnnxValue
    {
        IValueInfo IOnnxValue.Info
        {
            get => Info;
        }

        Java.Lang.Object IOnnxValue.Value
        {
            get => (Java.Lang.Object)Value;
        }
    }

    public partial class OnnxTensor : Java.Lang.Object, IOnnxValue
    {
        IValueInfo IOnnxValue.Info
        {
            get => Info;
        }
    }
}
0reactions
msftbot[bot]commented, Apr 11, 2023

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why covariance and contravariance do not support value ...
IEnumerable<T> is co-variant but it does not support value type, just only reference type. The below simple code is compiled successfully:
Read more >
Unable to compile .net 6.0 projects in VS 2022
I am unable to compile .net 6.0 projects in VS 2022 (version 17.4.3). I see error message that - MSB3971 The reference assemblies...
Read more >
Covariant return types - C# 9.0 draft feature specifications
This feature specification describes covariant return types, where overriding ... It is a compile-time error if no unique such type exists.
Read more >
Why isn't .NET Standard 2.0 used as the default compared ...
I know that .NET Framework and .NET Core are the implementation frameworks, while .NET Standard 2.0 is the specification that the frameworks ...
Read more >
Unpopular opinion maybe but C# is getting too bloated
Yeah, I've been feeling that C# needs a Kotlin since NNRTs were introduced. Kotlin is a language that compiles to the same IL...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found