Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8823381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:20:27+00:00 2026-06-14T06:20:27+00:00

I have been trying to learn dependency injection but I have 2 errors when

  • 0

I have been trying to learn dependency injection but I have 2 errors when I run my code:

  1. DependencyInjection.Message.Sms() must declare a body because it is not marked abstract, extern, or partial.
  2. Cannot implicitly convert type DependencyInjection.IInterface to DependencyInjection.MyClass. An explicit conversion exists (are you missing a cast?)

Is the code below a good design for DI?

namespace DependencyInjection
{
    public interface IInterface
    {

    }

    public abstract class Message
    {
        public virtual void Sms();
    }

    public class MyClass : Message, IInterface
    {
        public override void Sms()
        {
            Console.WriteLine("Sms gönder.");
        }
    }

    public class ClassManager
    {
        private IInterface _myinterface;


        public MyClass Xyz
        {
            get { return _myinterface; }
            set { _myinterface = value; }
        }

        public ClassManager(IInterface myinterface)
        {
            _myinterface = myinterface;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:20:28+00:00Added an answer on June 14, 2026 at 6:20 am

    1) DependencyInjection.Message.Sms()’ must declare a body because it is not marked abstract, extern, or partial

    Add abstract keyword (and remove virtual) to method declaration:

    public abstract void Sms();
    

    2) Cannot implicitly convert type ‘DependencyInjection.IInterface’ to ‘DependencyInjection.MyClass’. An explicit conversion exists (are you missing a cast?)

    private IInterface _myinterface;
    public MyClass Xyz
    {
        get { return _myinterface; }
        set { _myinterface = value; }
    }
    

    Xyz has return-type of type MyClass but in get you are returning _myinterface which is of type IInterface.

    Change to following:

    public IInterface Xyz
    {
        get { return _myinterface; }
        set { _myinterface = value; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to learn about dependency injection and have been reading about
Ok, this may have been answered, but I'm new and trying to learn, so
I'm trying to learn dependency injection and have come across a problem, when unit
I have been trying to learn CakePHP's ACL stuff recently but keep getting confused,
Hi I have been trying to learn how to add some accessibility tools but
I have been trying to learn how to add testing to existing code --
I am somewhat new to jQuery but have been having fun trying learn about
I have been trying to learn from reading tutorials online and stuff but I
i have been trying to learn PHP Repeat Region... i have searched google but
I have been trying to learn how to build jQuery plugins, so I'm still

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.