Wcf: dotnet-svcutil.xmlserializer Could not load file or assembly System.ServiceModel.Primitives, Version=4.5.0.1

Created on 7 Jul 2018  路  15Comments  路  Source: dotnet/wcf

I am trying to generate VMware.vSphere.Management.Serialization using dotnet-svcutil.xmlserializer to speed up serialization https://github.com/dotnet/wcf/issues/3002, but it fails with an error about not being able to load 'System.ServiceModel.Primitives, Version=4.5.0.1 if I reference the new nuget packages. Everything is building using the microsoft/dotnet:2.1-sdk docker image.

[18:46:55][Step 1/1]   Restore completed in 2.77 sec for /build/VMware.vSphere.Management.Serialization/VMware.vSphere.Management.Serialization.csproj.
[18:46:57][Step 1/1] Microsoft (R) Service Model Metadata Tool\r\n[Microsoft (R) Windows (R) Communication Foundation, Version 1.0.0-preview1]\r\nCopyright (c) Microsoft Corporation.  All rights reserved.\r\n
[18:46:57][Step 1/1] Generating XML serializers...
[18:46:57][Step 1/1] Warning: There were errors loading types in an assembly loaded from '/build/VMware.vSphere.Management/bin/release/netstandard2.0/VMware.vSphere.Management.dll' some types in the assembly could not be loaded and will not be available to the tool.
[18:46:57][Step 1/1] 
[18:46:57][Step 1/1]   Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.5.0.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
[18:46:57][Step 1/1] 
[18:46:57][Step 1/1]   Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.5.0.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
[18:46:57][Step 1/1] 
[18:46:57][Step 1/1] Error: An error occurred in the tool.

VMware.vSphere.Management.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="dotnet-svcutil" Version="1.0.1" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.*" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.*" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.*" />
    <PackageReference Include="System.ServiceModel.Security" Version="4.*" />
  </ItemGroup>
</Project>

VMware.vSphere.Management.Serialization.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="dotnet-svcutil.xmlserializer" Version="1.0.0-preview1" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\VMware.vSphere.Management\VMware.vSphere.Management.csproj" />
  </ItemGroup>
</Project>

The command failing is:

dotnet svcutil.xmlserializer $dir/VMware.vSphere.Management/bin/release/netstandard2.0/VMware.vSphere.Management.dll /out:Serialization
tooling

All 15 comments

Issue #2972 is unrelated to this problem.

@ctaggart Thank you for reporting the issue. This is likely a build issue and we need to rebuild and release a newer version of svcutil.xmlserialization. Currently as a workaround, could you try to reference the older version(4.5.0) of System.ServiceModel,Primitives to see if it works?

@yujayee, the workaround does not work. I can't reference the older System.ServiceModel,Primitives 4.5.0 if I reference the other 4.5.1 packages.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="dotnet-svcutil" Version="1.0.1" />
    <DotNetCliToolReference Include="dotnet-svcutil.xmlserializer" Version="1.0.0-preview1" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.5.1" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.5.1" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.5.1" />
    <PackageReference Include="System.ServiceModel.Security" Version="4.5.1" />
    <!-- https://github.com/dotnet/wcf/issues/3004 -->
    <PackageReference Include="System.ServiceModel.Primitives" Version="4.5.0" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="../VMware.vSphere.Management.Serialization/bin/release/netstandard2.0/VMware.vSphere.Management.Serialization.dll">
      <Pack>true</Pack>
      <PackagePath>lib/netstandard2.0</PackagePath>
    </Content>
    <Content Include="../VMware.vSphere.Management.Serialization/bin/release/netstandard2.0/VMware.vSphere.Management.Serialization.pdb">
      <Pack>true</Pack>
      <PackagePath>lib/netstandard2.0</PackagePath>
    </Content>
  </ItemGroup>
</Project>

leads to this error:

