【问题标题】:System.MissingMethodException: Method not found ,when i call sendEmail method in my repositorySystem.MissingMethodException:找不到方法,当我在我的存储库中调用 sendEmail 方法时
【发布时间】:2014-09-19 10:30:40
【问题描述】:

我正在尝试实施电子邮件服务。如您所见,我有一个存储库类:

 ConfigRepository objConfigRepository = new ConfigRepository();

      public bool SendMail(Message message, List<User> lstUser)
      {
          bool result = true;
          try
          {
              foreach (User item in lstUser)
              {
                  int reciverId = item.Id;
                  var ConfigMail = objConfigRepository.GetAll().First();
                  //var user = objUserRepository.FindBy(i => i.Id == reciverId).First();

                  WebMail.SmtpServer = ConfigMail.SmtpServer;
                  WebMail.SmtpPort = int.Parse(ConfigMail.SmtpPort);
                  WebMail.EnableSsl = ConfigMail.EnableSsl;
                  WebMail.UserName = ConfigMail.Username;
                  WebMail.Password = ConfigMail.Password;
                  WebMail.From = ConfigMail.From;

                  WebMail.Send(to: item.Email, subject: message.Title, body: message.MsgText);

              }
          }
          catch (Exception ex)
          {
              result = false;
          }

          return result;

      }

    }

如您所见,sendmail 需要 2 个参数 messageuserinfo。在我的控制器中,我这样调用此方法:

  objEmailRepository.SendMail(message, lstUser);

但我收到了这个错误:

Method not found: 'Void System.Web.Helpers.WebMail.Send(System.String, System.String, System.String, System.String, System.String, System.Collections.Generic.IEnumerable`1<System.String>, Boolean, System.Collections.Generic.IEnumerable`1<System.String>)'.

最好的问候

【问题讨论】:

  • 错误在这一行:WebMail.Send(to: item.Email, subject: message.Title, body: message.MsgText); you´re missing some params
  • 你知道我放了一个断点,但错误发生在这里 objEmailRepository.SendMail(message, lstUser);而且它没有通过你指向的线
  • 您使用的 System.Web.Helpers 是什么版本?也许您的参考版本不包含此方法?

标签: c# asp.net-mvc exception-handling


【解决方案1】:

System.MissingMethodException: Method not found?

尝试清理并重新编译您的解决方案,并确保您在 GAC 中拥有最新版本的 dll

【讨论】:

    猜你喜欢
    • 2011-04-01
    • 2011-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-25
    • 1970-01-01
    相关资源
    最近更新 更多