Contexts.Context.Parameters 在 .NET 4.5 中是否被弃用?

Is Contexts.Context.Parameters deprecated in .NET 4.5?

在我大发雷霆之前帮助我,把房子里所有的毛绒兔子的头都撕下来!!

我只是想按照 MSDN tutorial 在 C# 中创建 Windows 服务。在子节 "Adding Startup Parameters" 下,有以下代码行:

System.Runtime.Remoting.Contexts.Context.Parameters["assemblypath"] = ...

当我在该行中键入符号参数时,VS2013(高级版)显示此错误:"Cannot resolve symbol 'Parameters'." 当我在帮助查看器和 MSDN 中检查 Contexts.Context class 时在线,Context,确实没有Parameters 属性。好吧,哎呀,我敢肯定很多人都尝试过这个演练;他们都遇到过这个错误吗?

我用谷歌搜索了几个小时,一切我发现关于设置上下文参数、使用上下文参数或两者的讨论。我找不到任何表明 Context.Parameters 已被弃用的内容。

我在 that tutorial page 上唯一能找到的 Context.Parameters 出现在以下代码片段中,在 "Adding startup parameters" 下的第 3 步中:

protected override void OnBeforeInstall(IDictionary savedState)
{
    string parameter = "MySource1\" \"MyLogFile1";
    Context.Parameters["assemblypath"] = "\"" + Context.Parameters["assemblypath"] + "\" \"" + parameter + "\"";
    base.OnBeforeInstall(savedState);
}

在这个方法中,Context指的是Context property that's inherited from the base Installer class, not to System.Runtime.Remoting.Contexts.Context

从您的代码中删除 System.Runtime.Remoting.Contexts.,它应该会成功编译。