命名空间不能直接包含成员... + 类型或命名空间定义,或文件结尾预期错误

2024-01-06

我正在尝试编译适用于 Windows Phone 的 Sync Framework 4.0 的示例代码,但是我在几个文件中遇到了错误。这些文件之一是:

#if SERVER
namespace Microsoft.Synchronization.Services
#elif CLIENT
namespace Microsoft.Synchronization.ClientServices
#endif
{
    /// <summary>
    /// Represents the base interface that all offline cacheable object should derive from.
    /// </summary>
    public interface IOfflineEntity
    {
        /// <summary>
        /// Represents the sync and OData metadata used for the entity
        /// </summary>
        OfflineEntityMetadata ServiceMetadata { get; set; }
    }
}

有两个错误:

  • 命名空间不能直接包含字段或方法等成员——对于第一个括号
  • 类型或名称空间定义,或预期的文件结束符 - 对于最后一个括号

我已经通过谷歌搜索了这两个错误,并且找到了很多此类错误的答案 - 但是这些错误都不能应用于我的情况(据我所知,没有缺少括号)。


您收到此错误是因为您既没有 SERVER 也没有 CLIENT条件符号 http://msdn.microsoft.com/en-us/library/aa691095%28v=VS.71%29.aspx定义的。预处理阶段消除文本后#if http://msdn.microsoft.com/en-us/library/4y6tbswk...#endif http://msdn.microsoft.com/en-us/library/hyx43has指令,编译器只看到这段代码:

{
    /// <summary>
    /// Represents the base interface that all offline cacheable object should derive from.
    /// </summary>
    public interface IOfflineEntity
    {
        /// <summary>
        /// Represents the sync and OData metadata used for the entity
        /// </summary>
        OfflineEntityMetadata ServiceMetadata { get; set; }
    }
}

这不是有效的 C# 代码(因为在打开大括号之前缺少“命名空间 xyz”)。

在 Visual Studio 中,转到项目属性和页面Build set 条件编译符号到服务器或客户端(名称区分大小写)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

命名空间不能直接包含成员... + 类型或命名空间定义,或文件结尾预期错误 的相关文章

随机推荐