Skip to content

DispatchProxy.Create reads AssemblyLoadContext.Name but treats it as an assembly name #80387

@philiphendry

Description

@philiphendry

Describe the bug

An msbuild task that calls a WCF service errors when running with dotNet 7.0. This occurred after a Visual Studio upgrade which delivered dotNet 7.0 alongside the already installed dotNet 6.0.

To Reproduce

Here I've attached a minimalist project that reproduces the issue:
DotNet7BuildBug.zip

To see the problem follow these steps:

  1. Ensure dotNet Core SDK 7.0 is installed.
  2. Load the solution into Visual Studio
  3. Run dotnet publish .\BuildTools\ from the root folder.
  4. Run dotnet msbuild .\Test.msbuild. This highlights the issue being raised and raises the exception shown below.

We are currently working around this problem by adding a global.json targeting the core 6.0 runtime and this can be demonstrated in the attached application by renaming the provided global.json.bak file. Before running the msbuild, start the WcfServiceLibrary so the service host is available and this will allow the mean the msbuild will run without error.

Exceptions (if any)

C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018: The "LoadTask" task failed unexpectedly.
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018: System.IO.FileLoadException: The given assembly name was invalid.
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018: File name: 'DispatchProxyTypes.MSBuild plugin C:\temp\DotNet7BuildBug\BuildTools\bin\Debug\net6.0\publish\BuildTools.dll'
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.Reflection.AssemblyNameParser.ThrowInvalidAssemblyName()
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.Reflection.AssemblyNameParser.GetNextToken(String& tokenString)
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.Reflection.AssemblyNameParser.Parse()
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.Reflection.AssemblyNameParser.Parse(String name)
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.Reflection.AssemblyName..ctor(String assemblyName)
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.Reflection.DispatchProxyGenerator.ProxyAssembly..ctor(AssemblyLoadContext alc)
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.Reflection.DispatchProxyGenerator.<>c.<CreateProxyInstance>b__6_0(AssemblyLoadContext x)
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValueLocked(TKey key, CreateValueCallback createValueCallback)
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValue(TKey key, CreateValueCallback createValueCallback)
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.Reflection.DispatchProxyGenerator.CreateProxyInstance(Type baseType, Type interfaceType)
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.Reflection.DispatchProxy.Create[T,TProxy]()
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.ServiceModel.Channels.ServiceChannelProxy.CreateProxy[TChannel](MessageDirection direction,ServiceChannel serviceChannel)
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.ServiceModel.Channels.ServiceChannelFactory.CreateProxy[TChannel](MessageDirection direction, ServiceChannel serviceChannel)
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.ServiceModel.Channels.ServiceChannelFactory.CreateChannel[TChannel](EndpointAddress address, Uri via)
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via)
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.ServiceModel.ChannelFactory`1.CreateChannel()
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.ServiceModel.ClientBase`1.CreateChannel()
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.ServiceModel.ClientBase`1.CreateChannelInternal()
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at System.ServiceModel.ClientBase`1.get_Channel()
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at ServiceReference1.Service1Client.GetDataAsync(Int32 value) in C:\temp\DotNet7BuildBug\BuildTools\Connected Services\ServiceReference1\Reference.cs:line 116
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at BuildTools.LoadTask.Execute() in C:\temp\DotNet7BuildBug\BuildTools\LoadTask.cs:line 10
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
C:\temp\DotNet7BuildBug\Test.msbuild(7,9): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)

Further technical details

Output from dotnet --info:

.NET SDK:
 Version:   7.0.101
 Commit:    bb24aafa11

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.101\

Host:
  Version:      7.0.1
  Architecture: x64
  Commit:       97203d38ba

.NET SDKs installed:
  3.1.426 [C:\Program Files\dotnet\sdk]
  5.0.403 [C:\Program Files\dotnet\sdk]
  5.0.408 [C:\Program Files\dotnet\sdk]
  5.0.410 [C:\Program Files\dotnet\sdk]
  6.0.200 [C:\Program Files\dotnet\sdk]
  6.0.202 [C:\Program Files\dotnet\sdk]
  6.0.203 [C:\Program Files\dotnet\sdk]
  6.0.301 [C:\Program Files\dotnet\sdk]
  6.0.302 [C:\Program Files\dotnet\sdk]
  6.0.307 [C:\Program Files\dotnet\sdk]
  6.0.401 [C:\Program Files\dotnet\sdk]
  6.0.404 [C:\Program Files\dotnet\sdk]
  7.0.101 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.24 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.28 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.29 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Visual Studio version information:

Microsoft Visual Studio Enterprise 2022
Version 17.4.3
VisualStudio.17.Release/17.4.3+33205.214
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Enterprise

Visual C++ 2022   00476-80000-00000-AA277
Microsoft Visual C++ 2022

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASA Service Provider   1.0

ASP.NET and Web Tools   17.4.326.54890
ASP.NET and Web Tools

Azure App Service Tools v3.0.0   17.4.326.54890
Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio   2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   17.4.326.54890
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   4.4.0-6.22580.4+d7a61210a88b584ca0827585ec6e871c6b1c5a14
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

File Differ   3.0.43
The easiest way to diff two files directly in Solution Explorer

File Icons   2.7
Adds icons for files that are not recognized by Solution Explorer

iMeta CLM Cdmu Editor   1.0
A Cdmu rule editor for iMeta CLM modules.

iMeta CLM Csx Rule Editor   1.0
A Csx rule editor for iMeta CLM modules.

iMeta CLM User Group Config Editor   1.0
Editor for iMeta CLM module User Group Configuration

Microsoft Azure Hive Query Language Service   2.6.5000.0
Language service for Hive query

Microsoft Azure Stream Analytics Language Service   2.6.5000.0
Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio   2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Node.js Tools   1.5.40817.1 Commit Hash:66443775f9f3b1d8f8fee47af5002828b346688d
Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager   6.4.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core)   17.0.0.2246202+61cc048d36a3fc9246d2f04625988b19a18ab8f0
Provides languages services for ASP.NET Core Razor.

RuleVisualiserWindow Extension   1.0
RuleVisualiserWindow Visual Studio Extension Detailed Info

SQL Server Data Tools   17.0.62207.28050
Microsoft SQL Server Data Tools

SVG Viewer   1.0.16
Makes it much easier to work with SVG files by showing a live preview in the bottom-right corner of the code window

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   17.0.10921.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.4.0-6.22580.4+d7a61210a88b584ca0827585ec6e871c6b1c5a14
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   17.4.0-beta.22512.4+525d5109e389341bb90b144c24e2ad1ceec91e7b
Microsoft Visual F# Tools

Visual Studio Extension for SpecFlow   1.0
Visual Studio extension for working with SpecFlow projects and Gherkin feature files.

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.

VSColorOutput64   2022.2
Color output for build and debug windows - https://mike-ward.net/vscoloroutput

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions