• Register
0 votes
594 views

Problem :

I am facing below error while trying to compile my code of C# in visual Studio 2015.

“There is no argument given that corresponds to the required formal parameter”

7 5 2
3,870 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

I had also faced a same issue in the past. I did a lot of research on it and found a solution on it. Since the Circle inherits from the Oval, when you create the Circle a default constructor for Oval is called in this case. Since that constructor accepts only 2 parameters, you need to explicitly call a constructor and provide them as shown below:

class Circle : Oval
{
    private double rad;
    public Circle(double Circle_Radius) : base(0, 0) // change to your values
    {
      rad = Circle_Radius;  
    }
}

So the Circle is an Oval, so it has a major_axis and minor_axis values. It seems you just did not provide them as they are very much required values to create the Oval.

Of course you can add the default public constructor for your Oval with no parameters, but that makes you to create the Oval with no major_axis and minor_axis and both seem required by a only constructor in a current status of your code. So, you need to rethink how to design the classes.

 

9 7 4
38,600 points
0 votes

Solution:

You have a constructor which accepts 2 parameters. You must write something like:

new ErrorEventArg(errorMsv, lastQuery)

It's less code and simpler to read.

EDIT

Or, in order for your way to perform, you can attempt writing a default constructor for ErrorEventArg which would have no parameters, like this:

public ErrorEventArg() {}

In the constructor of

 public class ErrorEventArg : EventArgs

You have to include "base" as follows:

  public ErrorEventArg(string errorMsg, string lastQuery) : base (string errorMsg, string lastQuery)
    {
        ErrorMsg = errorMsg;
        LastQuery = lastQuery;
    }

Your MenuModel class has a single constructor, which needs a DbContext parameter:

public MenuModel(DBContext context)

You are attempting to create an example of that class by calling the constructor without passing any parameters:

var menuModel = new NewWebsite_Site_2018.Pages.View.ViewBar_Info.MenuModel();

The compiler can't trace a constructor which doesn't accepts any parameters, and hence it generates the compiler error from your question.

You either require to pass the parameter to the constructor:

var menuModel = new NewWebsite_Site_2018.Pages.View.ViewBar_Info.MenuModel(new DBContext());

or include a parameterless constructor to the class:

public MenuModel() : this(new DBContext()) 
{
}

 

10 6 4
31,120 points

Related questions

0 votes
1 answer 40 views
40 views
Problem: I am beginner to C#. Please find below my code for your help: public class MySoundManager : MonoBehaviour { public List<AudioSource> audioSounds = new List<AudioSource>(); public double minTime = 0.5; public static void playSound(AudioClip sourceSound, Vector3 objectPosition, int ... to create the object of a class or create a methods as the static one but I don&rsquo;t know how to do it.
asked Jul 22, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 8 views
8 views
Problem: What are the desirable situation (real-life examples) to create static methods except for creating helper? Can anybody answer this question by briefly explaining every scenario???
asked Mar 23 ummesalma 29.2k points
1 vote
1 answer 12 views
12 views
What are polymorphism and inheritance? Why And When To Use "Inheritance" and "Polymorphism"?
asked Oct 4, 2020 Sofi55 1.1k points
0 votes
1 answer 15 views
0 votes
1 answer 18 views
2 votes
1 answer 29 views
29 views
Problem : I am new to C# and I am currently preparing for my interview and I have below question. &ldquo;When to use abstract class and interface in c# with real time example&rdquo; Can somebody help me in finding correct answer for above question?
asked Mar 24, 2020 morrisBson 3.2k points
1 vote
1 answer 86 views
86 views
Problem : While binding the dropdown in MVC, I often face following error: There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key country. Please find below my View for your reference : @Html.DropDownList("country", (IEnumerable<SelectListItem>)ViewBag ... .countryid.ToString() }); } ViewBag.mycountrydrop = myitem8; return View(); I do not know how to resolve above error.
asked Dec 28, 2019 alecxe 7.5k points
0 votes
1 answer 2 views
2 views
Problem: Can someone please help fix this > The general term for methods that are invoked as a result of a user action is
asked 6 days ago ummeshani 8.8k points
0 votes
1 answer 1 view
1 view
Problem: When should I use an interface and when should I use a base class? Should it always be an interface if I don't want to actually define a base implementation of the methods? If I have a Dog and Cat class. Why would I want to implement IPet instead of PetBase? ... IBarks (IMakesNoise?), because those can be placed on a pet by pet basis, but I don't understand which to use for a generic Pet.
asked Apr 26 Yeamin 21.4k points
0 votes
1 answer 3 views
3 views
Problem: My question is kinda basic, what do we call a constructor ? Can I call it a method? or something else? As a beginner, I have so many questions of the sort. Please answer my question. Thank You!
asked Mar 31 Code Learner 9.8k points