• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 83
  • Last Modified:

C Sharp script deployed in Azure not working

Hello Experts,

I have deployed the following C# script in Azure, however I'm constantly getting the following error when I enter the firstname and lastname parameters as shown in the image


       
using System.Net;
        public static async Task<HttpResponseMessage> 
        Run(HttpRequestMessage req, TraceWriter log)
        {
            string firstname=null,lastname = null;
            dynamic data = await req.Content.ReadAsAsync<object>();
            firstname = firstname ?? data?.firstname;
            lastname = data?.lastname;
            return (lastname + firstname) == null ? 
             req.CreateResponse(HttpStatusCode.BadRequest, 
             "Please pass a name on the query string or in the 
             request body") : 
            req.CreateResponse(HttpStatusCode.OK, "Hello " + 
             firstname + " " + lastname);
        }

Open in new window


The following is the error message@

2017-11-27T16:37:37.340 Function started (Id=a7a78773-bf61-44b3-999a-3792ac4dd28f)2017-11-27T16:37:37.351 Function compilation error2017-11-27T16:37:37.351 run.csx(11,14): error CS1010: Newline in constant2017-11-27T16:37:37.351 run.csx(11,64): error CS1003: Syntax error, ',' expected2017-11-27T16:37:37.351 run.csx(12,22): error CS1003: Syntax error, ',' expected2017-11-27T16:37:37.351 run.csx(12,26): error CS1003: Syntax error, ',' expected2017-11-27T16:37:37.351 run.csx(12,26): error CS1010: Newline in constant2017-11-27T16:37:37.351 run.csx(12,31): error CS1003: Syntax error, ',' expected2017-11-27T16:37:37.351 run.csx(14,41): error CS1026: ) expected2017-11-27T16:37:37.351 run.csx(14,41): error CS1003: Syntax error, ':' expected2017-11-27T16:37:37.351 run.csx(14,41): error CS1525: Invalid expression term ';'2017-11-27T16:37:37.351 run.csx(12,14): error CS0103: The name 'request' does not exist in the current context2017-11-27T16:37:37.351 run.csx(12,22): error CS0103: The name 'body' does not exist in the current context2017-11-27T16:37:37.607 Exception while executing function: Functions.RegisterUser. Microsoft.Azure.WebJobs.Script: Script compilation failed.2017-11-27T16:37:37.670 Function completed (Failure, Id=a7a78773-bf61-44b3-999a-3792ac4dd28f, Duration=324ms)

Open in new window


The following is an image of the inputs
csharp
Can someone please let me know where I'm going wrong?

Thanks

Carlton
0
Member_2_7966113
Asked:
Member_2_7966113
  • 2
1 Solution
 
Snarf0001Commented:
If you still need help with this, it's just the line break in the prompt field "Please pass xxxx".  You're breaking onto a new line, so you either have to terminate the string and use a "+" symbol, or prefix the string with "@":

using System.Net;
        public static async Task<HttpResponseMessage> 
        Run(HttpRequestMessage req, TraceWriter log)
        {
            string firstname=null,lastname = null;
            dynamic data = await req.Content.ReadAsAsync<object>();
            firstname = firstname ?? data?.firstname;
            lastname = data?.lastname;
            return (lastname + firstname) == null ? 
             req.CreateResponse(HttpStatusCode.BadRequest, 
             "Please pass a name on the query string or in the request body") : 
            req.CreateResponse(HttpStatusCode.OK, "Hello " + 
             firstname + " " + lastname);
        }

Open in new window


OR:

using System.Net;
        public static async Task<HttpResponseMessage> 
        Run(HttpRequestMessage req, TraceWriter log)
        {
            string firstname=null,lastname = null;
            dynamic data = await req.Content.ReadAsAsync<object>();
            firstname = firstname ?? data?.firstname;
            lastname = data?.lastname;
            return (lastname + firstname) == null ? 
             req.CreateResponse(HttpStatusCode.BadRequest, 
             @"Please pass a name on the query string or in the 
             request body") : 
            req.CreateResponse(HttpStatusCode.OK, "Hello " + 
             firstname + " " + lastname);
        }

Open in new window

0
 
Member_2_7966113Author Commented:
Snarf

Thanks for responding. I'm just about to board a flight so I will try your suggestion when I land.

Will let you know how I get on when I land.

Cheerd
0
 
Member_2_7966113Author Commented:
Snarf,

Fantastic. The code worked like a dream. Cheers mate.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now