System.UriFormatException:无效的 URI:指定的端口无效。在 c# 中

Zad*_*xmi 1 c# nunit unit-testing

当我尝试进行单元测试时,

我最终出现错误,指出“System.UriFormatException:无效的 URI:指定的端口无效。” 显示错误的代码是,

  public Dictionary<SensorMode, Uri> ImageSrc = new Dictionary<SensorMode, Uri>()
        {
            {SensorMode.f, new Uri("pack://application:,,,/Resources/TS.png") },//towards to sensor image
            {SensorMode.b, new Uri("pack://application:,,,/Resources/AS.png") },//away from the sensor image
            {SensorMode.c, new Uri("pack://application:,,,/Resources/F.png") },//fast moving image
            {SensorMode.p, new Uri("pack://application:,,,/Resources/S.png") },//slow moving image
            {SensorMode.x, new Uri("pack://application:,,,/Resources/fail.png")}//fail image 
        };
Run Code Online (Sandbox Code Playgroud)

谁能帮我解决这个问题。

Zad*_*xmi 6

这是因为您在 pack:// 方案尚未注册时执行此代码。该方案在您创建 Application 对象时注册。您可以在测试装置的设置中添加以下代码:

 [SetUp]
  public void OnTestInitialize()
  {
      UriParser.Register(new GenericUriParser(
      GenericUriParserOptions.GenericAuthority), "pack", -1);
  }
Run Code Online (Sandbox Code Playgroud)