Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executable compiled with Visual Studio 2019 and NuGet package 1.9.8 in Debug configuration throws exception #1146

Open
DonChunior opened this issue Nov 21, 2024 · 4 comments

Comments

@DonChunior
Copy link

Description

I'm using following simple example code:

#include <cpr/cpr.h>

int main() {
    cpr::Response r = cpr::Get(cpr::Url{"https://example.com/"});
}

Building the executable works with all combinations:

  • Debug + x86 = 🆗
  • Debug + x64 = 🆗
  • Release + x86 = 🆗
  • Release + x64 = 🆗

But executing does only work for the Release builds.
The Debug builds throw an error:

Exception thrown at 0x00007FFD9A0B3240 (msvcp140d.dll) in my_example.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

When the exception is thrown, Visual Studio jumps to line 58 of the file ...\packages\libcpr.1.9.8\build\native\x64\Debug\include\cpr\api.h:

template <typename... Ts>                               // Line 56
Response Get(Ts&&... ts) {                              // Line 57
    Session session;                                    // Line 58 <-- Visual Studio jumps to here when exception is thrown
    priv::set_option(session, std::forward<Ts>(ts)...); // Line 59
    return session.Get();                               // Line 60
}                                                       // Line 61

Example/How to Reproduce

  1. Create new, empty C++ project in Visual Studio 2019.
  2. Add a C++ file with the example code above.
  3. Install version 1.9.8 of the libcpr NuGet package.
  4. Choose Debug as configuration and x64 as platform.
  5. Press the key F7 to build the executable.
  6. Press the key F5 to start debugging.

Possible Fix

No response

Where did you get it from?

NuGet

Additional Context/Your Environment

  • OS: Windows 10
  • OS Version: Version 22H2 (Build 19045.5131)
  • IDE: Visual Studio Professional 2019
  • IDE Version: Version 16.11.42
@DonChunior
Copy link
Author

Today I tested the behaviour on my private home computer:

  • OS: Windows 10
  • OS Version: 22H2 (Build 19045.5131)
  • IDE: Visual Studio Community 2019
  • IDE Version: 16.11.42

Building the executable again works with all combinations of configurations and platforms.

But executing only works for the Release x64 build.
Debug x86, Debug x64 and Release x86 throw the previously mentioned exception.

@COM8
Copy link
Member

COM8 commented Nov 24, 2024

@DonChunior thanks for reporting! I will try to look into this.

@DonChunior
Copy link
Author

Hello @COM8,

thanks, I would appreciate it very much if there would be a fix for my problem in the 1.9.x version, because I am bound to the standard C++14 due to dependencies to other libraries.
Therefore I can't use a newer cpr version which already relies on C++17 features.

@COM8
Copy link
Member

COM8 commented Dec 21, 2024

@DonChunior I can not reproduce your issue in VS 2022.

I used:

Microsoft Visual Studio Community 2022 (64-bit) - Current
Version 17.11.6

Bot, Release and Debug compile and execute with cpr 1.9.8. Do you mind sharing an example solution for me to reproduce this?

@COM8 COM8 self-assigned this Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants