首页 > 解决方案 > 我在下面的代码中收到 PXDefault 的发布错误

问题描述

我检查了代码的所有大括号和语法,这是唯一发布的代码。我已经删除了其他所有内容

using PX.Objects;
using PX.Data;

namespace MaxQ.Products.RBRR
{
  public class ContractMaint_Extension : PXGraphExtension<ContractMaint>
  {
    #region Event Handlers
   
    protected virtual void XRBContrHdr_DestSiteID_CacheAttached(PXCache cache)
      {   
         [PXDefault(typeof(Search2<INSite.siteCD,
          InnerJoin<BAccount, On<BAccount.bAccountID, Equal<Current<XRBContrHdr.bAccountID>>>,
          InnerJoin<LocationExtAddress, On<LocationExtAddress.locationID, Equal<BAccount.defLocationID>>>>,
          Where<INSite.siteID, Equal<LocationExtAddress.cSiteID>>>), PersistingCheck = PXPersistingCheck.Nothing)]
      }
      
    #endregion
  }
}

我得到的错误是

\App_RuntimeCode\ContractMaint.cs(13): 错误 CS1513: } 预期

\App_RuntimeCode\ContractMaint.cs(18):错误 CS1519:类、结构或接口成员声明中的令牌“}”无效

\App_RuntimeCode\ContractMaint.cs(22):错误 CS1022:类型或命名空间定义,或预期文件结尾

\App_RuntimeCode\ContractMaint.cs(13): 错误 CS1513: } 预期

标签: c#acumatica

解决方案


错误消息指向{}源代码中的格式错误的块: 在此处输入图像描述

出现这种情况是因为属性需要放在方法之前来装饰方法:

[PXDefault(…)]
protected virtual void XRBContrHdr_DestSiteID_CacheAttached(PXCache cache)
{
}

在您的代码中,属性放置在在 C# 中无效的方法定义中:

protected virtual void XRBContrHdr_DestSiteID_CacheAttached(PXCache cache)
{
   [PXDefault(…)]
}

推荐阅读