Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# Registering Delegate in Interface throw Target Framework Error

I am working on Azure Function FunctionA that is TargetFramework netcoreapp3.1. This FunctionA calls another project for services whose TargetFramework is netstandard2.0. In these service I have interface where I am trying to register Delegates but unable to do so and getting version error; reference below;

enter image description here

public interface ICustomerServices
{
    delegate Task<IEnumerable<string>> AppCustomerListHandler();
    Task<string> GetMyName();
}

Can I solve this problem without upgrading any framework

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

A delegate just describes the "shape" that some methods will conform to. It doesn’t, in itself, describe an actual member of any enclosing type. If you want to consume a delegate within an interface, that’s not a problem, e.g.:

public delegate Task<IEnumerable<string>> AppCustomerListHandler();
public interface ICustomerServices
{
    event AppCustomerListHandler AppCustomerListHandler;
    Task<string> GetMyName();
    void DoSomething(AppCustomerListHandler appCustomerListHandler);
}

Is just fine.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading