A namespace cannot directly contain members... + Type or namespace definition, or end-of-file expected errors(命名空间不能直接包含成员.+类型或命名空间定义,或文件结尾预期错误)
问题描述
我正在尝试编译Windows Phone同步框架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; }
}
}
有两个错误:
- 命名空间不能直接包含字段或方法等成员--第一个括号
- 类型或命名空间定义,或文件结尾--用于最后一个括号
我已经在Google上搜索了这两个错误,找到了很多此类错误的答案--但是这些答案都不适用于我的案例(AFAIK没有漏掉的括号)。
推荐答案
您会收到此错误,因为您既没有定义服务器,也没有定义客户端conditional symbol。预处理阶段消除#if.#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; }
}
}
这不是有效的C#代码(因为在打开大括号之前缺少"命名空间xyz")。
在Visual Studio中,转到"项目属性",并在"生成"页上将条件编译符号设置为服务器或客户端(名称区分大小写)。
这篇关于命名空间不能直接包含成员.+类型或命名空间定义,或文件结尾预期错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:命名空间不能直接包含成员.+类型或命名空间定义,或文件结尾预期错误


基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01