I have the below mentioned method where i am binding DataSource to the combobox control.
// floorLocnList is coming from a webservice method
private void lstFloor_BindFloor(FloorLocModel[] floorLocnList)
{
this.comboBox1.DataSource = floorLocnList;
this.comboBox1.DisplayMember = "Location";
this.comboBox1.ValueMember = "FloorLoc";
}
and class defined like this
[Serializable]
public class FloorLocModel
{
private int floorLoc;
private string location;
public int FloorLoc
{
get
{
return this.floorLoc;
}
set
{
this.floorLoc = value;
}
}
public string Location
{
get
{
return this.location;
}
set
{
this.location = value;
}
}
}
Shows Error Value Does not Fall within the Expected Range after reaching the assignment of value to ValueMember
Bug Detail:
at System.Windows.Forms.ListControl._SetDataBinding(Object newDataSource, BindingMemberInfo newDisplayMember, Boolean fForceRebind)
at System.Windows.Forms.ListControl.set_ValueMember(String value)
at IdineSmart.frmLogin.lstFloor_BindFloor(FloorLocModel[] floorLocnList)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Windows.Forms.Control.TASK.Invoke()
at System.Windows.Forms.Control._InvokeAll()
at System.Windows.Forms.Control.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.ListView.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at Microsoft.AGL.Forms.EVL.EnterModalDialog(IntPtr hwnModal)
at System.Windows.Forms.Form.ShowDialog()
at IdineSmart.frmMain.frmMain_Load(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form._SetVisibleNotify(Boolean fVis)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.Run(Form fm)
at IdineSmart.Program.Main()
It was working fine, but i dono suddenly it started giving me the problem. When i debug the code valuemember is displaying empty string even though i assigned it,might be this is the problem but how it can happen like this. Please help me.
Thanks in advance.
I'm not sure, but I think I had the same problem.
Try to change the sequence - DataSource at the end.
this.comboBox1.DisplayMember = "Location";
this.comboBox1.ValueMember = "FloorLoc";
this.comboBox1.DataSource = floorLocnList;
I Found it at last. Its all because of the error message that shown. But the actual problem was i had few user controls in the project that was targeted the platform Pocket PC 2003 SDK and the main project was targeted Pocket PC 2005 SDK. So i made all my project to target the same SDK then problem solved.
Any way thanks for the response.
Related
I am trying to run dotcover with NUnit.Console-3.9.0\nunit3-console-runner.exe as target executable.
Attached code and screenshots of my work so far.
using System;
namespace secondApp
{
public class Class1
{
public int add(int a, int b)
{
return a + b;
}
public int sub(int a, int b)
{
return a - b;
}
}
}
This is the corresponding test file.
using NUnit.Framework;
using secondApp;
namespace Tests
{
public class Tests
{
private Class1 class1;
[SetUp]
public void Setup()
{
class1 = new Class1();
}
[Test]
public void AddTest1()
{
int val = class1.add(1, 2);
Assert.AreEqual(val, 3);
}
[Test]
public void SubTest()
{
int val = class1.sub(1, 2);
Assert.AreEqual(val, -1);
}
}
}
This is the file_coverage.xml file(dotcover c file_coverage.xml), this is where the error occurs
<?xml version="1.0" encoding="utf-8"?>
<AnalyseParams>
<TargetExecutable>..\3rdparty\NUnit.Console-3.9.0\nunit3-console.exe
</TargetExecutable>
<TargetArguments>.\Testfile.nunit</TargetArguments>
<Output>output.dcvr</Output>
<Filters>
<IncludeFilters>
<FilterEntry>
<ModuleMask>*</ModuleMask>
<ClassMask>*</ClassMask>
<FunctionMask>*</FunctionMask>
</FilterEntry>
</IncludeFilters>
</Filters>
</AnalyseParams>
this is the Testfile.nunit
<NUnitProject>
<Settings activeconfig="Debug" />
<Config name="Debug" binpathtype="Auto">
<assembly path=".\bin\Debug\netcoreapp2.1\Test.dll" />
</Config>
</NUnitProject>
This is the error
dotcover c file_coverage.xml
JetBrains dotCover Console Runner 2018.2.3. Build 777.0.20180912.160624
Copyright (c) 2009-2019 JetBrains s.r.o. All rights reserved.
[JetBrains dotCover] Coverage session started [1/8/2019 12:19:36 PM]
NUnit Console Runner 3.8.0
Copyright (c) 2018 Charlie Poole, Rob Prouse
Runtime Environment
OS Version: Microsoft Windows NT 10.0.16299.0
CLR Version: 4.0.30319.42000
Test Files
c:\rough-work\secondApp\Test\Testfile.nunit
Errors, Failures and Warnings
1) Error : c:\rough-work\secondApp\Test\Testfile.nunit
NUnit.Engine.NUnitEngineException : An exception occurred in the driver while loading tests.
----> System.IO.FileNotFoundException : Could not load file or assembly 'nunit.framework' or one of its dependencies. The system cannot find the file specified.
--NUnitEngineException
Server stack trace:
at NUnit.Engine.Runners.DirectTestRunner.LoadDriver(IFrameworkDriver driver, String testFile, TestPackage subPackage)
at NUnit.Engine.Runners.DirectTestRunner.LoadPackage()
at NUnit.Engine.Runners.TestDomainRunner.LoadPackage()
at NUnit.Engine.Runners.DirectTestRunner.EnsurePackageIsLoaded()
at NUnit.Engine.Runners.DirectTestRunner.RunTests(ITestEventListener listener, TestFilter filter)
at NUnit.Engine.Runners.AbstractTestRunner.Run(ITestEventListener listener, TestFilter filter)
at NUnit.Engine.Agents.RemoteTestAgent.Run(ITestEventListener listener, TestFilter filter)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at NUnit.Engine.ITestEngineRunner.Run(ITestEventListener listener, TestFilter filter)
at NUnit.Engine.Runners.ProcessRunner.RunTests(ITestEventListener listener, TestFilter filter)
--FileNotFoundException
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)
at System.AppDomain.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)
at NUnit.Engine.Drivers.NUnit3FrameworkDriver.CreateObject(String typeName, Object[] args)
at NUnit.Engine.Drivers.NUnit3FrameworkDriver.Load(String testAssemblyPath, IDictionary`2 settings)
at NUnit.Engine.Runners.DirectTestRunner.LoadDriver(IFrameworkDriver driver, String testFile, TestPackage subPackage)
Test Run Summary
Overall result: Failed
Test Count: 0, Passed: 0, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
Start time: 2019-01-08 06:49:38Z
End time: 2019-01-08 06:49:38Z
Duration: 0.603 seconds
Results (nunit3) saved as TestResult.xml
[JetBrains dotCover] Coverage session finished [1/8/2019 12:19:40 PM]
[JetBrains dotCover] Analyzed application exited with code '-100'
[JetBrains dotCover] Coverage results post-processing started [1/8/2019 12:19:40 PM]
[JetBrains dotCover] Coverage results post-processing finished [1/8/2019 12:19:40 PM]
The path to your test file suggests it is a .NET Core file. It is not possible to execute .NET Core tests from the NUnit3-console runner at this time, you have to use dotnet test instead.
Your exception logs says that it could not find nunit.framework assembly, please check if its present in the references, if it is then go to Tools -> Options -> test and uncheck the option as highlighted in the below screenshot:
Let me know if it helps.
I received the following error message when running SSIS package. The Script Task is using Microsoft Visual C# 2008. Can you please help me to fix the problem?
Thank you very much! I also attach error message:
Error: 2015-12-22 02:58:08.28
Code: 0x00000001
Source: Script Task
Description: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
at System.Windows.Forms.MessageBox.ShowCore(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, Boolean showHelp)
at System.Windows.Forms.MessageBox.Show(String text)
at ST_d27b216cd7d64713b54c81f6ac28d805.csproj.ScriptMain.Main()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
End Error
DTExec: The package execution returned DTSER_FAILURE (1).
C# code:
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
namespace ST_d27b216cd7d64713b54c81f6ac28d805.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
#region VSTA generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
public void Main()
{
// TODO: Add your code here
System.IO.FileInfo fi;
String FilePath = null;
DateTime ModifiedTime = (DateTime)Dts.Variables["File_Modified"].Value;
DateTime LoadDate = (DateTime)Dts.Variables["File_Last_Load_Date"].Value;
Dts.Variables["isModified"].Value = false;
FilePath = Dts.Variables["SourceFolder"].Value.ToString();
ModifiedTime = System.IO.File.GetLastWriteTime(FilePath);
Dts.Variables["File_Modified"].Value = ModifiedTime;
// fi.LastWriteTime;
int result = DateTime.Compare(ModifiedTime, LoadDate);
if (result > 0)
{
MessageBox.Show("File Modified after last load in staging");
Dts.Variables["isModified"].Value = true;
}
else
{
MessageBox.Show("file is not modified since last load");
Dts.Variables["isModified"].Value = false;
}
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}
The error message extracted from your stack trace is:
Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
You have to remember that although when you are debugging your SSIS package you have a nice UI (BIDS or SQL Server Tools shells depending on your environment) but really it is not designed to be have a UI. What would you expect to happen when this package is deployed to a server and called by a SQL Job? i.e. Where would the message box show? Who would click "OK" to allow the thread to resume?
You probably want to just fire an information event if you are looking to post feedback, something like:
bool fireAgain = false;
Dts.Events.FireInformation(0, "Script Task", "File Modified after last load in staging", String.Empty, 0, ref fireAgain);
The error is raised because your script task is trying to display a message box and showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Therefore if you want to output a message, you could use Dts.Log instead, see the MSDN documentation for further details.
I add an Image to my project resources (Windows Mobile 6.1). I want to use this image to set the PictureBox.Image property of some PictureBoxes I have in my Form. I try the following code:
pictureBox1.Image = Properties.Resources.my_image;
pictureBox2.Image = Properties.Resources.my_image;
pictureBox3.Image = Properties.Resources.my_image;
...
pictureBoxN.Image = Properties.Resources.my_image;
The problem is that sometimes the image is displayed only in some of the PictureBox (I get a TargetInvocationException when I try to set the image), and not in all. Why? How can I solve this problem?
EDIT:
The StackTrace of the InnerException:
in Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR ar) in
System.Drawing.Bitmap._InitFromMemoryStream(MemoryStream mstream) in
System.Drawing.Bitmap..ctor(Stream stream) in
System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo
rtci, BindingFlags invokeAttr, Binder binder, Object parameters,
CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean
verifyAccess, StackCrawlMark& stackMark) in
System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
in System.Reflection.ConstructorInfo.Invoke(Object[] parameters) in
System.Resources.ResourceReader.CreateResource(Type objType, Type[]
ctorParamTypes, Object[] ctorParameters) in
System.Resources.ResourceReader.LoadBitmap(Int32 typeIndex) in
System.Resources.ResourceReader.LoadObjectV2(Int32 pos,
ResourceTypeCode& typeCode) in
System.Resources.ResourceReader.LoadObject(Int32 pos,
ResourceTypeCode& typeCode) in
System.Resources.RuntimeResourceSet.GetObject(String key, Boolean
ignoreCase) in System.Resources.ResourceManager.GetObject(String name,
CultureInfo culture) in
Icons_Control.Properties.Resources.get_glass_empty() in
Icons_Control.ListItem.set_CompletitionStatus(eCompletionStatus value)
in Icons_Control.ListItem..ctor() in
Icons_Control.ListItem..ctor(eItemType type) in
Icons_Control.MainForm.menuItem3_Click(Object sender, EventArgs e) in
System.Windows.Forms.MenuItem.OnClick(EventArgs e) in
System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32
wParam, Int32 lParam) in System.Windows.Forms.Form.WnProc(WM wm, Int32
wParam, Int32 lParam) in
System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam,
Int32 lParam) in Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
in System.Windows.Forms.Application.Run(Form fm) in
Icons_Control.Program.Main()
My guess is that you are running out of memory or other resources. Image resources are a bit dangerous. Every time you get a resource, a new one is created. You're likely only wanting to create one instance of my_image, and you likely want to dispose of it after you are done using it.
Image myImage = Properties.Resources.my_image;
pictureBox1.Image = myImage;
pictureBox2.Image = myImage;
pictureBox3.Image = myImage;
pictureBox4.Image = myImage;
...
pictureBoxN.Image = myImage;
// Later on when you are done using it
myImage.Dispose();
Very important on most CF apps to not waste memory.
I'm writing an app which need to download very large size files (usually more than 150MB) into the machine. I knew that the WebClient has buffer limit and able to be used in my case. Therefore, I followed the way of using HttpWebRequest to write my download function in here: http://dotnet.dzone.com/articles/2-things-you-should-consider?mz=27249-windowsphone7. The following is my code:
private void _downloadBook(string _filePath)
{
Uri _fileUri = new Uri(_filePath);
//DownloadFileName = System.IO.Path.GetFileName(_fileUri.LocalPath);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_fileUri);
request.AllowReadStreamBuffering = false;
request.BeginGetRequestStream(new AsyncCallback(GetData), request);
}
private void GetData(IAsyncResult result)
{
HttpWebRequest request = (HttpWebRequest)result.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
Stream str = response.GetResponseStream();
byte[] data = new byte[16 * 1024];
int read;
long totalValue = response.ContentLength;
while ((read = str.Read(data, 0, data.Length)) > 0)
{
if (streamToWriteTo.Length != 0)
Debug.WriteLine((int)((streamToWriteTo.Length * 100) / totalValue));
streamToWriteTo.Write(data, 0, read);
}
streamToWriteTo.Close();
Debug.WriteLine("COMPLETED");
}
However, it threw the ProtocolViolationException with the following stack:
System.Net.ProtocolViolationException was unhandled
Message=ProtocolViolationException
StackTrace:
at System.Net.Browser.ClientHttpWebRequest.InternalBeginGetRequestStream(AsyncCallback callback, Object state)
at System.Net.Browser.ClientHttpWebRequest.BeginGetRequestStream(AsyncCallback callback, Object state)
at HHC_EbookReaderWP7.ComicPage._downloadBook(String _filePath)
at HHC_EbookReaderWP7.ComicPage.b__2()
at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Delegate.DynamicInvokeOne(Object[] args)
at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)
Anything wrong with my code? or do I need to further on it? Thanks.
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.begingetrequeststream.aspx
As adontz mentioned. Give us the exact line that throws the exception. And according the silverlight doc. you need to call begingetresponsestream instead of the sync. getresponsestream. It also shows you some reasons for a protocol violationexception. Check this with the WP7 documentation.
To get the exact line of the exception, goto Debug In the top menu bar of vs2010 and goto Exceptions and enable the checkboxes for "Thrown"
Hope this helps.
I would like to parse some JSON:
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(e.Result)))
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(STMsgObj));
STMsgObj[] messages = (STMsgObj[])serializer.ReadObject(stream);
foreach(STMsgObj aMsg in messages){
MessageBox.Show(aMsg.body, "Data Passed", MessageBoxButton.OK);
}
}
}
How can I convert e.Result into a stream?
Exception:
System.InvalidCastException was unhandled
Message=InvalidCastException
StackTrace:
at StockTwits.ViewModels.StreamPage.webClient_DownloadStringCompleted(Object sender, DownloadStringCompletedEventArgs e)
at System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e)
at System.Net.WebClient.DownloadStringOperationCompleted(Object arg)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Delegate.DynamicInvokeOne(Object[] args)
at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)
Try the following:
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(e.Result)))
{
// Your code here, using stream.
}
Call DownloadDataAsync instead.
You can then pass new MemoryStream(e.Result) from the DownloadDataCompleted event.
If you really want to stick with DownloadStringAsync, you can pass XmlReader.Create(new StringReader(e.Result)).
Given that WebClient wraps an API that is already stream based means there are a number of unnecessary conversions. You might want to consider swapping your WebClient for plain old HttpWebRequest, which hands you a stream out of the box.
HttpWebRequest req=(HttpWebRequest)WebRequest.Create(myUrl);
using(var resp=req.GetResponse())
using(var stream=resp.GetResponseStream())
{
...
}
Your JSON data isn't an array.