c# - 没有给定的参数对应于所需的形式参数 - .NET 错误

标签 c# .net .net-4.5

我一直在重构我的一个旧 MSSQL 连接帮助程序库,但出现以下错误:

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

到目前为止,这是我的代码:

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
    }
}

这个错误是什么意思,我该如何解决?我以前没见过这个错误...

最佳答案

的构造函数中
public class ErrorEventArg : EventArgs

您必须按如下方式添加“base”:

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

关于c# - 没有给定的参数对应于所需的形式参数 - .NET 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33607188/

相关文章:

c# - 注册 Moq 实例时 Autofac 抛出 File Not Found 异常

c# - 如何使用 System.Net.HttpListener 在 WebSocket 中启用 SSL

c# - 如何减少 Windows 服务的高 CPU 使用率?

c# - IIS/C# 网站与 Tomcat/Java 网站共享身份验证 - 相同的顶级 URL

c# - 如何在 GET 请求中包含内容?

c# - 有没有办法免费使用 Office 2007 工具栏创建桌面应用程序?

.net - .Net 4.5 中的 WinRT API

c# - C#函数播放base64编码的mp3文件

c# - 检查 IEnumerable<T> 是否有 5 个或更多匹配项

c# - 程序关闭时 "First-chance exceptions"