0

我有这段代码在它自己的应用程序中工作。但是,如果我在最终要进入的项目中运行此代码,则会出现异常。这是相同的堆栈跟踪。

发生未处理的异常,进程终止。

申请编号:28507bb0

进程 ID:14936

异常:System.NullReferenceException

消息:对象引用未设置为对象的实例。

StackTrace:在 System.Web.ThreadContext.AssociateWithCurrentThread(Boolean setImpersonationContext) 在 System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext) 在 System.Web.LegacyAspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback 回调,对象状态) 在 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& currentTask) --- 在 System.Threading.Tasks 处从先前引发异常的位置结束堆栈跟踪。System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext) 的 AwaitTaskContinuation.b__1(Object s) executionContext、ContextCallback 回调、对象状态、布尔值 preserveSyncCtx) 在 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 在 System.Threading.ThreadPoolWorkQueue.Dispatch() 在 System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 处 System.Threading.QueueUserWorkItemCallback.System.Threading.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 处的 ContextCallback 回调,对象状态,布尔型 preserveSyncCtx) .ThreadPoolWorkQueue.Dispatch() 在 System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 处 System.Threading.QueueUserWorkItemCallback.System.Threading.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 处的 ContextCallback 回调,对象状态,布尔型 preserveSyncCtx) .ThreadPoolWorkQueue.Dispatch() 在 System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

旧应用程序是 .net 4.0,我已在 VS 2012 中打开它,并将该解决方案中的每个项目升级到 4.5。什么都没有改变这个错误。

任何想法为什么代码自己工作但在其他应用程序中抛出这个堆栈跟踪?

    private async Task<IList<InventoryItem>> GetPartsInfoAsync(string SearchText)
    {
        HttpClient client = new HttpClient();
        IList<InventoryItem> partList = new List<InventoryItem>();
        string address = ConfigurationManager.AppSettings["BaseUrl"] + ConfigurationManager.AppSettings["PartsSearch"] + "?login=" + ConfigurationManager.AppSettings["Login"] + "&apikey=" + ConfigurationManager.AppSettings["apiKey"] + "&search_token=" + SearchText + "&useExact=true";

        try
        {
            HttpResponseMessage responseMessage = await client.GetAsync(address); 
            responseMessage.EnsureSuccessStatusCode();
            //client.Timeout = System.TimeSpan.FromMilliseconds(50);

            Parts.RootObject ArrowPartData = JsonConvert.DeserializeObject<Parts.RootObject>(await responseMessage.Content.ReadAsStringAsync());

            if (ArrowPartData != null)
            {

            }
        }
        catch (HttpRequestException requestException)
        {
                        throw requestException;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return partList;
    }
4

0 回答 0