PackageServer.PushPackage throws WebException: The underlying connection was closed

Topics: Ecosystem
Apr 24, 2013 at 1:04 PM
Hello, I try to pragmatically create and push a NuGet package.
For this I create a PackageBuilder instance, adding my Files and Populate my ManifestMetadata.
When saving the stream as a nupkg file to disk and open it with 7zip everything looks fine.

Now I'am trying to push my package to nuget.org using this method:
public void UploadPackage(PackageBuilder package, string apiKey)
{
    var packageServer = new PackageServer("https://www.nuget.org", "NuGet Command Line");
    using (var stream = new MemoryStream())
    {
        package.Save(stream);
        packageServer.PushPackage(apiKey, () => stream, 60000);
    }
}
When calling with my package it throws this exception:
System.Net.WebException was unhandled by user code
  HResult=-2146233079
  Message=The underlying connection was closed: An unexpected error occurred on a receive.
  Source=System
  StackTrace:
       at System.Net.HttpWebRequest.GetResponse()
       at NuGet.RequestHelper.GetResponse(Func`1 createRequest, Action`1 prepareRequest, IProxyCache proxyCache, ICredentialCache credentialCache, ICredentialProvider credentialProvider)
       at NuGet.HttpClient.GetResponse()
       at NuGet.PackageServer.EnsureSuccessfulResponse(HttpClient client, HttpStatusCode expectedStatusCode)
       at NuGet.PackageServer.PushPackage(String apiKey, Func`1 packageStreamFactory, Int32 timeout)
       at NuGetPackageCreator.UploadPackage(PackageBuilder package, String apiKey) in c:\code\DeploymentPacker\NuGetPackageCreator.cs:line 47
  InnerException: System.IO.IOException
       HResult=-2146232800
       Message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
       Source=System
       StackTrace:
            at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
            at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
            at System.Net.Security._SslStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
            at System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
            at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
            at System.Net.Security._SslStream.Read(Byte[] buffer, Int32 offset, Int32 count)
            at System.Net.TlsStream.Read(Byte[] buffer, Int32 offset, Int32 size)
            at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
            at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
       InnerException: System.Net.Sockets.SocketException
            HResult=-2147467259
            Message=An existing connection was forcibly closed by the remote host
            Source=System
            ErrorCode=10054
            NativeErrorCode=10054
            StackTrace:
                 at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
                 at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
            InnerException:
Whats going wrong here?
May 21, 2013 at 3:50 PM
Same problem here, any solution?