No session available when I create a WebDialog

Hello,

I’m starting a new project so there’s nothing complex at this stage.
Trying to show a WebDialog with the code below, I’m getting a runtime exception: “Control could not be created because there is currently no Session. Create a WebSessionContext object.”.
The method executing this code is from another window, so there has to be an existing session… :thinking:

This is the relevant code, called from a WebListbox’s SelectionChanged event:

…[define p as picture earlier]…

if p<>nil then
  dim wp As new WDPreview
  
  wp.ShowPicture p,False,Nil 'Custom method
  Return
end if

The exception happens at the “dim wp As new WDPreview” line (if split, at the “New WDPreview” statement).

Looked in Xojo documentation or with a search engine, absolutely no result found.

Any idea?

What is WDPreview ?

Ok, I found the bug, coming from me (and my lack of knowledge/expectation, and available information).
The method was called from both Listbox.SelectionChanged and URLConnection.ContentReceived. The problem happens from the latter path. It looks like a URLConnection event doesn’t have a valid session (or is different than the original one).

I’m keeping this thread existing, as others may encounter the same error (though it looks no one already talked about that).

Ah, I could’ve been clearer, indeed. That’s the WebDialog’s name.
Thank you.

This is because the URLConnection events are raised without a session context. I don’t recall where this is documented, but it’s one of those got-yas.

Subclass URLConnection, stash the Session ID, and re-create a session context (via WebSessionContext) in the event handler. That should do the trick.

1 Like

I vaguely remember having read something like that on this forum, earlier. But, being not a web expert (that’s one reason I use Xojo for this task, after all), I can’t hold the reasoning behind this in my head (I’ll certainly agree again if I re-read it, but it’s not obvious to me).

Well, in my case, I already had the symptom (the exception) but the message didn’t lead to anywhere. Not expecting an event to fire without a valid session (the URLConnection object being on the same WebPage than the other working controls and not looking “different” makes it not obvious), I’m not sure I’d find the clue alone.

I’ll try that.

Thank you.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.