Application.GetResourceStream引发IOException [英] Application.GetResourceStream throws IOException
问题描述
我正在使用版本历史记录"对话框,并创建了一个示例来对其进行测试.但是,该示例似乎找不到HTML文件:
I'm working on a Version History dialog box, and I created a sample to test it. It seems, however, that the sample can't find the HTML file:
var dlg = new VersionHistoryDialog();
var uri = new Uri(@"pack://application:,,,/VersionHistory.html", UriKind.Absolute);
var source = Application.GetResourceStream(uri).Stream; // This line throws the error
dlg.Stream = source;
var result = dlg.ShowDialog();
label1.Content = result;
上面代码中的那一行抛出此错误:
That line in the code above throws this error:
System.IO.IOException was unhandled
Message=Cannot locate resource 'versionhistory.html'.
Source=PresentationFramework
StackTrace:
at MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode mode, FileAccess access)
at System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access)
at System.IO.Packaging.PackagePart.GetStream()
at System.Windows.Application.GetResourceStream(Uri uriResource)
....
那么....我该怎么办?该文件名为"VersionHistory.html
",它与xaml.cs
文件要求相同的文件夹(视图")中.
So.... what do I do? The file is named "VersionHistory.html
" and its in the same folder ("Views") as the xaml.cs
file asking for it.
推荐答案
您需要包括资源的程序集和路径:
You need to include the assembly and path of the resource:
例如:
Application.GetResourceStream(new Uri("/SilverlightApplication;component/EmbeddedInApplicationAssembly.png", UriKind.Relative)))
使用包装和您的示例,您可以指定:
With the pack and your example, you could specify:
Application.GetResourceStream(new Uri("pack://application:,,,/View/versionhistory.html"))
,以下内容也应该起作用:
and the following should also work:
Application.GetResourceStream(new Uri("/XYZ;component/View/versionhistory.html", UriKind.Relative)))
请参见 http://msdn.microsoft.com/zh-cn/library/ms596994(VS.95).aspx 和 http://msdn.microsoft.com/zh-cn/library/aa970069.aspx 了解更多信息.
See http://msdn.microsoft.com/en-us/library/ms596994(VS.95).aspx and http://msdn.microsoft.com/en-us/library/aa970069.aspx for more information.
这篇关于Application.GetResourceStream引发IOException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!