Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9246919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:36:22+00:00 2026-06-18T09:36:22+00:00

In looking into marshal_as one of the function calls expects the following format: System::String^

  • 0

In looking into marshal_as one of the function calls expects the following format:

System::String^ const &

What is the purpose of the const & after the managed pointer?

This does not compile for me:

static std::wstring GetString(const System::String^ value)
{
    return msclr::interop::marshal_as<std::wstring>(value);
}

Error 1 error C4996:

‘msclr::interop::error_reporting_helper<_To_Type,_From_Type>::marshal_as’: This conversion is not supported by the library or the header file needed for this conversion is not included. Please refer to the documentation on ‘How to: Extend the Marshaling Library’ for adding your own marshaling method. c:\program files (x86)\microsoft visual studio 9.0\vc\include\msclr\marshal.h 203

This does:

static std::wstring GetString(const System::String^ value)
{
    return msclr::interop::marshal_as<std::wstring>(const_cast<System::String^>(value));
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:36:24+00:00Added an answer on June 18, 2026 at 9:36 am

    The marshal_as method is defined by this template:

    template <class _To_Type, class _From_Type>
    inline _To_Type marshal_as(const _From_Type&);
    

    The primary purpose of the extra const & is to conform to this template declaration.

    This does affect how the function is called: I checked the IL, and the String^ is passed as a const indirect reference, as one would expect, but that’s not a major change.

    If the method were standalone, it would probably be declared without the const &, and there would be little difference.


    You’re trying to call a method String^ const & with a String^ const. The compiler can’t make that conversion automatically (safely).

    What you’re doing with your const_cast is turning the String^ const into a regular String^. The compiler can turn String^ into String^ const & safely and automatically.

    I’d just remove the const from your local method declaration. This compiles for me:

    static std::wstring GetString(System::String^ value)
    {
        return msclr::interop::marshal_as<std::wstring>(value);
    }
    

    Why can’t the compiler make that conversion? Note that String^ const & and const String^ const & are not the same thing. The first one says “A constant pointer to a string object”. The second says “A constant pointer to a constant string object“. In your method with (const System::String^ value), you’ve got a constant string object, and the function you’re calling expects a pointer to a non-const string object. We know that the String class is immutable, but the compiler doesn’t, so it won’t pass the address to a const object to a method that thinks the object is non-const.

    (I’m using Visual Studio 2010 SP1, but I don’t believe the marshal methods had any major changes between 2008 and 2010.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was looking into the String API and suddenly I came across one String
I looking into making a kind of robot testing browser. Like Selenium, but one
Currently looking into how I can go about playing two mp3 or aac format
Looking into Eclipse 4 RCP. Did the following: Created an Eclipse Plugin Project (no
Hi thanks for looking into this. I have been following Django's tutorial on URLs
I'm looking into creating a system / site which includes a website. I would
Were looking into Android for writing a tablet based system. Part of the design
After looking into 3D game programming, it quickly became evident why a physics engine
After looking into it for a while I am struggling to use a hidden
I am basically looking into a buggy makefile, which confused me with the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.