diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp
index 631acce2..f659476e 100644
--- a/include/nlohmann/detail/output/binary_writer.hpp
+++ b/include/nlohmann/detail/output/binary_writer.hpp
@@ -683,7 +683,7 @@ class binary_writer
     */
     static std::size_t calc_bson_entry_header_size(const typename BasicJsonType::string_t& name)
     {
-        if (name.find(static_cast<CharType>(0)) != BasicJsonType::string_t::npos)
+        if (name.find(static_cast<typename BasicJsonType::string_t::value_type>(0)) != BasicJsonType::string_t::npos)
         {
             JSON_THROW(out_of_range::create(409, "BSON key cannot contain code point U+0000"));
         }
diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp
index 94a0be69..e739eb5c 100644
--- a/single_include/nlohmann/json.hpp
+++ b/single_include/nlohmann/json.hpp
@@ -8840,7 +8840,7 @@ class binary_writer
     */
     static std::size_t calc_bson_entry_header_size(const typename BasicJsonType::string_t& name)
     {
-        if (name.find(static_cast<CharType>(0)) != BasicJsonType::string_t::npos)
+        if (name.find(static_cast<typename BasicJsonType::string_t::value_type>(0)) != BasicJsonType::string_t::npos)
         {
             JSON_THROW(out_of_range::create(409, "BSON key cannot contain code point U+0000"));
         }