views:

411

answers:

3

Using c#, VS2005, and .NET 2.0. (XP 32 bit) This is a Winforms app that gets called by a VBA addin (.xla) via Interop libraries. This app has been around for a while and works fine when the assembly is compiled and executed anywhere other than my dev machine. On dev it crashes hard (in debugger and just running the object) with "Unhandled exception at 0x... in EXCEL.EXE: 0x...violation reading location 0x...

But here's the weird part:

The first method in my interface works fine. All the other methods crash as above. Here is an approximation of the code:

[Guid("123Fooetc...")]
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface IBar
    {
        [DispId(1)]
         void ThisOneWorksFine(Excel.Workbook ActiveWorkBook);

         [DispId(2)]
         string Crash1(Excel.Workbook ActiveWorkBook);

         [DispId(3)]
         int Crash2(Excel.Workbook activeWorkBook, Excel.Range target, string someStr);
     }

    [Guid("345Fooetc..")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("MyNameSpace.MyClass")]    
    public class MyClass : IBar
    {
        public void ThisOneWorksFine(Excel.Workbook ActiveWorkBook)
        {...}

         string Crash1(Excel.Workbook ActiveWorkBook);
        {...}

         int Crash2(Excel.Workbook activeWorkBook, Excel.Range target, string someStr);
        {...}

    }

It seems like some kind of environmental thing. Registry chundered? Could be code bugs, but it works fine elsewhere.

A: 

Is your dev machine Win64? I've had problems with win64 builds of apps that go away if you set the build platform to x86.

Steve Cooper
+1  A: 

I've had problems in this scenario with Office 2003 in the past. Some things that have helped:

  • Installing Office 2003 Service Pack 2 stopped some crashes that happened when closing Excel.

  • Installing Office 2003 Service Pack 3 fixes a bug with using XP styles in a VSTO2005 application (not your case here)

  • Running the Excel VBA CodeCleaner http://www.appspro.com/Utilities/CodeCleaner.htm periodically helps prevent random crashes.

  • Accessing Excel objects from multiple threads would be dodgy, so I hope you aren't doing that.

If you have the possibility you could also try opening a case with Microsoft PSS. They are pretty good if you are able to reproduce the problem. And in most cases, this kind of thing is a bug, so you won't be charged for it :)

Joe
Thx Joe! Code Cleaner did the trick.
Andrew Cowenhoven
A: 

Is your dev machine running a different version of Office than the other machines? I know that the PIAs differ. So if you're developing on Office 2003 and testing on Office 2007 (or vice versa), for example, you will run into problems.

Robert S.