2
votes

Problem

I freshly installed mono on OS X Lion, compiled and ran my first-ever csharp "hello world", and then attempted a web request...

But I'm missing HttpUtility.

gmcs GoogleExample.cs -r:System.Web.Services -r:System.Web 
GoogleExample.cs(14,32): error CS0103: The name `HttpUtility' does not exist in the current context
Compilation failed: 1 error(s), 0 warnings

What to do?

History

I code C, NodeJS, Python, Ruby, etc. No noob to programming, just to mono.

I just installed mono (MRE Runtime, MDK, and MonoDevelop) on OS X via these instructions: http://www.go-mono.com/mono-downloads/download.html

Then I went off to play hello world with these instructions: http://www.mono-project.com/Mono_Basics

And now I want to create a web request following this tutorial: http://www.codeproject.com/KB/cross-platform/introtomono1.aspx?msg=3229009

End Goal: Naturally, I want to create a JSON-based chat server as my first csharp project.

2
Mono is certainly not missing HttpUtility. But maybe your install is. Try installing the Mono SDK, you'll have better luck at writing programs with a SDK than with a runtime. - Jb Evain
I do have the MDK installed. I believe that's what installed gmcs in the first place. Is there another SDK not listed on that downloads page I should be looking for? - coolaj86
are you sure you're not missing a using statement in your program? could we take a look at your code? - madd0
It's on the codeproject tutorial link. I just copy/pasted GoogleExample.cs. I was just looking on another SO post and it mentions that there's a difference between "Client" and "Full" frameworks: stackoverflow.com/questions/2405182/…. Perhaps this is related? - coolaj86

2 Answers

0
votes

I just started a new ASP.Net solution in Monodevelop 2.6

Typing Http in the codebehind (button1Clicked) of the sample page, immediately autocompletes to HttpUtility, among many others.

This is certainly not missing. You need reference to

System.Web

though

0
votes

Apparently google couldn't find it either, so they wrote there own api-compatible version:

Here's a workaround:

  1. Compile Google's version as a library

    wget 'http://google-gdata.googlecode.com/svn/trunk/clients/cs/src/core/HttpUtility.cs'
    gmcs -t:library HttpUtility.cs
    
  2. Edit GoogleExample.cs to include that namespace

    using Google.GData.Client; // where HttpUtility lives
    
  3. Recompile using the library

    gmcs GoogleExample.cs -r:System.Web.Services -r:System.Web -r:HttpUtility
    

Side Note: the RegEx (or perhaps URL) in the example GoogleExample.cs is out of date, so it never returns results, but at least it compiles and runs.