4

I am using .net Core 3 with Azure function version 2 (Visual studio 2019 with .net framework 4.8). While executing the function below exception occours :

System.Private.CoreLib: Exception while executing function:

Microsoft.Extensions.Configuration.AzureAppConfiguration: Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

System.Private.CoreLib: Could not load the specified file.

Please help.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
    <DependsOnNETStandard>true</DependsOnNETStandard>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.ServiceBus" Version="4.1.1" />
    <PackageReference Include="Microsoft.ApplicationInsights" Version="2.11.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="3.2.0" />
    <PackageReference Include="Microsoft.IdentityModel" Version="7.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.29" />
    <PackageReference Include="NETStandard.Library" Version="2.0.3" />
    <PackageReference Include="System.Text.Json" Version="4.6.0" />
  </ItemGroup>
  <ItemGroup>
    <None Include="******.cs" />
    <None Include="******.cs" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\************" />
    <ProjectReference Include="..\************" />
  </ItemGroup>
  <ItemGroup>
    <None Update="*******/function.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="*******/function.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Shailendra
  • 153
  • 3
  • 11
  • Can you show the code about the `.csproj` file of your app? – Cindy Pau Nov 14 '19 at 09:26
  • Hello, I have added .csproj file – Shailendra Nov 14 '19 at 12:25
  • Hi, can you show in text instead of the image? Change to text format, this is the point to pay attention to when asking questions on stackoverflow. :) – Cindy Pau Nov 14 '19 at 12:32
  • The program runs successfully in my side and there is no error. Your question is almost certain to be the problem of the assembly reference. The problem should be your dependence on the assembly in the next two . – Cindy Pau Nov 14 '19 at 17:44
  • 1
    You are using net core 3 with v2 function, did you try with the v3 function preview? – George Chen Nov 18 '19 at 07:52
  • @BowmanZhu That are the reference for another project in my solution – Shailendra Nov 18 '19 at 10:54
  • @GeorgeChen Yes i tried with v3 preview and got another exception : sni.dll not found. Please see the link https://stackoverflow.com/questions/58833050/azure-functions-runtime-exception-the-type-initializer-for-system-data-sqlclien – Shailendra Nov 18 '19 at 10:56
  • @GeorgeChen Finally with azure function v3 preview it is a success. – Shailendra Nov 20 '19 at 08:27
  • So you just change it to v3 or do other things, cause you said you still get exception before. – George Chen Nov 20 '19 at 08:36
  • @GeorgeChen I changed it to v3 and got exception 'sni.dll' not found but it worked with the workaround mentioned in the link in my above comment. BUT for v2 it`s still the same exception (this is the reason I updated to v3) Thanks – Shailendra Nov 20 '19 at 08:55
  • See https://github.com/Azure/azure-functions-core-tools/issues/1662 for the correct v3preview string : v3-preview – cab0 Jul 23 '21 at 15:19

4 Answers4

0

Is there any assembly dependency here?

 <ItemGroup>
    <None Include="******.cs" />
    <None Include="******.cs" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\************" />
    <ProjectReference Include="..\************" />
  </ItemGroup>

This is a problem caused by assembly dependencies, but the parts you provide are not in conflict. The problem should be in the part that is omitted later.

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • Do you think this link as a optimal solution ? https://stackoverflow.com/questions/57924191/azure-function-v2-and-system-text-json/58935206?noredirect=1#comment104129350_58935206 – Shailendra Nov 19 '19 at 13:48
  • @Shailendra Can you succeed in doing this? I think specific analysis is needed because assembly conflicts can not always be solved by downgrade the .net core version. – Cindy Pau Nov 20 '19 at 02:29
  • Not by downgrading But i updated to azure function 3 preview and it was successfull after few attempts https://stackoverflow.com/questions/58833050/azure-functions-runtime-exception-the-type-initializer-for-system-data-sqlclien/58937933#58937933 – Shailendra Nov 20 '19 at 08:25
  • @Shailendra `v3-preview` ? – Cindy Pau Nov 20 '19 at 08:26
  • Right, please see my csproj file from the link i mentioned. Thanks – Shailendra Nov 20 '19 at 08:29
0

Microsoft.Extensions.Configuration.AzureAppConfiguration

is missing in your .csproj. You can find it in Nuget Package as

Microsoft.Extensions.Configuration

and install into your project so then you should have in addition this line:

<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.0.1" />

If you ensure that all assemblies are physically present at your project and the issue still remains than check target platform across your dependency tree - e.g. AnyCPU. I got the specified error if I'm trying to run the Azure Functions v1.0.29 on x64 platform.

Ondrej Rozinek
  • 563
  • 8
  • 14
0

Change your project .net standard version to 2.0 and upgrade .net core version to 3.1, It will work without issue.

Function app version : v3

.Net Core : 3.1

.Net Standard : 2.0

My azure function app successfully running on Linux container with above configurations

vijay
  • 701
  • 2
  • 12
  • 26
0

I ran into something similar in my Azure Functions project. My project would build fine, but when calling certain functions via the CLI, I would get a similar error. What worked for me was including an inclusive lower bound reference for the problematic package, like so:

    <PackageReference Include="Microsoft.Extensions.Primitives" Version="[7.0.0,)" />    

Please take note of the versioning section specifically. An inclusive lower bound is a version range that specifies the minimum version of a package that is acceptable for your project. When you specify an inclusive lower bound, you are telling NuGet to only restore versions of the package that are equal to or greater than the specified version. In my case, adding an inclusive lower bound to the version range of the 'Microsoft.Extensions.Primitives' package fixed the issue because it ensured that NuGet only restored versions of the package that were 7.0.0 or higher.

Steven Wangler
  • 33
  • 2
  • 11