Вопрос

I am using Out of Browser Application in silverlight.

I have problem while loading xml file usine below mentioned code.

string contentUri = Application.Current.Host.Source
            .AbsoluteUri;
        var contentUri1 = contentUri.Substring(0, contentUri.LastIndexOf("/")) + "/Hello1.xml";

        WebClient wc = new WebClient();
        wc.OpenReadCompleted+=(open,read)=>
        {


            string content;
            using (StreamReader reader = new StreamReader(read.Result,Encoding.Unicode))
            {
                byte[] m_Bytes = ReadToEnd(read.Result);
                string s = Encoding.UTF8.GetString(m_Bytes, 0, m_Bytes.Length);
            }

        };
        wc.DownloadProgressChanged
            += (chang,dh)=>
          {

            };
        wc.OpenReadAsync(new Uri(contentUri));

where my xml file contained

<Root>
<element>FirstElement</element>
</Root>

I got the garbage value as output can anyone please help me how can i download that original xml content?

Это было полезно?

Решение

When you invoke webclient calls on Out-Of-Browser mode it suppose that you have already RootVisual Created, because webclient will run on its Dispatcher apparently. If not, you end up with no response from server, and what is strange, even exception is not thrown !!

Anyway, this Post from Jeremy explains details:

http://csharperimage.jeremylikness.com/2010/05/webclient-and-deploymentcatalog-gotchas.html

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top