none
Button action event doesn't fire if implementation reference a WinForm project RRS feed

  • Question

  • I'm coding an Outlook 2010 plug-in targeting .NET 3.5 in VS2010 Ultimate, and am experiencing some wierd stuff. Disclaimer right away: I'm blank at WPF and novice at Office 2010 plugins. I'm trying to open a WinForms Form that resides in a referenced WinForms project. In the project for the Outlook plugin, this is the code for the action event (button click):

        public void SettingsButton_Click(IRibbonControl control)
       
    {
           
    MessageBox.Show("Hello world!");    // Breakpoint here
           
    var form = new TestProject.Form1(); // WinForms project form
            form
    .Show();
       
    }

    This works perfectly if I comment out the two last lines in the method, but when they are present, the method never gets called! I have also verified this in debug mode, setting a breakpoint on line 1. With all three lines present, the breakpoint is never hit. With only the ShowDialog line, the method is called and the debugger breaks here.

    Why does the implementation matter?? This smells...

    PS: I have done a test with a normal WPF project referencing a WinForms project, and I was not able to produce the issue there.

    Tuesday, May 10, 2011 9:46 PM

Answers

  • Hi,

    now I got - no Idea what happens before.

    So - the Outlook AddIN project is set to Any CPU (Build)

    the Winforms is set to X86.

    On a 32bit Outlook that would load, but not on a X64.

    try setting the Winforms project to AnyCPU (create a new target using the configuration manager) recompile and then it would work also on a X64 Outlook installation.

    Hope this helps, 

    Greets - Helmut 


    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]
    • Marked as answer by FrodeNilsen2 Wednesday, May 11, 2011 4:40 PM
    Wednesday, May 11, 2011 3:21 PM
    Answerer

All replies

  • Hello,

    WinForms has nothing todo with WPF.
    So - when the breakpoint is nevr hit - I think you are missing a DLL-Reference in your project.

    Also check, that the referenced DLL Project has correct settings for the target Plattform and also the .Net Framework 3.5.

    With a plain Winforms-Dll that should be no problem at all.

    Greets - Helmut


    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]
    Wednesday, May 11, 2011 6:37 AM
    Answerer
  • Hello,

    WinForms has nothing todo with WPF.
    So - when the breakpoint is nevr hit - I think you are missing a DLL-Reference in your project.

    Also check, that the referenced DLL Project has correct settings for the target Plattform and also the .Net Framework 3.5.

    With a plain Winforms-Dll that should be no problem at all.

    Greets - Helmut


    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]

     

    I would find it disturbing if my code compiled and no runtime exception occurs if I was missing a DLL-reference, but I was thinking the same for a while. I do reference System.Windows.Forms in the Outlook Plugin project. I have also checked target framework for all projects.

    Here's a clean project template I created just for testing. Now targeting .NET 4.0, but the problem still occurs. Would be interesting to see if anyone else could reproduce it or not.

    I'm using Winodws 7 x64 with Outlook 2010 x64.

    Source code: http://data.nilzorblog.com/forumposts/OutlookAddIn_WinForms.zip

    The method you'd want to check out is button1_Click()  in Ribbon.cs.

    1. Run code without doing anything, verify that a messagebox appears when clicking "button1".
    2. Uncomment line 65 and 66 of Ribbon.cs. See if button1 still works
    Wednesday, May 11, 2011 1:57 PM
  • Hi,

    I downloaded the sources, but there are files missing in the .zip file.

    Greets - Helmut


    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]
    Wednesday, May 11, 2011 2:06 PM
    Answerer
  • What files? I just went through the zip file and all files needed seemed to be there:

    OutlookAddin2.sln
    OutlookAddin2\OutlookAddin2.csproj
    OutlookAddin2\Ribbon.cs
    OutlookAddin2\Ribbon.xml
    OutlookAddin2\ThisAddIn.*
    WindowsFormsApplication1\WindowsFormsApplication1.csproj
    WindowsFormsApplication1\Form1.*

    You do have Visual Studio 2010, Office 2010 and VSTO for Office 2010 installed?

    I appreciate very much that you're trying to help.

    Wednesday, May 11, 2011 2:58 PM
  • With regards to WinForms and why I'm doing this - I have an old Outlook 2003 plugin that I want to enable for Outlook 2010. It is WinForms, so I'd very much like to reuse that project. I could of course rewrite it to WPF but that will take a lot of time.

    What I do know is that there shouldn't be a problem launching winforms forms from WPF application. If I create a System.Windows.Form inside the Outlook project, I'm able to call Show() on that one. It's just when the Form is outside the project that the problems start.

    Wednesday, May 11, 2011 3:00 PM
  • Hi,

    now I got - no Idea what happens before.

    So - the Outlook AddIN project is set to Any CPU (Build)

    the Winforms is set to X86.

    On a 32bit Outlook that would load, but not on a X64.

    try setting the Winforms project to AnyCPU (create a new target using the configuration manager) recompile and then it would work also on a X64 Outlook installation.

    Hope this helps, 

    Greets - Helmut 


    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]
    • Marked as answer by FrodeNilsen2 Wednesday, May 11, 2011 4:40 PM
    Wednesday, May 11, 2011 3:21 PM
    Answerer
  • You nailed it! :)

    Believe me I had tried setting these settings before, but obviously not on the clean test project. I suppose the entire dependency chain must be 64 bit, and there I have a last challenge with an open source library I've linked in. But given it's open source, I guess I'll be able to rebuild it in 64 bit aswell.


    Thanks a lot! Helps with some fresh eyes to look at problems you've struggled with for hours and hours :)

    Wednesday, May 11, 2011 4:40 PM
  • ...by the way, if anyone from the Microsoft .NET developer team reads this, wouldn't it be an idea to give the developer some kind of feedback when this kind of CPU architecture discrepancy is present? A runtime error at least?
    Wednesday, May 11, 2011 4:42 PM
  • Thanks, I would suggest to build it not for I64, build it for target "AnyCPU".

    Then it will load on X86 and X64 Systems.

    When You Debug, you should see something in the Debugger-Output-Window --- could not be loaded, wrong Plattform or similar.

    Greets - Helmut

     


    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]
    Wednesday, May 11, 2011 5:08 PM
    Answerer
  • ...by the way, if anyone from the Microsoft .NET developer team reads this, wouldn't it be an idea to give the developer some kind of feedback when this kind of CPU architecture discrepancy is present? A runtime error at least?

    You might want to post this on Connect, as a Suggestion or Feedback. I think that's the best way to make sure the VSTO team actually sees it, these days...
    Cindy Meister, VSTO/Word MVP
    Wednesday, May 18, 2011 7:24 AM
    Moderator