Azure / Azure/azure-functions-host

Latest patch version of System.Text.Encodings.Web breaks in Azure Function

Open
#7,220 6 comments 1 reaction 0 assignees View on GitHub
needs-investigation
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

When using a different version of System.Text.Encodings.Web from 4.0.5.0, runtime API fails.

I am loading a view DLL into my Azure Function as such
```
string executionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var compiledViewAssembly = Assembly.LoadFile(Path.Combine(executionPath, "MyApp.AzureFunctions.Views.dll"));
builder.Services
.AddSingleton()
.AddSingleton()
.AddMvcCore()
.AddViews()
.AddRazorViewEngine()
.AddApplicationPart(compiledViewAssembly);
```

Everything works fine until I call the rendering engine with
```
await view.RenderAsync(viewContext);
```

I get the following error:
```
System.MissingMethodException: 'Method not found: 'Void Microsoft.AspNetCore.Mvc.Razor.RazorPageBase.StartTagHelperWritingScope(System.Text.Encodings.Web.HtmlEncoder)'.'
```

After 5 hours of investigation on this, it seems that the version update from 4.0.5.0 to 4.0.5.1 will fail.

I have noticed that if I change the DLL from
C:\Users\jsgou\AppData\Local\AzureFunctionsTools\Releases\3.23.0\cli_x64\System.Text.Encodings.Web.dll from 4.0.5.0, to 4.0.5.1
Then everything will start to work for me.

When decompiling my MyApp.AzureFunctions.Views.dll, I see that it requires `System.Text.Encodings.Web, Version=4.0.5.1`

I am aware of the limitations with the host here, but I wanted to bring this to your attention if it were to be "updated" in production for everybody; I would believe that this scenario would fail as well (if I were to stay on 4.0.5.0 and you update to 4.0.5.1).

Is there a way to make this work? I wanted to take advantage of this fix rather than staying behind.

Contributor guide

Open the contributing guide

Research direction

Reproduce the Azure Function setup that loads MyApp.AzureFunctions.Views.dll with Assembly.LoadFile, comparing System.Text.Encodings.Web versions 4.0.5.0 and 4.0.5.1. Start at view.RenderAsync(viewContext) and the reported RazorPageBase.StartTagHelperWritingScope failure; done means the compiled view renders without the MissingMethodException under the host runtime.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.