Why code:

client->Credentials = gcnew NetworkCredential("username", "password");

doesnt work for me?

Error	1	error C2061: syntax error : identifier 'NetworkCredential'

Dani AI

Generated

Good catch by and thanks for confirming, . The C2061 here means the compiler never resolved the .NET type you were trying to use. That normally comes from one of three issues: the file is being built as native C++ (not C++/CLI), the assembly that contains the type is not referenced, or the type’s namespace hasn’t been made visible to the compiler.

Checklist to avoid C2061 in this situation:

  • Make sure the source is compiled with CLR support (C++/CLI). In Visual Studio set Common Language Runtime Support to /clr under Project Properties -> Configuration Properties -> General.
  • Ensure the System assembly is referenced by the project (or add a file-level assembly reference with #using <System.dll>).
  • Either import the network namespace at the top of your file or use the fully qualified type name so the compiler can find the type.

If the error persists, verify you are editing a managed source file (no accidental plain-C++ compile settings), check for typos/case sensitivity, and try a minimal test file to isolate the problem. For details on the type and the compiler option, see the official docs: NetworkCredential class documentation and .

Recommended Answers

All 2 Replies

Do you have using namespace System::Net; at the top?

Ehh..thought that System::Net:Mail
Will be enough :) Thx once again..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.