从DLL动态加载时,Magento.RestApi的行为会有所不同

时间:2018-05-19 19:44:49

标签: c# rest magento async-await

我在一个更大的系统中使用Magento.RestApi,我从DLL动态加载代码。

当我在独立项目中使用以下代码时,它可以正常工作:

private async void dostuff() {
    var client = new MagentoApi()
            .Initialize("<url>", "key", "secret")
            .AuthenticateAdmin("user", "pass");

    var response = await client.GetProductBySku("sku");

    // The response contains the result or errors
    if (!response.HasErrors) {
        var product = response.Result;
        ... do stuff with the result ...
    }
}

但是,当加载到较大的项目中时,我得到&#34;请求未成功完成。&#34;,当尝试捕获错误以找到InnerException或堆栈跟踪时,调试器似乎不再起作用了。打印出堆栈跟踪给了我:

   at Magento.RestApi.MagentoApi.<HandleResponse>d__35`1.MoveNext() in C:\Users\bart\Documents\Visual Studio 2015\Projects\SapphireMagentoDriver\SapphireMagentoDriver\MagentoApi.cs:line 445
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Magento.RestApi.MagentoApi.<Execute>d__34`1.MoveNext() in C:\Users\bart\Documents\Visual Studio 2015\Projects\SapphireMagentoDriver\SapphireMagentoDriver\MagentoApi.cs:line 410
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Magento.RestApi.MagentoApi.<GetProductBySku>d__45.MoveNext() in C:\Users\bart\Documents\Visual Studio 2015\Projects\SapphireMagentoDriver\SapphireMagentoDriver\MagentoApi.cs:line 708
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Magento.RestApi.SapphireMagentoDriver.<DoDownloadArticles>d__6.MoveNext() in C:\Users\bart\Documents\Visual Studio 2015\Projects\SapphireMagentoDriver\SapphireMagentoDriver\DriverInterface.cs:line 103

我必须从源代码编译Magento.RestApi,因为NuGet包使用的是与我的大项目不同的NewtonSoft.Json包。这在独立版本中工作正常。

0 个答案:

没有答案
相关问题