Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling external webapi causes nullreference exception. This code works if its in project by itself
    primarykey
    data
    text
    <p>I have this code working in its own application. But if I run this code in the project that is going to finally end up in, I get an exception. Here is the stacktrace for the same.</p> <p>An unhandled exception occurred and the process was terminated.</p> <p>Application ID: 28507bb0</p> <p>Process ID: 14936</p> <p>Exception: System.NullReferenceException</p> <p>Message: Object reference not set to an instance of an object.</p> <p>StackTrace: at System.Web.ThreadContext.AssociateWithCurrentThread(Boolean setImpersonationContext) at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext) at System.Web.LegacyAspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state) at System.Web.LegacyAspNetSynchronizationContext.CallCallback(SendOrPostCallback callback, Object state) at System.Web.LegacyAspNetSynchronizationContext.Post(SendOrPostCallback callback, Object state) at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.PostAction(Object state) at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(ContextCallback callback, Object state, Task&amp; currentTask) --- End of stack trace from previous location where exception was thrown --- at System.Threading.Tasks.AwaitTaskContinuation.b__1(Object s) at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()</p> <p>The old app was .net 4.0 and I have opened it in VS 2012 and upgraded each of the project in that solution to 4.5. Nothing has changed that error.</p> <p>Any ideas why the code works on its own but throws this stacktrace in the other application?</p> <pre><code> private async Task&lt;IList&lt;InventoryItem&gt;&gt; GetPartsInfoAsync(string SearchText) { HttpClient client = new HttpClient(); IList&lt;InventoryItem&gt; partList = new List&lt;InventoryItem&gt;(); string address = ConfigurationManager.AppSettings["BaseUrl"] + ConfigurationManager.AppSettings["PartsSearch"] + "?login=" + ConfigurationManager.AppSettings["Login"] + "&amp;apikey=" + ConfigurationManager.AppSettings["apiKey"] + "&amp;search_token=" + SearchText + "&amp;useExact=true"; try { HttpResponseMessage responseMessage = await client.GetAsync(address); responseMessage.EnsureSuccessStatusCode(); //client.Timeout = System.TimeSpan.FromMilliseconds(50); Parts.RootObject ArrowPartData = JsonConvert.DeserializeObject&lt;Parts.RootObject&gt;(await responseMessage.Content.ReadAsStringAsync()); if (ArrowPartData != null) { } } catch (HttpRequestException requestException) { throw requestException; } catch (Exception ex) { throw ex; } return partList; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload