在我只添加了另一个变量和一个getter之前,代码就开始工作了。现在一切都不正常了。解决方案中所有项目的.NET版本是相同的(4.7)。错误截图
我不能再运行这个项目了,因为它没有正确地启动(有个错误)。怎么一回事?这种情况已经发生了好几个月了。我从我的高年级学生那里得到的答案是,这个解决方案是一个巨大的问题,Visual有时会错误地处理它,因此这个错误就是由此产生的灾难。区别在于,这次重新启动Visual /my并没有“解决”它。在清理和重建之后,我试着重新开始,但没有取得任何成果。有人知道该怎么做吗?
代码在我将<%# GetCssClass %>添加到.ascx文件之前工作。在我加了这个之后,一切都变坏了,即使我撤销了加起来,也没有什么是有效的。
.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="EventICTGenerator.ascx.cs" Inherits="CMSApp.CMSWebParts.MyCompany.DetailPages.Event.EventICTGenerator" %>
<%@ Register Src="~/CMSWebParts/MyCompany/Controls/ICSCalendarControl.ascx" TagPrefix="uc1" TagName="ICSCalendarControl" %>
<uc1:ICSCalendarControl runat="server" ID="ICSCalendarControl" LinkCssClass='event-header__info-actions-save <%# GetCssClass %>' 
      ResourceString="MyCompany.event.SaveTheDate"
      EventName='<%# EventName %>' 
      EventLocation='<%# EventLocation %>' 
      EventAddress='<%# EventAddress %>' 
      EventStartDate='<%# EventStartDate %>' 
      EventEndDate='<%# EventEndDate %>' 
      EventSummary='<%# EventSummary %>' />
<%# Position %>.ascx.cs
using CMS.DocumentEngine;
using CMS.Helpers;
using CMS.PortalEngine.Web.UI;
using System;
using System.Linq;
namespace CMSApp.CMSWebParts.MyCompany.DetailPages.Event
{
    public partial class EventICTGenerator : CMSAbstractWebPart
    {
        protected string EventName = "";
        protected string EventLocation = "";
        protected string EventAddress = "";
        protected DateTime EventStartDate = DateTime.Now;
        protected DateTime EventEndDate = DateTime.Now;
        protected string EventSummary = "";
        protected int widgetPosition = -1;
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (!StopProcessing)
            {
                SetupControl();
                BindEventData(EventDocumentID);
            }
        }
        private void SetupControl()
        {
            BindEventData(EventDocumentID);
            this.DataBind();
            widgetPosition = Position;
        }
        protected string EventDocumentID
        {
            get
            {
                return ValidationHelper.GetString(GetValue("EventID"), string.Empty);
            }
        }
        protected string EventLink
        {
            get
            {
                return ValidationHelper.GetString(GetValue("Link"), string.Empty);
            }
        }
        protected int Position
        {
            get
            {
                return ValidationHelper.GetInteger(GetValue("Position"), -1);
            }
        }
        protected string GetCssClass
        {
            get
            {
                return Position switch
                {
                    1 => "generic-content_align generic-content_align–left",
                    2 => "generic-content_align generic-content_align–center",
                    3 => "generic-content_align generic-content_align–right",
                    _ => "",
                };
            }
        }
        protected string EventLinkText
        {
            get
            {
                return ValidationHelper.GetString(GetValue("LinkText"), string.Empty);
            }
        }
        private string LinkTextAndUrl()
        {
            return $"{EventLinkText} <{EventLink}>";
        }
        private void BindEventData(string documentID)
        {
            TreeNode item = DocumentHelper.GetDocuments("MyCompany.Event")
                .Columns("EventName, LocationName, LocationAddress, ShortDescription, Date, EndDate")
                .OnCurrentSite()
                .WhereEquals("DocumentID", documentID)
                .FirstOrDefault();
            if (item != null)
            {
                string summary = ValidationHelper.GetString(item.GetValue("ShortDescription"), string.Empty);
                this.EventName = ValidationHelper.GetString(item.GetValue("EventName"), string.Empty);
                this.EventLocation = ValidationHelper.GetString(item.GetValue("LocationName"), string.Empty);
                this.EventAddress = ValidationHelper.GetString(item.GetValue("LocationAddress"), string.Empty);
                this.EventSummary = $"{summary}\n{LinkTextAndUrl()}";
                this.EventStartDate = ValidationHelper.GetDateTime(item.GetValue("Date"), DateTime.Now);
                this.EventEndDate = ValidationHelper.GetDateTime(item.GetValue("EndDate"), DateTime.Now);
            }
        }
    }
}发布于 2021-09-02 14:52:22
“解决”的办法是改变我的开关箱。我输入它就像
 switch
                {
                    1 => "generic-content_align generic-content_align–left",
                    2 => "generic-content_align generic-content_align–center",
                    3 => "generic-content_align generic-content_align–right",
                    _ => "",
                };VS告诉我,我的开关箱不好,这就是为什么我一开始就把它改成了那种形式。然后它并没有告诉我它有什么问题,也没有以任何方式指出它。
https://stackoverflow.com/questions/69031279
复制相似问题