Casablanca Concurrency Error

Jun 17, 2014 at 1:42 PM
Edited Jun 17, 2014 at 2:48 PM
Hello,

I have the this code:
    http_client client(LOGIN_SERVICE_URL);
    uri_builder builder(OAUTH2_CONTEXT_

    builder.append_query(L"grant_type", L"password");
    builder.append_query(L"username", username);
    builder.append_query(L"password", password);
    builder.append_query(L"scope", L"send_hybrid");

    http_request request(methods::POST);
    request.headers().add(L"Authorization", AUTH_STRING);
    request.headers().add(L"content-type", L"application/x-www-form-urlencoded");
    request.set_request_uri(builder.to_uri());

    client.request(request);
and get this unobserved exception:
cpprest120d_xp_2_1.dll!Concurrency::details::_ExceptionHolder::~_ExceptionHolder(void)  Unknown
cpprest120d_xp_2_1.dll!Concurrency::details::_ExceptionHolder::`scalar deleting destructor'(unsigned int)   Unknown
cpprest120d_xp_2_1.dll!std::_Ref_count_obj<struct Concurrency::details::_ExceptionHolder>::_Destroy(void)   Unknown
cpprest120d_xp_2_1.dll!std::_Ref_count_base::_Decref(void)  Unknown
cpprest120d_xp_2_1.dll!std::_Ptr_base<struct Concurrency::details::_ExceptionHolder>::_Decref(void) Unknown
cpprest120d_xp_2_1.dll!std::shared_ptr<struct Concurrency::details::_ExceptionHolder>::~shared_ptr<struct Concurrency::details::_ExceptionHolder>(void) Unknown
cpprest120d_xp_2_1.dll!Concurrency::details::_Task_completion_event_impl<class web::http::http_response>::~_Task_completion_event_impl<class web::http::http_response>(void)    Unknown
cpprest120d_xp_2_1.dll!Concurrency::details::_Task_completion_event_impl<class web::http::http_response>::`scalar deleting destructor'(unsigned int)    Unknown
cpprest120d_xp_2_1.dll!std::_Ref_count_obj<struct Concurrency::details::_Task_completion_event_impl<class web::http::http_response> >::_Destroy(void)   Unknown
cpprest120d_xp_2_1.dll!std::_Ref_count_base::_Decref(void)  Unknown
cpprest120d_xp_2_1.dll!std::_Ptr_base<struct Concurrency::details::_Task_completion_event_impl<class web::http::http_response> >::_Decref(void) Unknown
cpprest120d_xp_2_1.dll!std::shared_ptr<struct Concurrency::details::_Task_completion_event_impl<class web::http::http_response> >::~shared_ptr<struct Concurrency::details::_Task_completion_event_impl<class web::http::http_response> >(void) Unknown
cpprest120d_xp_2_1.dll!Concurrency::task_completion_event<class web::http::http_response>::~task_completion_event<class web::http::http_response>(void) Unknown
cpprest120d_xp_2_1.dll!web::http::client::details::request_context::~request_context(void)  Unknown
cpprest120d_xp_2_1.dll!web::http::client::details::winhttp_request_context::~winhttp_request_context(void)  Unknown
cpprest120d_xp_2_1.dll!web::http::client::details::winhttp_request_context::`vector deleting destructor'(unsigned int)  Unknown
cpprest120d_xp_2_1.dll!web::http::client::details::winhttp_request_context::finish(void)    Unknown
cpprest120d_xp_2_1.dll!web::http::client::details::request_context::report_exception(class std::exception_ptr)  Unknown
cpprest120d_xp_2_1.dll!web::http::client::details::request_context::report_exception<class web::http::http_exception>(class web::http::http_exception)  Unknown
cpprest120d_xp_2_1.dll!web::http::client::details::request_context::report_error(unsigned long,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &)    Unknown
cpprest120d_xp_2_1.dll!web::http::client::details::winhttp_client::completion_callback(void *,unsigned long,unsigned long,void *,unsigned long) Unknown
winhttp.dll!73f34b87()  Unknown
[Frames below may be incorrect and/or missing, no symbols loaded for winhttp.dll]   
[External Code] 
The lib was installed as NuGet Package.
Visual Studio 2013 v. 12.021005.1
Windows 8.1 Pro

What am I doing wrong?
Coordinator
Jun 18, 2014 at 6:26 PM
Edited Jun 18, 2014 at 6:33 PM
Hi

client.request(request); returns a task that is completed once a response from the request is received.
You will have to handle any exceptions that can be thrown from this task. Can you catch the exception and check the exception details (errorcode, errormessage etc).
I would recommend reading the article: "Exception Handling in the concurrency Runtime" to understand how to program with tasks.

Two ways of doing this:
  • Call client.request().get(); inside a try catch block
    try
    {
    client.request(request).get();
    }
    catch(const web::http::http_exception& ex) // Or catch a std::exception.
    {
        std::cout << ex.what();
    }
  • Add a task based continuation to observe all exceptions:
    client.request(request).then([](pplx::task<http_response> t)
    {
        try
        {
            t.get();
        }
        catch(const http_exception& ex)
        {
            std::cout << ex.what();
        }
    });
Thanks
Kavya.
Jun 19, 2014 at 8:46 AM
Hello Kavya,

thank you for the reply!

After installing VS2013 redistributable and running all Windows updates, the problem disappeared. Now I cannot reproduce the exception.
Perhaps my system was somehow broken, but strangely this was the only exception i got.