0
votes

This exception is being thrown, and I apparently have no way to catch it:

No connection could be made because the target machine actively refused it 127.0.0.1:10000

Source:

Line 102:            try
Line 103:            {
Line 104:                var blobClient = GetClient();  <-- throws here
Line 105:                var container = blobClient.GetContainerReference(containerName);
Line 106:                container.CreateIfNotExists(BlobContainerPublicAccessType.Blob);

Source File: ...Blob.cs Line: 104

The entire function:

private static CloudBlobContainer GetContainer(string containerName)
{
    try
    {
        var blobClient = GetClient();
        var container = blobClient.GetContainerReference(containerName);
        container.CreateIfNotExists(BlobContainerPublicAccessType.Blob);
        return container;
    }
    catch (HttpException ex)
    {
        Helpers.Error.Functions.RecordError(ex);
        throw new HttpException(500, "Could not connect.");
    }
}

The GetClient() function:

private static CloudBlobClient GetClient()
{
    try
    {
        var account = CloudStorageAccount.Parse(Settings.Deployment.AzureConnectionString);
        return account.CreateCloudBlobClient();
    }
    catch (Exception ex)
    {
        Helpers.Error.Functions.RecordError(ex);
        throw new HttpException(500, "Could not connect GetClient.");
    }
}

Stack trace:

[SocketException (0x274d): No connection could be made because the target machine actively refused it 127.0.0.1:10000]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +520
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +621

[WebException: Unable to connect to the remote server]
System.Net.HttpWebRequest.GetResponse() +1724
Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync(RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:699

[StorageException: Unable to connect to the remote server]
Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync(RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:604 Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.CreateIfNotExists(BlobContainerPublicAccessType accessType, BlobRequestOptions requestOptions, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlobContainer.cs:233 C3.Code.Controls.Application.Storage.Blob.Blob.GetContainer(String containerName) in ...Blob.cs:104
C3.Code.Controls.Application.Storage.Blob.Blob.AddBlob(String containerName, String blobReference, Byte[] bytes) in D:\Dropbox (Scirra Ltd)\Tom\C3 Website\C3Alpha2\Code\Controls\Application\Storage\Blob\Blob.cs:87
C3.Code.Callbacks.Application.ApplicationStart() in D:\Dropbox (Scirra Ltd)\Tom\C3 Website\C3Alpha2\Code\Callbacks\Application.cs:26
C3.Global.Application_Start(Object sender, EventArgs e) in D:\Dropbox (Scirra Ltd)\Tom\C3 Website\C3Alpha2\Global.asax.cs:30

[HttpException (0x80004005): Unable to connect to the remote server]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +534
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +186
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +175
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +424
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +360

[HttpException (0x80004005): Unable to connect to the remote server]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +539
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +118 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +730

1
this is probably the behavior while you debugging in VS, there is settings of exceptions in VS, you need to tweak thatEhsan Sajjad
I'm a bit confused you deleted the old question instead of editing it.Mighty Badaboom
You're only trying to catch a HttpException, everything else will not get caught. You exception is actually a SocketException I think.DavidG
have you tried catching a WebException?Wheels73
Sorry @Mighty, thought I'd solved it so didn't want to waste anyone's time. Turned out I didn't solve it.Tom Gullen

1 Answers

2
votes

From the exception message you posted:

[SocketException (0x274d): No connection could be made because the target machine actively refused it 127.0.0.1:10000]

Note that this is a SocketException, not an HttpException but your code says this:

catch (HttpException ex)

So it's not being caught. Either use a generic Exception to catch everything, or switch to catching SocketException.