Out of memory exception in C# WCF service

  • Thread starter Thread starter ANi2000
  • Start date Start date
A

ANi2000

Guest
Ive a C# wcf service in which my GetProducts() method has code as per below.

using (var client = CreateHttpClient("/myURL", string.Empty))
{
HttpResponseMessage response = client.GetAsync(client.BaseAddress.AbsolutePath).Result;

if (response.IsSuccessStatusCode)
{
var products= response.Content.ReadAsAsync<List<Product>>().Result;
lstProducts.AddRange(products);
}
else
{
throw new Exception("Error fetching products...");
}
}

Theres another method A() in this service that calls this method and it throws following out of memory exception:

System.AggregateException: One or more errors occurred. ---> System.OutOfMemoryException: Exception of type System.OutOfMemoryException was thrown.
at System.Threading.Thread.StartInternal(IPrincipal principal, StackCrawlMark& stackMark)
at System.Threading.Thread.Start(StackCrawlMark& stackMark)
at System.Threading.Thread.Start()
at System.Net.TimerThread.Prod()
at System.Net.TimerThread.TimerQueue.CreateTimer(Callback callback, Object context)
at System.Net.ServicePoint..ctor(Uri address, Queue defaultIdlingQueue, Int32 defaultConnectionLimit, String lookupString, Boolean userChangedLimit, Boolean proxyServicePoint)
at System.Net.ServicePointManager.FindServicePointHelper(Uri address, Boolean isProxyServicePoint)
at System.Net.ServicePointManager.FindServicePoint(Uri address, IWebProxy proxy, ProxyChain& chain, HttpAbortDelegate& abortDelegate, Int32& abortState)
at System.Net.HttpWebRequest.FindServicePoint(Boolean forceFind)
at System.Net.HttpWebRequest.BeginGetResponse(AsyncCallback callback, Object state)
at System.Net.Http.HttpClientHandler.StartGettingResponse(RequestState state)
at System.Net.Http.HttpClientHandler.StartRequest(Object obj)
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
MyService.ProductsManager.GetProducts()
--> (Inner Exception #0) System.OutOfMemoryException: Exception of type System.OutOfMemoryException was thrown.
at System.Threading.Thread.StartInternal(IPrincipal principal, StackCrawlMark& stackMark)
at System.Threading.Thread.Start(StackCrawlMark& stackMark)
at System.Threading.Thread.Start()
at System.Net.TimerThread.Prod()
at System.Net.TimerThread.TimerQueue.CreateTimer(Callback callback, Object context)
at System.Net.ServicePoint..ctor(Uri address, Queue defaultIdlingQueue, Int32 defaultConnectionLimit, String lookupString, Boolean userChangedLimit, Boolean proxyServicePoint)
at System.Net.ServicePointManager.FindServicePointHelper(Uri address, Boolean isProxyServicePoint)
at System.Net.ServicePointManager.FindServicePoint(Uri address, IWebProxy proxy, ProxyChain& chain, HttpAbortDelegate& abortDelegate, Int32& abortState)
at System.Net.HttpWebRequest.FindServicePoint(Boolean forceFind)
at System.Net.HttpWebRequest.BeginGetResponse(AsyncCallback callback, Object state)
at System.Net.Http.HttpClientHandler.StartGettingResponse(RequestState state)
at System.Net.Http.HttpClientHandler.StartRequest(Object obj)<---

Im already using the "using" block in GetProducts() method.So just wondering what else I could do in my code to prevent this out of memory exception?
Or could it be that there is a memory leak at the "myURL" service side?

Or would following help?
1.Change the build platform target to x64.
2.Add following in the service config file?

<runtime>
<gcAllowVeryLargeObjects enabled="true" />
</runtime>

Please advise.

Thanks for your help.

Continue reading...
 
Back
Top