Getting a SessionNotAvailableException while creating a webcontainer control instance

I’m creating a whole bunch of webcontainer controls on the fly.
First a “master” container then multiple “sub” containers.

Here’s the pseudocode:

Sub buildContainer()

' remove previous ccMaster if any
ccMasterClear

Dim ccMaster as New ccHld
ccMaster.EmbedWithin(self, left, top, width, height)
...
for i as integer = 1 to maxCount 
  Select Case cond
  Case 0
   Dim ccSub as New reParm0
   ccSub.EmbedWithin(ccMaster, l, t, w, h)
  Case 1
   Dim ccSub as New reParm1
   ccSub.EmbedWithin(ccMaster, l, t, w, h)
  Case 2
  ...
  Case n
  ...
  End Select
Next

...

The method buildContainer is called many times and it works many times and suddently I get a SessionNotAvailableException on a Dim line (Dim ccSub as New reParm1, eg).
I can sometimes test dozens of times before getting the exception.
When I press “continue” on the exception the debugger just closes, as does the webapp.

Really annoying as I don’t know where to look first.
What can I do to find out when and why this session is not available anymore ?

I have no thread, no timer.

Environment is:
Xojo 2013 r4.1 (problem is the same with r3.3)
Web App
IDE running on Mac OSX 10.9
Same problem using Chrome or Safari

Maybe important, I was using Web Essentials with:
WebApplication is WEApplication
WebSession is WESession
all WebPages are WEWebPage
all WebContainers are WEWebContainer

But removing all Web Essentials and getting back to the standard classes doesn’t solve the problem.

Any idea or hint ?

Many thanks

Where are you calling this method from?

The method is called from a MouseDown event on another control.
It’s a quite long stack of WebPage / ContainerControl / WebDialog / ContainerControl / …

SessionNotAvailableException fires when there is no current session to write to. What’s puzzling is that this should never happen if called directly from an event that is part of an event loop thread.

That’s why I’m puzzled too !

I’m using a DynaTree control (from DT Web Custom Controls), could that be a reason ?

It’s quite difficult to provide a sample app to reproduce it, I’m using MySQL and SQLite databases.
The app is heavily datacentric, most of the controls are created on the fly, based on database info.

What can I provide to help you trace the problem ?

What is the “other control” in this case?

The other control is a DynaTree and the event is “wccNodeClick” when clicking on a DynaTreeNode.

Try calling this method from a simple button and see if you get the exception. If not, I’d talk to Daniel and see if he can narrow this down.

As suggested, I changed the wccNodeClick to save the DynaTreeNode in a property and created a button calling the method.
After selecting tens of different nodes, and using the button to call the method I couldn’t reproduce the error.

I’ll check with Daniel.

Thanks anyway and I wish you a pretty bug free 2014 !