Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 运行MSBuild时发生内部故障-无法加载文件或程序集System.Net.Primitives_C#_Asp.net Core_Msbuild_Asp.net Core 5.0 - Fatal编程技术网

C# 运行MSBuild时发生内部故障-无法加载文件或程序集System.Net.Primitives

C# 运行MSBuild时发生内部故障-无法加载文件或程序集System.Net.Primitives,c#,asp.net-core,msbuild,asp.net-core-5.0,C#,Asp.net Core,Msbuild,Asp.net Core 5.0,使用XUnit和Asp.Net Core 5,我进行了以下测试: public class Tests : IClassFixture<ServiceProviderFixture> { private readonly ServiceProviderFixture _fixture; public IndicatorsTests(ServiceProviderFixture fixture) { _fixture = fixture; } [Fact]

使用XUnit和Asp.Net Core 5,我进行了以下测试:

public class Tests : IClassFixture<ServiceProviderFixture> {

  private readonly ServiceProviderFixture _fixture;

  public IndicatorsTests(ServiceProviderFixture fixture) {
    _fixture = fixture;
  }

  [Fact]
  public async Task FirstTest() {
    IEnumerable<Decimal> values = await _fixture.Provider.GetService<ICsvImporter>().ImportAsync("Values.csv");
    Assert.Equal(1000, values.Count());
  }

}
ServiceProviderFixture
类是:

public class ServiceProviderFixture : IDisposable {

  public IServiceProvider Provider { get; private set; }

  public ServiceProviderFixture() {

    IServiceCollection services = new ServiceCollection();

    services.AddSingleton<CsvImporterConfiguration>();

    services.AddTransient<ICsvImporter, CsvImporter>();

    Provider = services.BuildServiceProvider();

  }

  public void Dispose() { } // Dispose

}
public class CsvImporter : ICsvImporter {

  private readonly CsvImporterConfiguration _configuration;

  public CsvImporter(CsvImporterConfiguration configuration) {

    _configuration = configuration;

  }

  public CsvImporter(Action<CsvImporterConfiguration> configuration) {

    _configuration = new CsvImporterConfiguration();

    configuration(_configuration);

  } 

  public async Task<IEnumerable<Decimal>> ImportAsync(String path, CancellationToken token = default(CancellationToken)) {

    return await Task.Factory.StartNew(() => {

      using (StreamReader stream = new StreamReader(path)) {

        using (CsvReader csv = new CsvReader(stream, new CsvConfiguration(_configuration.Culture) { 
          Delimiter = _configuration.Delimiter
        })) {

        return csv.GetRecords<Decimal>();

        }

      }

      }, token);

    }

  }
我错过什么了吗


可能是通过读取文件?

这是MacOS上的一个已知问题

这似乎在安装防病毒软件时最常见

我见过几个这样的案例。我找到的唯一“修复”方法是卸载防病毒软件。在某些情况下,我们不得不重新安装MacOS


如果您不在MacOS上,请告诉我们。

尝试使用查找程序集无法加载的原因。您是否在Windows上运行此程序?是否可以发布您的.csproj?我想看看您的TargetFramework设置为什么。您的问题中缺少一些内容,无法轻松重现您的体验。出于好奇,您使用的是什么csv软件包?你有没有考虑过Josh Close的CsvHelper,它非常快!
public class CsvImporter : ICsvImporter {

  private readonly CsvImporterConfiguration _configuration;

  public CsvImporter(CsvImporterConfiguration configuration) {

    _configuration = configuration;

  }

  public CsvImporter(Action<CsvImporterConfiguration> configuration) {

    _configuration = new CsvImporterConfiguration();

    configuration(_configuration);

  } 

  public async Task<IEnumerable<Decimal>> ImportAsync(String path, CancellationToken token = default(CancellationToken)) {

    return await Task.Factory.StartNew(() => {

      using (StreamReader stream = new StreamReader(path)) {

        using (CsvReader csv = new CsvReader(stream, new CsvConfiguration(_configuration.Culture) { 
          Delimiter = _configuration.Delimiter
        })) {

        return csv.GetRecords<Decimal>();

        }

      }

      }, token);

    }

  }