【问题标题】:I want to add a controller to my ASP.NET MVC project, but I get an error我想将控制器添加到我的 ASP.NET MVC 项目中,但出现错误
【发布时间】:2021-09-09 12:18:03
【问题描述】:

我使用 Visual Studio 2019。

在使用 Entity Framework 添加带有视图的 ASP.NET MVC 5 控制器时,此错误一次又一次出现,我尝试了很多方法都没有删除。

我的代码:

namespace SingletoninMVC.logger
{
    public sealed class Log : ILog
    {
        private Log()
        {
        }

        private static readonly Lazy<Log> instance = new Lazy<Log>(() => new Log());

        public static Log GetInstance
        {
            get { return instance.Value; }
        }

        public void LogException(string message)
        {
            string fileName = string.Format("{0}_{1}.log", "Exception", DateTime.Now.ToShortDateString());
            string logFilePath = string.Format(@"{0}\{1}", AppDomain.CurrentDomain.BaseDirectory, fileName);
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("----------------------------------------");
            sb.AppendLine(DateTime.Now.ToString());
            sb.AppendLine(message);

            using (StreamWriter writer = new StreamWriter(logFilePath, true))
            {
                writer.Write(sb.ToString());
                writer.Flush();
            }
        }
    }
}

【问题讨论】:

标签: c# asp.net asp.net-mvc visual-studio visual-studio-2019


【解决方案1】:

根据我的测试,我重现了与您相同的错误。

另外,我找到了解决方案。在使用实体框架添加带有视图的控制器之前,您可以尝试重建您的项目

它对我很有效。

【讨论】:

    猜你喜欢
    • 2021-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-10
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多