Runtime Exception

Feb 10, 2015 at 6:38 PM
I'm working on a MediaFoundation plugin. It uses WRL and will be targeting Windows 8.1 and Windows Phone 8.1. Whenever I execute client.request I get a runtime exception.

Code:
web::http::http_request req;
web::http::client::http_client client(L"http://www.google.com");
req.set_method(web::http::methods::GET);

client.request(req).then([](web::http::http_response response)
{
});
Call Stack:
cpprest120d_app_2_4.dll!505fb44c() Unknown
[Frames below may be incorrect and/or missing, no symbols loaded for cpprest120d_app_2_4.dll]   
05cbdedc()  Unknown
cpprest120d_app_2_4.dll!508bd686()  Unknown
cpprest120d_app_2_4.dll!505c7ebf()  Unknown
cpprest120d_app_2_4.dll!505eff3c()  Unknown
cpprest120d_app_2_4.dll!50598bf2()  Unknown
cpprest120d_app_2_4.dll!50609a8e()  Unknown
cpprest120d_app_2_4.dll!505f2b00()  Unknown
cpprest120d_app_2_4.dll!505fafb1()  Unknown
cpprest120d_app_2_4.dll!5061d46b()  Unknown
cpprest120d_app_2_4.dll!5061dbd6()  Unknown
cpprest120d_app_2_4.dll!508c065e()  Unknown
cpprest120d_app_2_4.dll!507af2ed()  Unknown
msxml6.dll!URLMONRequest::_CallOnHeadersAvailable() Line 341    C++
msxml6.dll!URLMONRequest::_OnResponse(unsigned long dwResponseCode, const wchar_t * pwszResponseHeaders, const wchar_t * pwszRequestHeaders) Line 3761  C++
msxml6.dll!URLMONRequest::OnResponse(unsigned long dwResponseCode, const wchar_t * pwszResponseHeaders, const wchar_t * pwszRequestHeaders, wchar_t * * ppwszAdditionalRequestHeaders) Line 3813    C++
msxml6.dll!URLMONRequest::URLMONRequestSink::OnResponse(unsigned long dwResponseCode, const wchar_t * szResponseHeaders, const wchar_t * szRequestHeaders, wchar_t * * pszAdditionalRequestHeaders) Line 251    C++
urlmon.dll!CINetHttp::QueryStatusOnResponseDefault(unsigned long dwStat) Line 2343  C++
urlmon.dll!CINetHttp::QueryStatusOnResponse() Line 2122 C++
urlmon.dll!CINet::QueryInfoOnResponse() Line 6469   C++
urlmon.dll!CINet::INetQueryInfo() Line 4243 C++
urlmon.dll!CINet::OnINetInternal(unsigned long dwState) Line 5705   C++
urlmon.dll!CINet::Continue(_tagPROTOCOLDATA * pStateInfoIn) Line 1442   C++
urlmon.dll!CINet::TransitState(unsigned long dwState, int fAsync) Line 5609 C++
urlmon.dll!CINet::OnINetSendRequest(unsigned long dwResult, bool fReadPendingCallback) Line 4153    C++
urlmon.dll!CINet::CINetCallback(void * hInternet, unsigned long dwContext, unsigned long dwStatus, void * pvInfo, unsigned long dwStatusLen) Line 5273  C++
wininet.dll!InternetIndicateStatus()    Unknown
wininet.dll!CFsm::RunWorkItem() Unknown
wininet.dll!ICSocket::ReceiveCompletion()   Unknown
wininet.dll!CWxSocket::IoCompletionCallback()   Unknown
kernel32.dll!_BasepTpIoCallback@20()   Unknown
ntdll.dll!TppIopExecuteCallback()   Unknown
ntdll.dll!TppWorkerThread() Unknown
kernel32.dll!@BaseThreadInitThunk@12() Unknown
ntdll.dll!__RtlUserThreadStart()    Unknown
ntdll.dll!__RtlUserThreadStart@8() Unknown

Error Log:

First-chance exception at 0x505FB44C (cpprest120d_app_2_4.dll) in UniversalPlayer.Windows.exe: 0xC0000005: Access violation reading location 0xCDCD00CD.
Unhandled exception at 0x505FB44C (cpprest120d_app_2_4.dll) in UniversalPlayer.Windows.exe: 0xC0000005: Access violation reading location 0xCDCD00CD.


