Could not load type 'System.Runtime.CompilerServices.DefaultInterpolatedStringHandler' from assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
I am currently using the latest Visual Studio 2022 Preview.
Just created a new Function App sample with a TimerTrigger Function.
As soon as I run the code, I got the error.

I have the same issue. Here is my .csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<DebugType>embedded</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="0.7.2-preview" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Hi @gabrielbaptista / @sujayvsarma , Triaging this issue as it requires investigation.
Hi, having the same issue. That's what I figured so far:
At the moment, the latest version of VS2022 is 17.0.0 Preview 3.0 which when installed, also installs .NET SDK 6.0.100-preview7:

In the .csproj file of the Azure Function project, we specify just 'net6.0'. I assume it means that we're effectively targeting the latest .NET 6.0 runtime installed at the machine.

Therefore, after installing the 3rd preview of VS2022 you're implicitly using preview 7 which has the new String Interpolation mechanism described here. That's where the 'DefaultInterpolatedStringHandler' comes from.
It would not be a problem should the Azure Functions Core Tools 4 would work the same way (i.e. just use the latest runtime installed) but that's not how it works. Instead of using the preview-7 runtime located here:
%PROGRAMFILES%\dotnet\shared\Microsoft.NETCore.App\6.0.0-preview.7.21377.19
Azure Functions Core Tools 4 uses its own runtime files located here:
%USERPROFILE%\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin
which in my case appear to be preview-5 which obviously doesn't have the new Interpolation feature, hence the error.

So, that's what you can do as a temporary workaround:
- Go to the %USERPROFILE%\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin folder.
- Back up the 'bin' folder just in case.
- Replace the files in that folder with the files from %PROGRAMFILES%\dotnet\shared\Microsoft.NETCore.App\6.0.0-preview.7.21377.19 folder.
@BikeInventor -
The file replacement in the Bin folder confirms the incorrect .Net Runtime files used between the project and Azure Functions runtimes. But, it wont help once you deploy to Azure unless you are deploying in self-hosting mode ?
I just went and built the function core tools myself from the release_4.0 branch against preview 7 sdk:
https://github.com/Azure/azure-functions-core-tools/tree/release_4.0
@BikeInventor -
The file replacement in the Bin folder confirms the incorrect .Net Runtime files used between the project and Azure Functions runtimes. But, it wont help once you deploy to Azure unless you are deploying in self-hosting mode ?
@sujayvsarma
I don't have any issues with deploying & running my function in Azure because the CI/CD pipeline builds it with the latest (preview-7) SDK which is also installed on the AF host.

I've replaced any files in here:
%USERPROFILE%\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin
That were from here:
%PROGRAMFILES%\dotnet\shared\Microsoft.NETCore.App\6.0.0-preview.7.21377.19
But I still get this error. I've tried killing the node.exe process, restarting VS, restarting my computer, etc. I can't get it to work still. Thoughts?
I figured it out. I needed to replace the files in:
%USERPROFILE%\AppData\Local\AzureFunctionsTools\Releases\4.3.0\cli_x64
with the files in here:
%PROGRAMFILES%\dotnet\shared\Microsoft.NETCore.App\6.0.0-preview.7.21377.19
I figured it out. I needed to replace the files in:
%USERPROFILE%\AppData\Local\AzureFunctionsTools\Releases\4.3.0\cli_x64with the files in here:
%PROGRAMFILES%\dotnet\shared\Microsoft.NETCore.App\6.0.0-preview.7.21377.19
Thanks, I've been trying to fix this issue for a couple of days. For me it was particularly when trying to execute an EFCore query.
This has resolved the issue.
Let us know if the above information resolves your query, or if you have any further queries.
@v-bbalaiagar - The above is not a "fix". It is a temporary workaround. When we deploy such an application to the Cloud, it won't work unless you publish it in "self-contained" mode.
We need a proper fix for this from the Azure Functions engineering team.
As far as I know, mine seems to work in Azure. But not locally.
@v-bbalaiagar - The above is not a "fix". It is a temporary workaround. When we deploy such an application to the Cloud, it won't work unless you publish it in "self-contained" mode.
We need a proper fix for this from the Azure Functions engineering team.
Thank you for your feedback! We will investigate this further and update you with the findings.
Tagging @anthonychu / @brettsam, for further investigation
Is anyone still reproducing this with .NET 6.0 RC1 and the latest core tools (https://www.npmjs.com/package/azure-functions-core-tools/v/4.0.3780). .NET 6.0 previews include breaking changes and this has conflicted with the core tools releases for some periods of time. Right now, everything should be caught up and things should work smoothly... but please let us know if that is not the case.
I'm having this same problem with .NET 6.0.100
@junalmeida -- can you share your sample csproj? Are you using the latest packages for everything?
I am getting the same issue when trying to add identity framework. First i added the package like so dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design then i use this command dotnet-aspnet-codegenerator identity -dc NombreDelProyecto.Data.DataContext --files "Account.Register;Account.Login;Account.Logout;Account.RegisterConfirmation" --useSqlite and i got the following error Unhandled exception. System.TypeLoadException: Could not load type 'System.Runtime.CompilerServices.DefaultInterpolatedStringHandler' from assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) at Microsoft.VisualStudio.Web.CodeGeneration.Design.Program.Execute(String[] args, ConsoleLogger logger) at Microsoft.VisualStudio.Web.CodeGeneration.Design.Program.Main(String[] args)
@rgbetanco -- can you also share your csproj? Are you using the latest Microsoft.NET.Sdk.Functions package?
@brettsam I updated all my referenced packages like the following
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.1-dev-00229" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.1-dev-00947" />
</ItemGroup>
</Project>
I also decided to try adding Identity without the code generator, now the error is as followed:
➜ NombreDelProyecto git:(master) ✗ dotnet ef migrations add IdentityMigrations
Build started...
Build succeeded.
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Could not load type 'System.Runtime.CompilerServices.DefaultInterpolatedStringHandler' from assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
System.TypeInitializationException: The type initializer for 'System.SharedTypeExtensions' threw an exception.
---> System.TypeLoadException: Could not load type 'System.DateOnly' from assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
--- End of inner exception stack trace ---
at System.SharedTypeExtensions.ProcessType(StringBuilder builder, Type type, Boolean fullName, Boolean compilable)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.FindContextTypes()
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.FindContextType(String name)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The type initializer for 'System.SharedTypeExtensions' threw an exception.
My DbContext class looks as follow:
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using NombreDelProyecto.Models;
using Microsoft.AspNetCore.DataProtection;
namespace NombreDelProyecto.Data
{
public class DataContext: IdentityDbContext
{
private readonly IDataProtector _protector;
public DataContext(DbContextOptions<DataContext> options, IDataProtectionProvider provider) : base(options){
_protector = provider.CreateProtector("Protect.Email");
}
public virtual DbSet<ContactUsModel> ContactUs { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder){
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ContactUsModel>()
.HasData(new ContactUsModel
{
Name = "Robert Deniro",
Email = _protector.Protect("[email protected]"),
Phone = "0909090909"
},
new ContactUsModel {
Name = "Maria Smith",
Email = _protector.Protect("[email protected]"),
Phone = "0808080808"
}
);
}
}
}
My current SDK and runtime versions are
6.0.100-preview.3.21202.5 [/usr/local/share/dotnet/sdk]
Microsoft.NETCore.App 6.0.0-preview.3.21201.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]