Operation is not valid due to the current state of the object.

Apr 22, 2009 at 8:36 AM

I have installed the latest version of Virtual Earth 3D and the latest build released yesterday.  I can run the sample provided for WPF and all works well, however when I add InfoStrat.VE to my project and add a map to a use control i get the following error when the user control loads:

Operation is not valid due to the current state of the object.

public void InitRenderEngine()
             this.Host.RenderEngine.ManuallyInitializeRender(); ------- BREAKS HERE

            PositionStep positionStep = new PositionStep(this.Host.RenderEngine.StepManager);

            this.Host.RenderEngine.StepManager.InsertBefore(typeof(RenderStep), positionStep);


Is this something anone else has experience, any ideas?

Many thanks

Apr 23, 2009 at 5:45 PM
Can you confirm that you can go to http://maps.live.com, click 3D, and the 3D control loads? 

What version of Windows are you running?
Apr 23, 2009 at 7:41 PM
Hi Josh,

Our build was working fine with the previous release of Infostrat.VE and the previous version of Virtual Earth 3D. 

The machine is Vista Home Premium SP1.

I went to http://maps.live.com and clicked 3D and it works fine.

All that has been changed is a) updated to latest VE 3D and b) replaced the InfoStrat.VE project.

I can actually run the sample you provide, but when i put the control in a user control within our application it fails.  Which was working ok before.

Any ideas would be appreciated.



Apr 23, 2009 at 8:11 PM
Can you email me a minimal application where this error occurs?  If I can reproduce the issue locally then it would be much easier to fix.

joshblake at gmail dot com

Apr 28, 2009 at 3:00 PM
Hi Josh,

I actually cannot email you an application, the project is very large and part of our main build.  The full error is:

System.InvalidOperationException was unhandled by user code
  Message="Operation is not valid due to the current state of the object."
       at Microsoft.MapPoint.Rendering3D.RenderThread.InitializeRender()
       at Microsoft.MapPoint.Rendering3D.RenderEngine.ManuallyInitializeRender()
       at InfoStrat.VE.PublicEventsGlobeControl.InitRenderEngine() in D:\Universes\virtualearthwpf-22590\Infostrat.VE\VEMap\PublicEventsGlobeControl.cs:line 58
       at InfoStrat.VE.VEMap.VEMap_Loaded(Object sender, RoutedEventArgs e) in D:\Universes\virtualearthwpf-22590\Infostrat.VE\VEMap\VEMap.cs:line 582
       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.AnimatedRenderMessageHandler(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)

Are you near to a new release?  Perhaps that will iron out the issue.



Apr 29, 2009 at 2:57 PM
I have been testing the new version on the simulator and Surface (which tests those features as well as the standard WPF features) and haven't come across this problem.  Hopefully it is something unique to the code you downloaded or any changes you made.  I can't tell much from just the call stack, since I'd have to check the internal status of some of the VE3D control variables to see what exactly was not initialized.

I think I'll be able to upload a new code drop today.  I think I'm ready to release but this is an outstanding issue, and I haven't tested the complete functionality as much as the original release.  Once I upload can you download the source and test?
Apr 29, 2009 at 5:05 PM
Hi Josh,

No problems, I will test as soon as you post the code.

Thanks for this, much appreciated.

May 1, 2009 at 4:54 PM
Hi Josh,

Are you closer to uploading the new source for this?  Would be great if you are.



May 1, 2009 at 5:03 PM
Sorry for the delay, work schedule didn't allow me to work on the right project to work on this.

Uploaded, see thread:
May 28, 2009 at 2:36 PM

I have the same problem.

In my case I've got the Map control on a TabItem withen a TabControl. On first rendering it appears fine, however if I switch to another tab then switch back I get this error.

As a quick & dirty workaround I enclosed the


in a try { ... } catch {} which got around the problem .... but .... aint quite ideal



Jul 3, 2009 at 7:24 PM

Hi Josh,

same problem...

Vista SP1
Latest vemap source code (downloaded today)
Latest BingMaps3D (downloaded today)

I am using the Surface Simulator and the problem occurs after switching view so that the vemap is hidden and back to the vemap.

Added the same dirty workaround as AngloR did...

Aug 27, 2009 at 2:34 AM

JoshB, I'm seeing the exact same scenario AngloR is getting, however I am not rendering the VEMap on the first tab item, but the second tab item.  As a result even his try-catch workaround doesn't even work for me.  The map just never shows up. 

Here's how to reproduce: The exception is thrown on the flip to the second tab.

<Window x:Class="VETest.Window1"
    Title="Window1" Height="480" Width="800">
        <TabItem Header="Test1" >
        <TabItem Header="Test2" >
            <ve:VEMap x:Name="map" MapStyle="Hybrid" />

Changing the TabItem to use a ContentPresenter fixed the initial rendering of the item, however The exception is thrown anytime you navigate away from the tab and come back to it.  Like others say, wrapping the ManualyInitizeRender() line of code in a try/catch block produces the expected results.
        <TabItem Header="Test2" >
                    <ve:VEMap x:Name="map" MapStyle="Hybrid" />
Thanks for all of your hard work on this project!

Aug 27, 2009 at 2:55 AM

Great, thanks for reporting your results and work-around!

Jan 4, 2010 at 6:47 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jan 4, 2010 at 6:48 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.