ThinkGeo.com    |     Documentation    |     Premium Support

User control Exception

Hai


am using WPF component, am using it in user control, when i run the usercontrol seperately its working fine, when am trying to call the user control in the another form am getting exception in runtime. what the reason is??


The below exception is thrown when am tryinhg to use that user control in another form,.


System.ArgumentException was unhandled

  Message="An item with the same key has already been added."

  Source="mscorlib"

  StackTrace:

       at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)

       at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)

       at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)

       at ThinkGeo.MapSuite.Core.GeoCollection`1.Add(String key, T item)

       at TAMIS.AccuracyReportControl.loadMap() in D:\Development\dep\AccuracyReportControl.xaml.cs:line 152

       at TAMIS.AccuracyReportControl.UserControl_Loaded(Object sender, RoutedEventArgs e) in D:\Development\dep\AccuracyReportControl.xaml.cs:line 77

       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)

       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)

       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)

       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)

       at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)

       at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)

       at MS.Internal.LoadedOrUnloadedOperation.DoWork()

       at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()

       at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()

       at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)

       at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)

       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)

       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

       at System.Windows.Threading.DispatcherOperation.InvokeImpl()

       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)

       at System.Threading.ExecutionContext.runTryCode(Object userData)

       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)

       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

       at System.Windows.Threading.DispatcherOperation.Invoke()

       at System.Windows.Threading.Dispatcher.ProcessQueue()

       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)

       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)

       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)

       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)

       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)

       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)

       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)

       at System.Windows.Threading.Dispatcher.Run()

       at System.Windows.Application.RunDispatcher(Object ignore)

       at System.Windows.Application.RunInternal(Window window)

       at System.Windows.Application.Run(Window window)

       at System.Windows.Application.Run()

       at TAMIS.App.Main() in D:\Development\dep\obj\Release\App.g.cs:line 0

       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

       at System.Threading.ThreadHelper.ThreadStart()

  InnerException: 

 



Deep, 
  
 Thanks for your post. 
  
 Which version are you using now? Could you send me your sample application to recreate this problem, which would be very helpful for us to fix this problem. 
  
 Thanks. 
  
 Yale 


Deep, 
  
 It seems the exception is not caused by our MapSuite Wpf component, becuase from your stack trace of exception, I can not find any method of MapSuite. Or you might provide the wrong stack trace or stack trace is not entire one just part of them. 
  
 Hope you could provide more information to us that can help us solve your problem. 
  
 Thanks 
 James

Hai Yale and James, 



Thanks for your reply, the code is working good, but when i convert it into user control it arises some exception, as u said i here attached the two samples, one is normal one which working good without user control 

normal sample with out usercontrol. 

cid-08ec3041618e8ee4.skydrive.live.com/self.aspx/.SharedFavorites/Normal%20sample.rar 





the problem one is user control one. plz take a look into this. i jus migrated the normal sample to usercontorl one. after that it throws exception in map layer and finding the feature layer. U can see the output and workable model in normal sample, so i attached that too ain above link. 

User Control Sample 

cid-08ec3041618e8ee4.skydriv...sample.rar



Posted By Yale on 03-17-2010 03:05 AM 

Deep, 



Thanks for your post. 



Which version are you using now? Could you send me your sample application to recreate this problem, which would be very helpful for us to fix this problem. 



Thanks. 



Yale 




Hi yale,

plz check this sample


cid-08ec3041618e8ee4.skydriv…sample.rar



 


Deep,
 
I can recreate your problem, I compare two samples and I found the reason that you get the exception.
 
In the second sample, you put MapSuite Wpf control to the MapUserControl, and add MapUserControl to the main Window, I think it's fine. The problem is that you create another member variable MapUserControl in UserControl1, it's the same as you create a new WpfMap and call Refresh(). I am afraid it's not working if you choose this way, the right way is that drag the WpfMap control to a container and after InitializeComponent then the Refresh method that can work.
 
The correct way is using the MapUserControl which is already in main Window, I name it mapUserControl, and call mapUserControl.getFileandLoad("Default"); I have modied a little with your second sample and add another button to make it works.
 
Please let me know If you have more questions.
 
Thanks
James

1879-WpfMapSample_Updated1.zip (12.5 KB)

Yes james. its working,you placed the new button in the main window, but i want that button("Use This one")  to be placed  inside the usercontrol.  
 map Viewer is one user control, map file selector is another user control, am using this two user control in one main form, if we select any file in selector control that should be viewable in map viewer control, is it possible to place that button inside the user control, coz i have tried lot and hanging with diff diff exceptions. so can u see how it will be possible???

Deep.


There are many ways to match your requirements, I have an idea that you can define a static delegate and then you can access the private method in another UserControl. Please look at my updated code for detail.


Thanks


James


 



1880-WpfMapSample_Updated2.zip (12.6 KB)

Hai 
  
 This is first time am using your component, i not yet read the documentation of this map suite also,coz am in rush to do this. i searched many components and finally choose yours and directly started my development, so i thought some layer concepts of your suite throwng error., so i pinged u, but it seems my mistake, 
  
 Thanks James 
  


Deep, 
  
 Thanks for your patience, is updated2 sample solve your problem? Please let me know if anything I can help. 
  
 James

james i sent a query to ur sales team before two days, but i didnt get any response ya. is it possible for u to reach my mail id. i need to clarify somethings from you.

Deep, 
  
 I will let them know this thing, and how do you send the query to them? If you email them, please verify the mail address is right or not?  
 My responsibility is solve the client’s problem at here, so if you want to clarify something please create another topic and I will reply you. 
  
 Thanks 
 James