Any recommendations? I've tried to simplify the code as much as i can and get the same exception every time. When monitoring web traffic i see that the URL does download completely.
Feb 11, 2015 at 10:16 PM
more Updates:

Here is the full stack trace when referencing a locally compiled version of cpprest.
cpprest120d_app_2_4.dll!Concurrency::details::_ContextCallback::_CallInContext(std::function<void __cdecl(void)> _Func) Line 656 C++
cpprest120d_app_2_4.dll!Concurrency::details::_Task_impl_base::_ScheduleContinuationTask::__l18::<lambda>() Line 2033   C++
cpprest120d_app_2_4.dll!std::_Callable_obj<void <lambda>(void),0>::_ApplyX<void>() Line 284 C++
cpprest120d_app_2_4.dll!std::_Func_impl<std::_Callable_obj<void <lambda>(void),0>,std::allocator<std::_Func_class<void> >,void>::_Do_call() Line 229    C++
cpprest120d_app_2_4.dll!std::_Func_class<void>::operator()() Line 315   C++
cpprest120d_app_2_4.dll!Concurrency::details::_TaskProcThunk::_Bridge(void * _PData) Line 497   C++
cpprest120d_app_2_4.dll!Concurrency::details::_TaskCollectionImpl::_RunTask(void (void *) * _Proc, void * _Parameter, Concurrency::details::_TaskInliningMode _InliningMode) Line 243   C++
cpprest120d_app_2_4.dll!Concurrency::details::_ScheduleFuncWithAutoInline(const std::function<void __cdecl(void)> & _Func, Concurrency::details::_TaskInliningMode _InliningMode) Line 535  C++
cpprest120d_app_2_4.dll!Concurrency::details::_Task_impl_base::_ScheduleContinuationTask(Concurrency::details::_ContinuationTaskHandleBase * _PTaskHandle) Line 2011    C++
cpprest120d_app_2_4.dll!Concurrency::details::_Task_impl_base::_RunContinuation(Concurrency::details::_ContinuationTaskHandleBase * _PTaskHandle) Line 1988 C++
cpprest120d_app_2_4.dll!Concurrency::details::_Task_impl_base::_RunTaskContinuations() Line 2145    C++
cpprest120d_app_2_4.dll!Concurrency::details::_Task_impl<web::http::http_response>::_FinalizeAndRunContinuations(web::http::http_response _Result) Line 2489    C++
cpprest120d_app_2_4.dll!Concurrency::task_completion_event<web::http::http_response>::set(web::http::http_response _Result) Line 2687   C++
cpprest120d_app_2_4.dll!web::http::client::details::request_context::complete_headers() Line 112    C++
cpprest120d_app_2_4.dll!web::http::client::details::HttpRequestCallback::OnHeadersAvailable(IXMLHTTPRequest2 * xmlReq, unsigned long dw, const wchar_t * phrase) Line 113   C++
msxml6.dll!URLMONRequest::_CallOnHeadersAvailable() Line 341    C++
msxml6.dll!URLMONRequest::_OnResponse(unsigned long dwResponseCode, const wchar_t * pwszResponseHeaders, const wchar_t * pwszRequestHeaders) Line 3761  C++
msxml6.dll!URLMONRequest::OnResponse(unsigned long dwResponseCode, const wchar_t * pwszResponseHeaders, const wchar_t * pwszRequestHeaders, wchar_t * * ppwszAdditionalRequestHeaders) Line 3813    C++
msxml6.dll!URLMONRequest::URLMONRequestSink::OnResponse(unsigned long dwResponseCode, const wchar_t * szResponseHeaders, const wchar_t * szRequestHeaders, wchar_t * * pszAdditionalRequestHeaders) Line 251    C++
urlmon.dll!CINetHttp::QueryStatusOnResponseDefault(unsigned long dwStat) Line 2343  C++
urlmon.dll!CINetHttp::QueryStatusOnResponse() Line 2122 C++
urlmon.dll!CINet::QueryInfoOnResponse() Line 6469   C++
urlmon.dll!CINet::INetQueryInfo() Line 4243 C++
urlmon.dll!CINet::OnINetInternal(unsigned long dwState) Line 5705   C++
urlmon.dll!CINet::Continue(_tagPROTOCOLDATA * pStateInfoIn) Line 1442   C++
urlmon.dll!CINet::TransitState(unsigned long dwState, int fAsync) Line 5609 C++
urlmon.dll!CINet::OnINetSendRequest(unsigned long dwResult, bool fReadPendingCallback) Line 4153    C++
urlmon.dll!CINet::CINetCallback(void * hInternet, unsigned long dwContext, unsigned long dwStatus, void * pvInfo, unsigned long dwStatusLen) Line 5273  C++
wininet.dll!InternetIndicateStatus()    Unknown
wininet.dll!CFsm::RunWorkItem() Unknown
wininet.dll!ICSocket::ReceiveCompletion()   Unknown
wininet.dll!CWxSocket::IoCompletionCallback()   Unknown
kernel32.dll!_BasepTpIoCallback@20()   Unknown
ntdll.dll!TppIopExecuteCallback()   Unknown
ntdll.dll!TppWorkerThread() Unknown
kernel32.dll!@BaseThreadInitThunk@12() Unknown
ntdll.dll!__RtlUserThreadStart()    Unknown
ntdll.dll!__RtlUserThreadStart@8() Unknown

