title: Failed to allocate a managed memory buffer of 268435456 bytes. The amount of available memory may be low
body: <p>I am trying to save some big data to database through a WCF service call. I am not able to invoke the service. Its throwing an error:</p>
  
  <p><strong>Failed to allocate a managed memory buffer of 268435456 bytes. The amount of available memory may be low</strong></p>
  
  <pre><code>public async Task&lt;int&gt; UploadExportPackage(DTO.Upload.UploadPackage package)
  {
      int result = await serviceProxy.UploadResultsAsync(package);
      return result;
  }
  </code></pre>
  
  <p>Server side config:</p>
  
  <p>
        </p>
  
  <pre><code>    &lt;!-- 
        Place limits on the amount of data that can be received in one go.
        This helps to protect the server from attack and abuse.
      --&gt;
      &lt;binding name="primaryBinding"
               maxReceivedMessageSize="6000000"
               maxBufferSize="6000000"
               maxBufferPoolSize="12000000"&gt;
  
        &lt;readerQuotas maxArrayLength="6000000"
                      maxStringContentLength="6000000" /&gt;
  
        &lt;!--
            Set the security mode. Apply at:
              - Transport layer
              - Message layer
        --&gt;
        &lt;security mode="TransportWithMessageCredential"&gt;
          &lt;message clientCredentialType="UserName" /&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/basicHttpsBinding&gt;
  &lt;/bindings&gt;
  </code></pre>
  
  <p>Stack trace:</p>
  
  <pre><code>Exception no: 0 
  </code></pre>
  
  <p>Next Exception:
  Message:</p>
  
  <p>Failed to allocate a managed memory buffer of 268435456 bytes. The amount of available memory may be low.</p>
  
  <p>Stack trace:
  Server stack trace: 
     at System.Runtime.Fx.AllocateByteArray(Int32 size)
     at System.Runtime.InternalBufferManager.PooledBufferManager.TakeBuffer(Int32 bufferSize)
     at System.ServiceModel.Channels.BufferManagerOutputStream.Init(Int32 initialSize, Int32 maxSizeQuota, Int32 effectiveMaxSize, BufferManager bufferManager)
     at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)
     at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
     at System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message message, Boolean shouldRecycleBuffer)
     at System.ServiceModel.Channels.HttpOutput.SendAsyncResult.SendWithoutChannelBindingToken()
     at System.ServiceModel.Channels.HttpOutput.SendAsyncResult.Send()
     at System.ServiceModel.Channels.HttpOutput.SendAsyncResult..ctor(HttpOutput httpOutput, HttpResponseMessage httpResponseMessage, Boolean suppressEntityBody, TimeSpan timeout, AsyncCallback callback, Object state)
     at System.ServiceModel.Channels.HttpOutput.BeginSendCore(HttpResponseMessage httpResponseMessage, TimeSpan timeout, AsyncCallback callback, Object state)
     at System.ServiceModel.Channels.HttpChannelFactory<code>1.HttpRequestChannel.HttpChannelAsyncRequest.SendWebRequest()
     at System.ServiceModel.Channels.HttpChannelFactory</code>1.HttpRequestChannel.HttpChannelAsyncRequest.BeginSendRequest(Message message, TimeSpan timeout)
     at System.ServiceModel.Channels.RequestChannel.BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, Object state)
     at System.ServiceModel.Channels.SecurityChannelFactory<code>1.RequestChannelSendAsyncResult.BeginSendCore(IRequestChannel channel, Message message, TimeSpan timeout, AsyncCallback callback, Object state)
     at System.ServiceModel.Security.ApplySecurityAndSendAsyncResult</code>1.OnSecureOutgoingMessageComplete(Message message)
     at System.ServiceModel.Security.ApplySecurityAndSendAsyncResult<code>1.Begin(Message message, SecurityProtocolCorrelationState correlationState)
     at System.ServiceModel.Channels.SecurityChannelFactory</code>1.SecurityRequestChannel.BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, Object state)
     at System.ServiceModel.Dispatcher.RequestChannelBinder.BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, Object state)
     at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartSend(Boolean completedSynchronously)
     at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.FinishEnsureOpen(IAsyncResult result, Boolean completedSynchronously)
     at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartEnsureOpen(Boolean completedSynchronously)
     at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.FinishEnsureInteractiveInit(IAsyncResult result, Boolean completedSynchronously)
     at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartEnsureInteractiveInit()
     at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.Begin()
     at System.ServiceModel.Channels.ServiceChannel.BeginCall(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, TimeSpan timeout, AsyncCallback callback, Object asyncState)
     at System.ServiceModel.Channels.ServiceChannel.BeginCall(ServiceChannel channel, ProxyOperationRuntime operation, Object[] ins, AsyncCallback callback, Object asyncState)
     at System.Threading.Tasks.TaskFactory<code>1.FromAsyncImpl[TArg1,TArg2,TArg3](Func</code>6 beginMethod, Func<code>2 endFunction, Action</code>1 endAction, TArg1 arg1, TArg2 arg2, TArg3 arg3, Object state, TaskCreationOptions creationOptions)
     at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.CreateGenericTask[T](ServiceChannel channel, ProxyOperationRuntime operation, Object[] inputParameters)
     at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.CreateGenericTask(ServiceChannel channel, ProxyOperationRuntime operation, Object[] inputParameters)
     at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.CreateTask(ServiceChannel channel, IMethodCallMessage methodCall, ProxyOperationRuntime operation)
     at System.ServiceModel.Channels.ServiceChannelProxy.InvokeTaskService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
     at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)</p>
  
  <p>Exception rethrown at [0]: 
     at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
     at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)
     at RossendaleClient8.DAL.RR.IRossendaleService.UploadResultsAsync(UploadPackage package)
     at RossendaleClient8.DAL.RR.RossendaleServiceClient.UploadResultsAsync(UploadPackage package)
     at RossendaleClient8.DAL.RossendaleServiceClient.d__13.MoveNext()</p>
  
  <p>Next Exception:
  Message:</p>
  
  <p>Exception of type 'System.OutOfMemoryException' was thrown.</p>
  
  <p>Stack trace:   at System.Runtime.Fx.AllocateByteArray(Int32 size)</p>