【问题标题】:System.ServiceModel with .NET 2.0 on Windows 7 and Windows Server 2008 R2在 Windows 7 和 Windows Server 2008 R2 上使用 .NET 2.0 的 System.ServiceModel
【发布时间】:2018-03-07 15:04:20
【问题描述】:

.NET Framework 2.0 中使用 System.ServiceModel 的项目不能在 Windows 7 机器上编译,但可以在 Windows Server 2008 R2 机器上编译。你能解释一下原因吗?

工程文件Test1.vbproj:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <PropertyGroup>
    <OutputType>Library</OutputType>
    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
    <OutputPath>bin\Debug</OutputPath>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="IService1.vb" />
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" />
</Project>

IService1.vb:

Imports System.ServiceModel
<ServiceContract()> Public Interface IService1
    <OperationContract()> Function Function1() As String
End Interface

在 Windows 7 32 位机器上,此项目无法编译,显示错误消息:

类型“OperationContract”未定义。
未定义类型“ServiceContract”。

在 Windows Server 2008 R2 64 位机器上,此项目编译成功。

在 Windows 7 机器上打开的项目:

在 Windows Server 2008 R2 机器上打开的项目:

安装在 Windows 7 机器上的 .NET 框架:

安装在 Windows Server 2008 R2 机器上的 .NET 框架:

Windows 7 机器上的 Windows 功能:

Windows Server 2008 R2 机器上的 Windows 功能:

Windows 7 机器属性:

Windows Server 2008 R2 机器属性:

有人有什么想法,为什么它不在Windows 7机器上编译,而是在Windows Server 2008 R2机器上编译?

我必须在 Windows 7 机器上编译它,而不更改代码或项目文件。因此,我必须在 Windows 7 机器上安装或配置一些东西。

【问题讨论】:

  • 您是否在可选功能下安装了.net 3.5 sp1?
  • 是的,两台机器上都安装了 .NET 3.5。我在问题中添加了相关的 Windows 功能屏幕截图。

标签: wcf windows-7 .net-2.0 windows-server-2008-r2


【解决方案1】:

在 Windows 注册表中,我指示 .NET Framework 2.0 也在 .NET Framework 3.0 文件夹中查找程序集。我将以下代码放入名为 DotNET3.0Compatiblity.reg 的文件中:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v2.0.50727\AssemblyFoldersEx\.NET 3.0 Compatiblity]
@="C:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\v3.0"

我双击该文件,并创建了所需的注册表项。 您可以在下图中看到,System.ServiceModel.dll 现在位于文件夹C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.ServiceModel.dll 中。

【讨论】:

    猜你喜欢
    • 2014-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-29
    • 2012-06-05
    • 1970-01-01
    相关资源
    最近更新 更多