intellij IDEA + System.Net.Http.Formatting + issue to run function CLI command from staging folder

124 Views Asked by At

I am working with Azure Functions app in intellij idea. From Yesterday I am struggling with following issue :

[2023-10-05T12:18:02.170Z] A host error has occurred during startup operation '7ab97efe-26f0-49bd-a6c9-53decba6c71b'.
[2023-10-05T12:18:02.170Z] Microsoft.Azure.WebJobs.Extensions.Http: Could not load file or assembly 'System.Net.Http.Formatting, Version=5.2.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
Value cannot be null. (Parameter 'provider')
[2023-10-05T12:18:02.197Z] Host startup operation has been canceled
Failed to run function CLI command from staging folder(azure-functions3169719571234745861). Value cannot be null. (Parameter 'provider').

I have done these steps :

  • Checked Java version everywhere in project it's correct.
  • Removed all Azure Functions Core Tool and upgraded to latest version - not worked.
  • Removed this folder C:\Users\me.azure-functions-core-tools - not worked.
  • Removed all version of intellij 2021 and installed latest 2023.2.2 version - not worked.
  • Run mvn clean package or mvn clean insall - not worked.
  • Removed .intellij folder then reloaded - not worked.
  • Install VS Code and run the project - not working
  • Tried with CLI - not working

Same issue I am getting everywhere.

Please let me know if any other settings to do for me to work with Azure Functions in intellij.

1

There are 1 best solutions below

0
Pravallika KV On

This happens mostly due to issues with Azure functions core tools.

  • Though you upgraded Azure function core tools, try uninstalling the function core tools completely and re-install again.
1. npm ls -g azure-functions-core-tools
2. npm uninstall -g func
3. npm install -g azure-functions-core-tools --unsafe-prem true

  • Reinstall Java and Maven as well.
  • Delete bin folder of your project, then clean and rebuild the application.
  • Make sure you have all the required dependencies with compatible versions in pom.xml:

Pom.xml of my sample Http Azure function:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>samplehttpfunction</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Azure Java Functions</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <azure.functions.maven.plugin.version>1.24.0</azure.functions.maven.plugin.version>
        <azure.functions.java.library.version>3.0.0</azure.functions.java.library.version>
        <functionAppName>samplehttpfunction-1696583393512</functionAppName>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.microsoft.azure.functions</groupId>
            <artifactId>azure-functions-java-library</artifactId>
            <version>${azure.functions.java.library.version}</version>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.4.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>2.23.4</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-functions-maven-plugin</artifactId>
                <version>${azure.functions.maven.plugin.version}</version>
                <configuration>
                    <appName>${functionAppName}</appName>
                    <resourceGroup>java-functions-group</resourceGroup>
                    <appServicePlanName>java-functions-app-service-plan</appServicePlanName>
                   <region>westus</region>
                    <runtime>
                        <os>windows</os>
                        <javaVersion>8</javaVersion>
                    </runtime>
                    <appSettings>
                        <property>
                            <name>FUNCTIONS_EXTENSION_VERSION</name>
                            <value>~4</value>
                        </property>
                    </appSettings>
                </configuration>
                <executions>
                    <execution>
                        <id>package-functions</id>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>obj</directory>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

local.settings.json:

{  
"IsEncrypted": false,  
"Values": {  
"AzureWebJobsStorage": "usedevelopmentstorage=true",  
"FUNCTIONS_WORKER_RUNTIME": "java"  
}  
}
  • If the issue still persists, try creating a new sample Azure function and check if you are getting the same error.

References:

https://github.com/Azure/azure-functions-core-tools/issues/3115