CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2025-01-20
by Pravallika KV

Original Post

Original - Posted on 2023-11-24
by Vivek Vaibhav Shandilya



            
Present in both answers; Present only in the new answer; Present only in the old answer;

I can see the [core packages](https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide?tabs=hostbuilder,windows#performance-optimizations) of Isolated Azure functions `Microsoft.Azure.Functions.Worker.Sdk` and `Microsoft.AspNetCore.App` are missing in your `.csproj`, refer [MSDOC](https://learn.microsoft.com/en-us/azure/azure-functions/migrate-dotnet-to-isolated-model?tabs=net8) to upgrade the function from in-process to isolated.
1. Install the NuGet packages `Microsoft.Azure.Functions.Worker.Sdk` with version `1.16.4 or later`.
2. Add the framework reference to `Microsoft.AspNetCore.App`. 3. Add `<Nullable>enable</Nullable>` in `.csproj`.
**.csproj of Service Bus trigger .NET 8.0 Isolated Azure function:** ```xml <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <AzureFunctionsVersion>v4</AzureFunctionsVersion> <OutputType>Exe</OutputType> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> <ItemGroup> <FrameworkReference Include="Microsoft.AspNetCore.App" /> <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.22.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0" /> </ItemGroup> <ItemGroup> <None Update="host.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Update="local.settings.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToPublishDirectory>Never</CopyToPublishDirectory> </None> </ItemGroup> <ItemGroup> <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" /> </ItemGroup> </Project> ``` **local.settings.json:** ```json { "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated", "ServiceBusConnection": "ServiceBus_ConnectionString" } } ``` **Code Snippet:**
**Function.cs:** ```csharp [Function(nameof(Function1))] public async Task Run( [ServiceBusTrigger("queue1", Connection = "demo")] ServiceBusReceivedMessage message, ServiceBusMessageActions messageActions) { _logger.LogInformation("Message ID: {id}", message.MessageId); _logger.LogInformation("Message Body: {body}", message.Body); _logger.LogInformation("Message Content-Type: {contentType}", message.ContentType);
await messageActions.CompleteMessageAsync(message); } ```
**Program.cs:**
```csharp using Microsoft.Azure.Functions.Worker; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting;
var host = new HostBuilder() .ConfigureFunctionsWebApplication() .ConfigureServices(services => { services.AddApplicationInsightsTelemetryWorkerService(); services.ConfigureFunctionsApplicationInsights(); }) .Build();
host.Run(); ```
I have used code mentioned in the [document](https://learn.microsoft.com/en-us/azure/azure-functions/migrate-dotnet-to-isolated-model?tabs=net8#programcs-file) and it worked for me.
Make sure to install `.NET 8.0`, latest `packages` as per requirement and upgrade to latest `Azure Function core tools` for local run from [here](https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows,in-process,node-v4,python-v2,http-trigger,container-apps&pivots=programming-language-csharp#install-the-azure-functions-core-tools)
I am using HTTP Trigger
**#My Code:** **`.csproj`:** ```xml <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <AzureFunctionsVersion>v4</AzureFunctionsVersion> <RootNamespace>My.Namespace</RootNamespace> <OutputType>Exe</OutputType> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> <ItemGroup> <FrameworkReference Include="Microsoft.AspNetCore.App" /> <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.19.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.2" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.0.0" /> <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.0.0" /> <!-- Other packages may also be in this list --> </ItemGroup> <ItemGroup> <None Update="host.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Update="local.settings.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToPublishDirectory>Never</CopyToPublishDirectory> </None> </ItemGroup> <ItemGroup> <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext"/> </ItemGroup> </Project> ``` **`program.cs`:** ```csharp using Microsoft.Azure.Functions.Worker; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.DependencyInjection;
var host = new HostBuilder() .ConfigureFunctionsWorkerDefaults() .ConfigureServices(services => { services.AddApplicationInsightsTelemetryWorkerService(); services.ConfigureFunctionsApplicationInsights(); }) .Build();
await host.RunAsync(); ``` **`HttpTrigger`:** ```csharp using System.Net; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.Functions.Worker; using Microsoft.Extensions.Logging;
namespace Company.Function { public class HttpTrigger1 { private readonly ILogger _logger;
public HttpTrigger1(ILoggerFactory loggerFactory) { _logger = loggerFactory.CreateLogger<HttpTrigger1>(); }
[Function("HttpTrigger1")] public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req) { _logger.LogInformation("C# HTTP trigger function processed a request.");
return new OkObjectResult("Welcome to Azure Function!"); } } } ```
**`local.settings.json`:** ```json { "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated" } } ```
**`OUTPUT`:**
![enter image description here](https://i.imgur.com/NfwmSC7.png)
![enter image description here](https://i.imgur.com/8RQcuER.png)
**Azure:** ![enter image description here](https://i.imgur.com/4zOJDEo.png)

        
Present in both answers; Present only in the new answer; Present only in the old answer;