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

C# 命名空间不能直接包含成员+;类型或命名空间定义,或预期的文件结尾错误,c#,windows-phone,C#,Windows Phone,我正在尝试为Windows Phone的同步框架4.0编译示例代码,但是在少数文件中遇到了错误。其中一个文件是: #if SERVER namespace Microsoft.Synchronization.Services #elif CLIENT namespace Microsoft.Synchronization.ClientServices #endif { /// <summary> /// Represents the base interface th

我正在尝试为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; }
    }
}
#如果服务器
命名空间Microsoft.Synchronization.Services
#elif客户端
命名空间Microsoft.Synchronization.ClientServices
#恩迪夫
{
/// 
///表示所有脱机可缓存对象应派生自的基本接口。
/// 
公共接口IOfflineEntity
{
/// 
///表示用于实体的同步和OData元数据
/// 
OfflineEntityMetadata服务元数据{get;set;}
}
}
有两个错误:

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

我在谷歌上搜索了这两个错误,找到了很多关于这两个错误的答案——但是没有一个可以应用到我的案例中(如果没有括号的话)。

你会遇到这个错误,因为你既没有定义服务器,也没有定义客户端。在预处理阶段后,删除。。。指令,编译器只能看到以下代码:

{
    /// <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; }
    }
}
{
/// 
///表示所有脱机可缓存对象应派生自的基本接口。
/// 
公共接口IOfflineEntity
{
/// 
///表示用于实体的同步和OData元数据
/// 
OfflineEntityMetadata服务元数据{get;set;}
}
}
这是无效的C#代码(因为在打开花括号之前缺少“名称空间xyz”)


在Visual Studio中,转到“项目属性”并在“页面生成”中将条件编译符号设置为服务器或客户端(名称区分大小写)。

我收到此错误是因为.TT文件中有UNIX样式的换行符,可能是因为换行符由git转换。将.tt文件复制到文本编辑器中,以PC格式保存,然后复制回VisualStudio为我解决了这个问题