[c#] There is no argument given that corresponds to the required formal parameter - .NET Error

I have been re-factoring one of my old MSSQL Connection helper library and I got the following error:

Severity Code Description Project File Line Error CS7036 There is no argument given that corresponds to the required formal parameter 'errorMsg' of 'ErrorEventArg.ErrorEventArg(string, string)' MSSQLTest C:\Users\Administrator\Desktop\MSSQLTest\MSSQLTest\MSSQLConnection.cs 61

This is my code so far:

MSSQLConnection.cs

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Threading;

namespace MSSQLTest
{
    public class ErrorEventArg : EventArgs
    {
        public string ErrorMsg { get; set; }
        public string LastQuery { get; set; }

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

    public class MSSQLConnection
    {
        /// <summary>
        /// Private class objects.
        /// </summary>
        private SqlConnection sqlConnection;
        private int sqlCommandTimeout;
        private string lastQuery = string.Empty;

        /// <summary>
        /// Public event related objects & handler.
        /// </summary>
        public event ErrorHandler OnError;
        public delegate void ErrorHandler(MSSQLConnection sender, ErrorEventArg e);

        /// <summary>
        /// Class constructor.
        /// </summary>
        /// <param name="sqlConnection"></param>
        /// <param name="sqlCommandTimeout"></param>
        public MSSQLConnection(SqlConnection sqlConnection, Int32 sqlCommandTimeout = 120)
        {
            if (null == sqlConnection)
                throw new Exception("Invalid MSSQL Database Conection Handle");

            if (sqlConnection.State != System.Data.ConnectionState.Open)
                throw new Exception("MSSQL Database Connection Is Not Open");

            this.sqlConnection = sqlConnection;
            this.sqlCommandTimeout = sqlCommandTimeout;
        }

        /// <summary>
        /// Helper method to emit a database error to event subscribers.
        /// </summary>
        /// <param name="errorMsg"></param>
        internal void EmitError(String errorMsg)
        {
            var errorDelegate = OnError;
            if (errorDelegate != null)
            {
                errorDelegate(this, new ErrorEventArg() // Line #61
                {
                    ErrorMsg = errorMsg,
                    LastQuery = lastQuery
                });
            }
        }

        /// rest of the code snipped
    }
}

What does this error means & how do I fix it? I've not seen this error before...

This question is related to c# .net .net-4.5

The answer is


In the constructor of

 public class ErrorEventArg : EventArgs

You have to add "base" as follows:

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

That solved it for me


I got the same error but it was due to me not creating a default constructor. If you haven't already tried that, create the default constructor like this:

public TestClass() {

}


I got this error when one of my properties that was required for the constructor was not public. Make sure all the parameters in the constructor go to properties that are public if this is the case:

using statements namespace someNamespace

public class ExampleClass {

  //Properties - one is not visible to the class calling the constructor
  public string Property1 { get; set; }
  string Property2 { get; set; }

   //Constructor
   public ExampleClass(string property1, string property2)
  {
     this.Property1 = property1;
     this.Property2 = property2;  //this caused that error for me
  }
}

I received this same error in the following Linq statement regarding DailyReport. The problem was that DailyReport had no default constructor. Apparently, it instantiates the object before populating the properties.

var sums = reports
    .GroupBy(r => r.CountryRegion)
    .Select(cr => new DailyReport
    {
        CountryRegion = cr.Key,
        ProvinceState = "All",
        RecordDate = cr.First().RecordDate,
        Confirmed = cr.Sum(c => c.Confirmed),
        Recovered = cr.Sum(c => c.Recovered),
        Deaths = cr.Sum(c => c.Deaths)
    });

Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to .net

You must add a reference to assembly 'netstandard, Version=2.0.0.0 How to use Bootstrap 4 in ASP.NET Core No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization .net Core 2.0 - Package was restored using .NetFramework 4.6.1 instead of target framework .netCore 2.0. The package may not be fully compatible Update .NET web service to use TLS 1.2 EF Core add-migration Build Failed What is the difference between .NET Core and .NET Standard Class Library project types? Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies Nuget connection attempt failed "Unable to load the service index for source" Token based authentication in Web API without any user interface

Examples related to .net-4.5

There is no argument given that corresponds to the required formal parameter - .NET Error The type or namespace name 'System' could not be found Which versions of SSL/TLS does System.Net.WebRequest support? async at console app in C#? Is it possible to run a .NET 4.5 app on XP? Awaiting multiple Tasks with different results Do you have to put Task.Run in a method to make it async? C# HttpClient 4.5 multipart/form-data upload Do HttpClient and HttpClientHandler have to be disposed between requests? What is the correct way to read a serial port using .NET framework?