Problem solved. I've put my site on apache server (copy ProjectName.web
folder and run ProjectNameTestPage.html
) and now it works.
Silverlight opening relative URI - works when debugging, fails when running outside VS
-
27-11-2021 - |
Question
My Silverlight project uses dane.xml
file, which is located in ProjectName.Web/Client.Bin/dane.xml
private void ReadXML()
{
WebClient client1 = new WebClient();
client1.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client1_DownloadStringCompleted);
link = new Uri("dane.xml", UriKind.Relative);
client1.DownloadStringAsync(filePath);
}
void client1_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.ToString() + "\n\nURI=" + link.ToString());
return;
}
// (...)
}
Everything is working fine when I run it from Visual Studio (Debug or Start without debugging). But now I'd like to start it outside VS, so I ran ProjectName.Web/ProjectNameTestPage.html
- and loading dane.xml
file failed, with following error from MessageBox:
Error when loading file dane.xml
System.Net.WebException: An exception occurred during a WebClient request.
---> System.NotSupportedException: The URI prefix is not recognized.
in System.Net.WebRequest.Create(Uri requestUri)
in System.Net.WebClient.GetWebRequest(Uri address)
in System.Net.WebClient.DownloadStringAsync(Uri address, Object userToken)
(...)URI=dane.xml
What should I do to fix that?
I've already tried setting dane.xml
in Solution Explorer as Resource and creating new Uri("ProjectName;component/dane.xml", UriKind.Relative);
, but it fails when running on Visual Studio.
La solution