在覆盖FileConfigurationProvider时,将System.IO.Stream用作不兼容类型

时间:2017-05-19 18:14:17

标签: c# asp.net-web-api resharper .net-core visual-studio-2017

我正在尝试为.Net Core WebApi应用程序中的某些配置元素创建自定义FileConfigurationProvider实现。

它看起来像这样..

public class MyProvider : FileConfigurationProvider
{
    public MyProvider(FileConfigurationSource source) : base(source) { }

    public override void Load(Stream stream)
    {
        try
        {
          // Stream reading things
        }
        catch
        {
            throw new Exception("Failed to load stream.");
        }
    }
}

尽管这个例子简单,但是Load(Stream stream)的覆盖在VS2017中给出了一个指示器,表明没有合适的覆盖方法。此外,另一个错误提示表明FileConfigurationProvider(System.IO.Stream) is not implemented

使用ReSharper向代理提取已显示调用Load(Stream stream)的新提示,指出Argument type System.IO.Stream [System.IO, Version=4.1.0.0...] is not assignable to parameter of type System.IO.Stream [System.Private.CoreLib, Version=4.0.0.0...]

尽管有这些错误提示,我仍然可以成功构建并运行此代码。

有人可以帮我理解这里有什么问题吗?

csproj如下..

    <Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="1.1.2" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.2" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
  </ItemGroup>

</Project>

我也试过在框架defs中更明确......

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
    <RuntimeFrameworkVersion>1.1.2</RuntimeFrameworkVersion>
  </PropertyGroup>

1 个答案:

答案 0 :(得分:7)

JetBrains错误跟踪器https://youtrack.jetbrains.com/issue/RSRP-464676

中存在错误