1

I've a nuget reference to System.Text.Json 7.0.1 in a in-process Azure function, targeting
.NET 6 When starting the function locally I got a runtime error,

Could not load file or assembly 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51

What is the problem? Is it due to the fact that the function is running in-process?

Mohammad Aghazadeh
  • 2,108
  • 3
  • 9
  • 20
Erik Z
  • 4,660
  • 6
  • 47
  • 74
  • 2
    Yes; likely due to it being an in-process func app. It'll try to remove redundant assemblies and since `System.Text.Json` is already part of the boilerplate it'll likely remove it causing the error. You could try adding the dependency in your `.csproj` using `FunctionsPreservedDependencies` to preserve it. Possibly also `System.Text.Encodings.Web` since the package has a dependency with it. – NotFound Dec 21 '22 at 12:17
  • 1
    Thank you @NotFound. I found a another solution that seems to work. https://stackoverflow.com/a/66084146/162003, What's the difference between using <_FunctionsSkipCleanOutput>true and FunctionPreservedDependencies? – Erik Z Dec 21 '22 at 12:55
  • 2
    `_FunctionsSkipCleanOutput` works over all assemblies. Using `FunctionPreservedDependencies` you narrow it down to particular assemblies, which is more efficient but requires extra tinkering with the exact assembly names to get it working. – NotFound Dec 21 '22 at 14:07

0 Answers0