OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Azure Function running locally but not in Azure

  • Thread starter Thread starter NLAnaconda
  • Start date Start date
N

NLAnaconda

Guest
I created a default Azure project in Visual Studio with an HttpTrigger.

This is the only code (its generated by the template).

Code:
public static class Function1
{
    [FunctionName("Function1")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");

        string name = req.Query["name"];

        string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
        dynamic data = JsonConvert.DeserializeObject(requestBody);
        name = name ?? data?.name;

        string responseMessage = string.IsNullOrEmpty(name)
            ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
            : $"Hello, {name}. This HTTP triggered function executed successfully.";

        return new OkObjectResult(responseMessage);
    }
}

When I run the code locally it works fine. Then I do a deploy to an Azure Function (with the publish function in Visual Studio) and when I then run the project I get an error:

Code:
27-06-2024, 15:05:54,230
Information
Executing 'Function1' (Reason='This function was programmatically called via the host APIs.', Id=d47ad353-d75f-4ae6-acf7-d560c1d31a73)
27-06-2024, 15:05:54,231

Error
Could not load file or assembly 'System.Linq.Expressions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Everything I try involves some error with a dependancy. How can I solve this?
<p>I created a default Azure project in Visual Studio with an HttpTrigger.</p>
<p>This is the only code (its generated by the template).</p>
<pre><code>public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");

string name = req.Query["name"];

string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;

string responseMessage = string.IsNullOrEmpty(name)
? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
: $"Hello, {name}. This HTTP triggered function executed successfully.";

return new OkObjectResult(responseMessage);
}
}
</code></pre>
<p>When I run the code locally it works fine.
Then I do a deploy to an Azure Function (with the publish function in Visual Studio) and when I then run the project I get an error:</p>
<pre><code>27-06-2024, 15:05:54,230
Information
Executing 'Function1' (Reason='This function was programmatically called via the host APIs.', Id=d47ad353-d75f-4ae6-acf7-d560c1d31a73)
27-06-2024, 15:05:54,231

Error
Could not load file or assembly 'System.Linq.Expressions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
</code></pre>
<p>Everything I try involves some error with a dependancy.
How can I solve this?</p>
Continue reading...
 

Online statistics

Members online
0
Guests online
4
Total visitors
4
Top