问题描述:

When I trying for unit testing,

I ended up error stating 'System.UriFormatException : Invalid URI: Invalid port specified.'

Code which showing error is ,

 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

};

Can anyone help me to solve this.

网友答案:

That's because you're executing this code while the pack:// scheme is not yet registered. This scheme is registered when you create the Application object. You can add this code in the setup of your test fixture:

 [SetUp]
  public void OnTestInitialize()
  {
      UriParser.Register(new GenericUriParser(
      GenericUriParserOptions.GenericAuthority), "pack", -1);
  }
相关阅读:
Top