locked
Using CRM Login Form for WPF Applications in Office Add-In RRS feed

  • Question

  • Hi,

    We are trying to use Out of the box CRM Login Form for WPF Applications in an Office Add-In (using VSTO).

    We can add Form in Add-In project and load it as well on a Ribbon Button click, but once user credentials are added it throws and Object Reference Error.

    Object reference not set to an instance of an object.


    ************** Exception Text **************
    System.NullReferenceException: Object reference not set to an instance of an object.
       at Microsoft.Xrm.Tooling.CrmConnectControl.CrmConnectionManager.SetConfigKeyInformation(Dictionary`2 configKeys)
       at Microsoft.Xrm.Tooling.CrmConnectControl.CrmServerLoginControl.StartConnectCheck()
       at Microsoft.Xrm.Tooling.CrmConnectControl.CrmServerLoginControl.btn_ConnectToServer(Object sender, RoutedEventArgs e)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)

    Code is very simple, we have Office Add-In project in which CRM Login Form for WPF Application is added and is invoked from Ribbon Button Click.

                    CRMLogin ctrl = null;
                    // Establish the Login control
                    ctrl = new CRMLogin();
                    // Wire Event to login response. 
                    ctrl.ConnectionToCrmCompleted += ctrl_ConnectionToCrmCompleted;
                    // Show the dialog. 
                    ctrl.ShowDialog();
                    // Handle return. 
                    if (ctrl.CrmConnectionMgr != null && ctrl.CrmConnectionMgr.CrmSvc != null && ctrl.CrmConnectionMgr.CrmSvc.IsReady)
                    {
                        MessageBox.Show("Connected to " + ctrl.CrmConnectionMgr.ConnectedOrgFriendlyName);
                    }
                    else
                    {
                        MessageBox.Show("BadConnect");
                    }

    We also tried converting CRM Login Form to WPF User Control and hosted it inside Windows Form (ElementHost) control, to no luck.

    There is little help available on this on Blogs and forums, any help is much appreciated.

    Monday, January 4, 2016 12:25 PM

Answers

  • VSTO apps run as C++.
    You will need to set the App Name and configuration behavior allow it to work..

    if you take a look at the code in the CRMLogin form, you will see a few comments in the Window_Loaded hander...  If you are using the templates we provide its around ln 94.
    you will see :

    // if you are using an unmanaged client, excel for example, and need to store the config in the users local directory
                // set this option to true. 
                mgr.UseUserLocalDirectoryForConfigStore = true;
                // if you are using an unmanaged client,  you need to provide the name of an exe to use to create app config key's for. 
                mgr.HostApplicatioNameOveride = "MyExecName.exe";

    where the HostApplicationName override is commented.

    uncomment that line and change the MyExecName.exe to a name to track your addin... "myaddin.exe" for example.  it needs to have the .exe extension on the text.

    let me know if that sorts it out for you

    • Marked as answer by GaurangSoni Tuesday, January 5, 2016 1:18 PM
    Monday, January 4, 2016 10:38 PM

All replies

  • VSTO apps run as C++.
    You will need to set the App Name and configuration behavior allow it to work..

    if you take a look at the code in the CRMLogin form, you will see a few comments in the Window_Loaded hander...  If you are using the templates we provide its around ln 94.
    you will see :

    // if you are using an unmanaged client, excel for example, and need to store the config in the users local directory
                // set this option to true. 
                mgr.UseUserLocalDirectoryForConfigStore = true;
                // if you are using an unmanaged client,  you need to provide the name of an exe to use to create app config key's for. 
                mgr.HostApplicatioNameOveride = "MyExecName.exe";

    where the HostApplicationName override is commented.

    uncomment that line and change the MyExecName.exe to a name to track your addin... "myaddin.exe" for example.  it needs to have the .exe extension on the text.

    let me know if that sorts it out for you

    • Marked as answer by GaurangSoni Tuesday, January 5, 2016 1:18 PM
    Monday, January 4, 2016 10:38 PM
  • Hi Matt,

    Thanks for your reply.

    Your suggestion did worked for me.

    I did saw  mgr.HostApplicatioNameOveride option, but I thought since I have Office Add-In which do not have any EXE with it, this option is not required.

    But your explanation "it needs to have the .exe extension on the text. ", helped me understand why it's needed.

    Thanks again :)

    Tuesday, January 5, 2016 6:42 AM