2016-12-21 5 views
0

Wenn ich für Unit-Test,System.UriFormatException: Ungültiger URI: Ungültiger Port angegeben. in C#

Ich endete Fehler 'System.UriFormatException: ungültiger URI: ungültiger Port angegeben.' -Code, der Fehler zeigt, ist,

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 
     }; 

Kann mir jemand helfen, dieses Problem zu lösen.

Antwort

1

Das liegt daran, dass Sie diesen Code ausführen, während das Schema pack: // noch nicht registriert ist. Dieses Schema wird registriert, wenn Sie das Anwendungsobjekt erstellen. Sie können diesen Code im Setup Ihres Testgeräts hinzufügen:

[SetUp] 
    public void OnTestInitialize() 
    { 
     UriParser.Register(new GenericUriParser(
     GenericUriParserOptions.GenericAuthority), "pack", -1); 
    } 
Verwandte Themen