error CS0117: 'Marshal' does not contain a definition for 'SecureStringToGlobalAllocUnicode'

Krishna Yalavarthi 1 Reputation point Microsoft Employee
2020-12-19T08:03:49.44+00:00

Hello,

Just want to check if Marshal.SecureStringToGlobalAllocUnicode(SecureString); is supported in .NET 4.5 . I keep getting the above error that Marshall doesnt contain a definition for SecureStringToGlobalAllocUnicode .

https://video2.skills-academy.com/en-us/dotnet/api/system.runtime.interopservices.marshal.securestringtoglobalallocunicode?view=netframework-4.5#System_Runtime_InteropServices_Marshal_SecureStringToGlobalAllocUnicode_System_Security_SecureString_
This is the code that I was using, which is giving the error.

using System.Security;
using System.Runtime.InteropServices;

            IntPtr valuePtr = IntPtr.Zero;  
            try  
            {  
                valuePtr = System.Runtime.InteropServices.Marshal.SecureStringToGlobalAllocUnicode(SecureString);  
                exportedString = System.Runtime.InteropServices.Marshal.PtrToStringUni(valuePtr);  
            }  
            finally  
            {  
                Marshal.ZeroFreeGlobalAllocUnicode(valuePtr);  
            }  
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,841 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,159 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 85,131 Reputation points
    2020-12-19T08:17:03.95+00:00

    valuePtr = System.Runtime.InteropServices.Marshal.SecureStringToGlobalAllocUnicode(SecureString);

    You passed as parameter "SecureString", which is a type

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.