用作Uri的參數的程序集限定字符串在XAML中工作,但給我在代碼中使用時顯示的錯誤。UriFormatException:無效的URI:指定的端口無效
我試過每種UriKind都有相同的結果。我怎樣才能解決這個問題?
[Test]
public void LargeImageSource_IsKnown()
{
var uri = new Uri(
"pack://application:,,,/" +
"MyAssembly.Core.Presentation.Wpf;component/" +
"Images/Delete.png", UriKind.RelativeOrAbsolute);
Assert.That(
_pickerActivityCollectionVm.DeleteActivityCommand.LargeImageSource,
Is.EqualTo(uri));
}
System.UriFormatException : Invalid URI: Invalid port specified.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString, UriKind uriKind)
UPDATE
基於托馬斯高超的答案,關於可讀性我自己的意見,我結束了用我的BaseTestFixture類以下。希望這可以幫助別人。
protected virtual void OnFixtureSetUp() {
// logging, other one time setup stuff...
const string scheme = "pack";
if (!UriParser.IsKnownScheme(scheme)) {
Assert.That(PackUriHelper.UriSchemePack, Is.EqualTo(scheme));
}
}
作爲FYI注意:我現在面臨使用託管到本機進程WPF窗口同樣的問題。 – 2012-09-10 10:59:21