[18:49:32][Step 1/1]   Restore completed in 4.09 sec for /app/VMware.vSphere.Management/VMware.vSphere.Management.csproj.
[18:49:32][Step 1/1] /app/VMware.vSphere.Management/VMware.vSphere.Management.csproj : error NU1605: Detected package downgrade: System.ServiceModel.Primitives from 4.5.1 to 4.5.0. Reference the package directly from the project to select a different version. 
[18:49:32][Step 1/1] /app/VMware.vSphere.Management/VMware.vSphere.Management.csproj : error NU1605:  VMware.vSphere.Management -> System.ServiceModel.Security 4.5.1 -> System.ServiceModel.Primitives (>= 4.5.1) 
[18:49:32][Step 1/1] /app/VMware.vSphere.Management/VMware.vSphere.Management.csproj : error NU1605:  VMware.vSphere.Management -> System.ServiceModel.Primitives (>= 4.5.0)
[18:49:32][Step 1/1] /app/VMware.vSphere.Management/VMware.vSphere.Management.csproj : error NU1605: Detected package downgrade: System.ServiceModel.Primitives from 4.5.1 to 4.5.0. Reference the package directly from the project to select a different version. 
[18:49:32][Step 1/1] /app/VMware.vSphere.Management/VMware.vSphere.Management.csproj : error NU1605:  VMware.vSphere.Management -> System.ServiceModel.Duplex 4.5.1 -> System.ServiceModel.Primitives (>= 4.5.1) 
[18:49:32][Step 1/1] /app/VMware.vSphere.Management/VMware.vSphere.Management.csproj : error NU1605:  VMware.vSphere.Management -> System.ServiceModel.Primitives (>= 4.5.0)
[18:49:32][Step 1/1] /app/VMware.vSphere.Management/VMware.vSphere.Management.csproj : error NU1605: Detected package downgrade: System.ServiceModel.Primitives from 4.5.1 to 4.5.0. Reference the package directly from the project to select a different version. 
[18:49:32][Step 1/1] /app/VMware.vSphere.Management/VMware.vSphere.Management.csproj : error NU1605:  VMware.vSphere.Management -> System.ServiceModel.NetTcp 4.5.1 -> System.ServiceModel.Primitives (>= 4.5.1) 
[18:49:32][Step 1/1] /app/VMware.vSphere.Management/VMware.vSphere.Management.csproj : error NU1605:  VMware.vSphere.Management -> System.ServiceModel.Primitives (>= 4.5.0)
[18:49:32][Step 1/1] /app/VMware.vSphere.Management/VMware.vSphere.Management.csproj : error NU1605: Detected package downgrade: System.ServiceModel.Primitives from 4.5.1 to 4.5.0. Reference the package directly from the project to select a different version. 
[18:49:32][Step 1/1] /app/VMware.vSphere.Management/VMware.vSphere.Management.csproj : error NU1605:  VMware.vSphere.Management -> System.ServiceModel.Http 4.5.1 -> System.ServiceModel.Primitives (>= 4.5.1) 
[18:49:32][Step 1/1] /app/VMware.vSphere.Management/VMware.vSphere.Management.csproj : error NU1605:  VMware.vSphere.Management -> System.ServiceModel.Primitives (>= 4.5.0)
[18:49:32][Step 1/1]   Generating MSBuild file /app/VMware.vSphere.Management/obj/VMware.vSphere.Management.csproj.nuget.g.props.
[18:49:32][Step 1/1]   Generating MSBuild file /app/VMware.vSphere.Management/obj/VMware.vSphere.Management.csproj.nuget.g.targets.
[18:49:32][Step 1/1]   Restore failed in 4.18 sec for /app/VMware.vSphere.Management/VMware.vSphere.Management.csproj.

I feels like a problem with dotnet-svcutil.xmlserializer tool. When I switch to the new 4.5.2 nuget packages, I get the error:

[19:19:16][Step 1/1] Microsoft (R) Service Model Metadata Tool\r\n[Microsoft (R) Windows (R) Communication Foundation, Version 1.0.0-preview1]\r\nCopyright (c) Microsoft Corporation.  All rights reserved.\r\n
[19:19:16][Step 1/1] Generating XML serializers...
[19:19:16][Step 1/1] Warning: There were errors loading types in an assembly loaded from '/app/VMware.vSphere.Management/bin/release/netstandard2.0/VMware.vSphere.Management.dll' some types in the assembly could not be loaded and will not be available to the tool.
[19:19:16][Step 1/1] 
[19:19:16][Step 1/1]   Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.5.0.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
[19:19:16][Step 1/1] 
[19:19:16][Step 1/1]   Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.5.0.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
[19:19:16][Step 1/1] 
[19:19:16][Step 1/1] Error: An error occurred in the tool.
[19:19:16][Step 1/1] 
[19:19:16][Step 1/1] Error: Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.5.0.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
[19:19:16][Step 1/1] 
[19:19:16][Step 1/1] 
[19:19:19][Step 1/1] Process exited with code 9

