Skip to content

C# compiler should report CS7003 (or similar) when call to IServiceProvider.GetService<T>() is missing generic type argument and is followed by another call #41779

@jpd30

Description

@jpd30

Version Used:

Microsoft .NET Core SDK 3.1.100 (x64)
Microsoft Visual Studio Community 2019 16.4.2

Steps to Reproduce:

Build the attached project FailedToEmitModule.zip
, or:

  1. Create a new .NET Core console app
  2. Add <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.2" /> to the .csproj file
  3. Copy the following into Program.cs:
using System;
using Microsoft.Extensions.DependencyInjection;

namespace FailedToEmitModule
{
    public static class Program
    {
        public static void Main()
        {
            IServiceProvider serviceProvider = null;
            var foo = serviceProvider.GetService<>().Foo();
        }
    }
}
  1. Build the project

Expected Behavior:

Build error along the lines of:

Program.cs(11,8,11,44): error CS7003: Unexpected use of an unbound generic name

This behaviour can be observed by removing the call to Foo().

Actual Behavior:

Build error:

CSC : error CS7038: Failed to emit module 'FailedToEmitModule'

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions