IShell.OpenStandardEditor throws InvalidOperationException

Discussions related to SoftPro Select user interface development.

Moderator: Phil Barton

Post Reply
kkirkfield
Posts: 27
Joined: Tue Jun 28, 2016 2:26 pm

IShell.OpenStandardEditor throws InvalidOperationException

Post by kkirkfield »

I am trying to open an editor pane at client startup that is separate from the start page.

Code: Select all

[ProvideEditorFactory(typeof(WDEditorFactory), "Workflow Dashboard Editor Factory")]
[ProvideEditorExtension(typeof(WDEditorFactory), "sp-select", "wd", 10)]
partial class MyPackage : Package
{
    protected override void OnInitialize()
    {
        RegisterEditorFactory(new WDEditorFactory(this));
        var shell = GetService<IShell>();
        shell.Load += ShellLoadHandler;
    }

    private void ShellLoadHandler(object sender, EventArgs e)
    {
        var shell = GetService<IShell>();
        shell.OpenStandardEditor(new Uri("sp-select:///wd")); // InvalidOperationException thrown here.
    }
}
The exception message says "Sequence contains no matching element." Here is the stack trace:

Code: Select all

   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
   at SoftPro.Select.Managers.MRUListManager.GetRecentDcumentsManager()
   at SoftPro.Select.Managers.MRUListManager.SoftPro.Select.Shell.IMRUList.Add(Uri moniker, String title, DateTime lastAccess)
   at SoftPro.Select.Managers.ShellManager.SoftPro.Select.Shell.IShell.OpenDocumentWindow(Uri moniker, String view, Object existingData, Boolean openAsNew, Boolean shellExecute)
   at SoftPro.Select.Managers.ShellManager.SoftPro.Select.Shell.IShell.OpenStandardEditor(Uri moniker)
   at WorkflowDashboard.MyPackage.ShellLoadHandler(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at SoftPro.Select.Managers.ShellManager.InvokeLoad()
   at SoftPro.Select.Runtime.OnRun()
   at SoftPro.Select.Runtime.Start()
OpenStandardEditor() is finding my editor factory, as my breakpoints are being hit. It seems to be something wrong with the MRU list. Do I need to use the OpenStandardEditor() in another way?

Here is another forum post that may be similar, but it is for opening orders through the order store.
viewtopic.php?f=6&t=748
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: IShell.OpenStandardEditor throws InvalidOperationExcepti

Post by BobRichards »

You need to change your Uri format slightly.

Code: Select all

shell.OpenStandardEditor(new Uri("sp-select://./wd"));
Bob Richards, Senior Software Developer, SoftPro
kkirkfield
Posts: 27
Joined: Tue Jun 28, 2016 2:26 pm

Re: IShell.OpenStandardEditor throws InvalidOperationExcepti

Post by kkirkfield »

I've tried that, and I'm still getting the same exception and stack trace.
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: IShell.OpenStandardEditor throws InvalidOperationExcepti

Post by BobRichards »

I find that opening the custom editor in the IShell.Load event does cause some issues for me as well - but not the same issues. However, it functions perfectly if done in a button event. Do you need to open it in the Load event? If so, what are you trying to achieve?
Bob Richards, Senior Software Developer, SoftPro
kkirkfield
Posts: 27
Joined: Tue Jun 28, 2016 2:26 pm

Re: IShell.OpenStandardEditor throws InvalidOperationExcepti

Post by kkirkfield »

The goal is to have a report view open at startup, in addition to our current start page that was created by another developer. If there is not a way to have multiple start pages, I will either have to recreate our other start page with a tab layout to include our report view, or we will have to settle for the user clicking a button to open the report editor.
John Morris
Posts: 411
Joined: Thu Sep 11, 2008 11:35 am
Location: Raleigh, NC, USA
Contact:

Re: IShell.OpenStandardEditor throws InvalidOperationExcepti

Post by John Morris »

Instead of calling open during the handling of the shell load event, try doing a begininvoke call during the load event. Have the begun invoke call, call routine that will so the open call.

Code: Select all

void OnInitialize() {
    GetService<IShell>().Load += OnShellLoad;
}

void OnShellLoad(object sender, EventArgs e) {
    GetService<IShell>().BeginInvoke(new MethodInvoker(OpenEditor));
}

void OpenEditor() {
    //open your editor here
}
John Morris
Sr. Software Architect
SoftPro
kkirkfield
Posts: 27
Joined: Tue Jun 28, 2016 2:26 pm

Re: IShell.OpenStandardEditor throws InvalidOperationExcepti

Post by kkirkfield »

Thanks John. That did the trick.
Post Reply