Or may be it requires a publish with all the required assemblies in the same folder. Checking...

@ctaggart Thanks for the feedback. We will look into it.

I tried to a bunch of ways to see if I could get the assemblies to load that it was complaining about. I started by turning on $env:COREHOST_TRACE=1, then I tried to see if I could use--aditional-deps to workaround the issue, but I simply ran into another issue about not being to load System.Private.ServiceModel https://github.com/dotnet/wcf/issues/2824 馃槥

PS C:\Users\taggac\coreservices\vsphere-automation-sdk-.net\VMware.vSphere.Management> dotnet --additional-deps C:\Users\taggac\coreservices\vsphere-automation-sdk-.net\VMware.vSphere.Management\bin\release\netstandard2.0\publish
\VMware.vSphere.Management.json C:\Users\taggac\.nuget\packages\dotnet-svcutil.xmlserializer\1.0.0-preview1\lib\netcoreapp2.1\dotnet-svcutil.xmlserializer.dll C:\Users\taggac\coreservices\vsphere-automation-sdk-.net\VMware.vSpher
e.Management\bin\release\netstandard2.0\publish\VMware.vSphere.Management.dll /out:C:\Users\taggac\coreservices\vsphere-automation-sdk-.net\VMware.vSphere.Management.Serialization/Serialization
Error: An error occurred in the tool.

Error: Could not load file or assembly 'System.Private.ServiceModel, Version=4.5.0.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

May or may not be helpful:

@ctaggart Looks like svcutil.xmlserializer is forcing older version of the assemblies. Could you please give it another try to reference all assemblies in your project to version 4.5.0?

  <ItemGroup>
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.5.0" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.5.0" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.5.0" />
    <PackageReference Include="System.ServiceModel.Security" Version="4.5.0" />
    <!-- https://github.com/dotnet/wcf/issues/3004 -->
    <PackageReference Include="System.ServiceModel.Primitives" Version="4.5.0" />
  </ItemGroup>

Yes, that worked!

The working build file:

#!/bin/bash -ex
# run this in the microsoft:dotnet:2.1-sdk docker to build
dir=$PWD

cd $dir/VMware.vSphere.Management
dotnet restore
dotnet svcutil ../wsdl/vim-service/vimService.wsdl -n "*,VMware.vSphere.Management"
dotnet build -c release /p:Version=$VERSION /v:m /p:ContinuousIntegrationBuild=true

cd $dir/VMware.vSphere.Management.Serialization
dotnet restore
dotnet svcutil.xmlserializer $dir/VMware.vSphere.Management/bin/release/netstandard2.0/VMware.vSphere.Management.dll /out:$PWD/Serialization
dotnet build --no-dependencies -c release /p:Version=$VERSION /v:m /p:ContinuousIntegrationBuild=true

cd $dir/VMware.vSphere.Management
dotnet pack --no-build -c release -o ../bin /p:Version=$VERSION /v:m

cd $dir
dotnet nuget push bin/VMware.vSphere.Management.$VERSION.nupkg

I forced the upgrade to 4.5.2 in my downstream project, so that now I have:

image

It would be nice there was a version that was compatible with the latest.

Reopen this issue. Although the workaround currently works, svcutil.xmlserialization tool still needs fix.

Will build a new version of tool.

@ctaggart We just build a new one and published on myget. Could you try it?
https://dotnet.myget.org/feed/dotnet-core/package/nuget/dotnet-svcutil.xmlserializer/1.0.0-Preview2

I can verify next week sometime. Have a great weekend!

Closing this issue. Please feel free to reopen it if the problem still exists.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IGx89 picture IGx89  路  6Comments

weitzhandler picture weitzhandler  路  6Comments

DotNetPart picture DotNetPart  路  6Comments

mconnew picture mconnew  路  6Comments

Petermarcu picture Petermarcu  路  4Comments