It fails here:
    void _CallInContext(_CallbackFunction _Func) const
    {
        if (!_HasCapturedContext())
        {
            _Func();
        }
        else
        {
            ComCallData callData;
            ZeroMemory(&callData, sizeof(callData));
            callData.pUserDefined = reinterpret_cast<void *>(&_Func);
------> HRESULT _Hr = _M_context._M_pContextCallback->ContextCallback(&_Bridge, &callData, IID_ICallbackWithNoReentrancyToApplicationSTA, 5, nullptr);
            if (FAILED(_Hr))
            {
                throw ::Platform::Exception::CreateException(_Hr);
            }
        }
    }

Still investigating how to fix.. any suggestions would be appreciated!
Coordinator
Feb 12, 2015 at 11:46 PM
Hi n8burr,

That seems like quite a simple code snippet making a GET request to Google. What platform are you actually running on hitting this, Windows 8.1 or Windows 8.1 Phone?

Steve
Feb 13, 2015 at 1:06 AM
Edited Feb 13, 2015 at 1:09 AM
It's Windows 8.1 & Phone 8.1 - they both fail

I think I know why it isn't working but haven't fully tested it yet. CppRest is compiled with /ZW (Consume Windows Runtime Extension). While in my code using WRL / IDL and has /ZW disabled.

I thought it would work because this page mentions Casablanca:
https://msdn.microsoft.com/en-us/library/hh873181.aspx (as linked from here: https://msdn.microsoft.com/en-us/library/hh438466.aspx)

I'm not sure if i can enable /ZW with WRL. Is there a way to compile Casablanca without /ZW ?

this is just a guess. I should know more tomorrow..

Thanks for the response.
Coordinator
Feb 13, 2015 at 8:01 PM
Hi n8burr,

Ah I missed keying in on the fact that you aren't using C++/CX (/ZW) and only using WRL in your original post. My mistake :). Yes this is going to have problems.

There are several reasons this currently isn't possible. First PPL tasks, which we build on, in Visual Studio 2013 are not usable across the dll boundary if the /ZW option doesn't match. This is fixed in Visual Studio 2015. The second issue is in the C++ REST SDK we have some checks that technically incorrect check the __cplusplus_winrt macro instead of checking WINAPI_FAMILY. __cplusplus_winrt is defined if the /ZW switch is on. All of these checks would need to be updated to correctly use WINAPI_FAMILY.

Steve
Feb 13, 2015 at 8:06 PM
Thanks for the reply. I don't think I'll be able to use CppRest then. I'll just go back to using IXMLHTTPRequest2.

Thanks for the support!
Mar 25, 2015 at 9:37 PM
Now that VS2015 is coming out. Is there any possibility of seeing this work?

I also noticed this new macro. CPPREST_FORCE_PPLX

Would that make it work in my situation?

Thanks!
Coordinator
Apr 1, 2015 at 2:11 AM
Hi n8burr,

I can finally respond now that CodePlex discussion and issues are back up :).

No the CPPREST_FORCE_PPLX option I don't think will help. PPLX is basically a version of PPL tasks removed from Visual Studio. I think it will have the same issues and need to be patched.

I've opened the following issue to track this work, but I'm not exactly sure when we will get to it. Once Visual Studio 2015 comes out if you wanted to take a stab at it we accept contributions.

Steve
Jul 28, 2015 at 6:52 AM
Edited Jul 28, 2015 at 6:53 AM
I have the same problem with 2.6 version and Visual Studio 2013. Do you have any news about solving bug? Maybe is there workaround?