Getting an exception when trying to close file stream on win8/RT

May 13, 2014 at 7:57 PM
I'm working on a basic downloader based on the http client tutorial. I've tried to match it as closely as possible, with the exception of the open_ostream call which takes a Windows::Storage::StorageFile instead of a path string. It does the download and save to file correctly, but when I try to close the file stream it throws an exception because fileInfo is NULL in _close_file in filestream.h.
auto fileStream = std::make_shared<ostream>();

Windows::Storage::StorageFolder^ storageRoot = Windows::Storage::ApplicationData::Current->TemporaryFolder;

    pplx::task<void> createFileTask = create_task(storageRoot->CreateFileAsync(fileName_w, Windows::Storage::CreationCollisionOption::ReplaceExisting))
        .then([=](Windows::Storage::StorageFile^ storageFile)
        return fstream::open_ostream(storageFile);
    }).then([=](ostream outFile)
        *fileStream = outFile;

        web::http::client::http_client client(url_u);

        return client.request(web::http::methods::GET);
    }).then([=](web::http::http_response response)
        m_lastStatusCode = response.status_code();

        return response.body().read_to_end(fileStream->streambuf());
        return fileStream->close(); // breaks here

    catch (const std::exception &e)
        printf("Error exception:%s\n", e.what());
May 13, 2014 at 9:07 PM
Hi TylerBit

This is a bug in our WinRT file streams. We are aware of this issue and we will fix it for our upcoming release (2.1), in the next couple of weeks.

May 13, 2014 at 9:18 PM
Ok, thanks for the reply.
May 13, 2014 at 9:25 PM
FYI: I have opened a workitem: to track this bug.