Sign in to follow this  
dxFoo

Why is System::Net not in scope while using Managed C++?

Recommended Posts

I was exploring my options using System::Net in my C++ program, and I noticed System::Net was nowhere to be found. How come? Was System::Net not part of the .NET framework? How can I take advantage of networking features then? Thanks in advanced.

Share this post


Link to post
Share on other sites
You need to add a reference to System.Net.dll. Right click on the References node and choose "Add Reference".

If you're using VS2002, you won't have a References node. You can instead put this in your source file (like an #include):

#using <System.Net.dll>

Share this post


Link to post
Share on other sites
I get this error...

fatal error C1107: could not find assembly 'System.Net.dll': please specify the assembly search path using /AI or by setting the LIBPATH environment variable

Using VS 2005, I look in the add references window and System.Net isn't there.

Share this post


Link to post
Share on other sites
I got it. I removed the System.Net.dll and just used System.dll. The NET namespace is already contained inside. So, I guess now I ask what's the differences between mscorlib.dll and System.dll?

And... System::Uri::Uri(System::String ^)' : cannot convert parameter 1 from 'System::Uri ^' to 'System::String ^'

Wha?


System::Uri sample = gcnew System::Uri("http://www.google.com");

Console::WriteLine("Host: " + sample.Host);
Console::WriteLine("Port: " + sample.Port);
Console::WriteLine("Scheme: " + sample.Scheme);



Share this post


Link to post
Share on other sites
I haven't used managed C++ in 2005 or anything, so maybe they added some things ... but last time I checked:

"Host: " was not a string, and therefore does not support the + operator ...

I don't know wht the Uri line wouldn't be right.

Share this post


Link to post
Share on other sites
Oh, that makes sense. It works now :) And Host would cast to a string here because of how Console::WriteLine() works. You could do sample->Host->ToString(), but it is redundent.

Thanks for the help.


Uri ^sample = gcnew Uri("http://www.google.com");

Console::WriteLine("Host: " + sample->Host);
Console::WriteLine("Port: " + sample->Port);
Console::WriteLine("Scheme: " + sample->Scheme);


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this