- Home /
Error CS0119 but new keyword was used
I'm connecting to my database with this:
IEnumerator ValidateLogin() {
WWWForm form = new WWWForm();
form.AddField( "myform_user", formUser );
form.AddField( "myform_pass", formPassword );
//error is here
WWW www = new WWW(URL, form);
yield return www;
if (www.error != null) {
print(www.error);
} else {
print("Test ok");
formText = www.data;
www.Dispose();
}
}
I'm getting the error: CS0119: Expression denotes a 'type', where a 'variable', 'value' or 'method group' was expected
On the line: WWW www = new WWW(URL, form);
I haven't done a lot of c# or unity web connectivity, and I'd appreciate the help. All of the other solutions I've found are because the programmer was missing the "new" keyword.
Have you called this script URL.cs or form.cs, perchance?
It looks like URL is the name of a class, that would produce exactly this error. WWW's constructor needs a string as its first argument. So, @nakoso, where do you declare URL? What is it?
I won't leave my website address, but otherwise the declaration is below.` string URL = "http://redacted/index.php";`
Answer by zach-r-d · Aug 04, 2015 at 11:20 PM
Pretty sure it's complaining about URL, not WWW. Try replacing URL with a literal string (or string variable) that is the URL to post the form to. Unless URL is the name of a string variable in all caps, in that case you should use lower case instead.
I don't think URL being the name of a string variable would produce this error. There's absolutely nothing wrong with having a variable name in caps.
I think you misunderstood my intention there. The reason I wrote that last sentence was in case a variable was given the same identifier as a type in the same assembly (basically, what you and tanoshimi said). In such a case, the compiler may have resolved the identifier in that line of code to the type ins$$anonymous$$d of the variable; if it did, it would in fact produce exactly that error. The suggestion to use lowercase ins$$anonymous$$d was a quick way to resolve such a name collision.
Personally, I believe having a variable name in caps is acceptable if and only if the variable is a constant.
Ah, fair enough zach, thanks for clarifying. I've not encountered that particular kind of compiler-confusion so it's interesting to hear about.
However, na$$anonymous$$g conventions are very much subjective and local.
I've worked on projects where types would always be given Pascal case names, and so a name in all-uppercase (even initialisms) would actually indicate that it is a variable.
I use all-caps for constants declared at the class level. URL is such a constant.
Ah, got it. Could you try rena$$anonymous$$g it to FOR$$anonymous$$_POST_URL or something else, just in case there's a URL class that's causing a name collision? There's almost certainly no type with that name. If that doesn't fix it, then try rena$$anonymous$$g "form".
Your answer
Follow this Question
Related Questions
Unity Null Reference Error 1 Answer
Unity PHP login always returning true 3 Answers
Getting Fatal Error 2030 using WWW in Flash 7 Answers
CommandInvokationFailure: Unable to install APK to device 6 Answers
Having difficulty with semicolons. 2 Answers