Excel 插件访问冲突

发布于 2024-07-04 18:58:23 字数 1148 浏览 6 评论 0原文

使用 C#、VS2005 和 .NET 2.0。 (XP 32 位)这是一个 Winforms 应用程序,由 VBA 插件 (.xla) 通过互操作库调用。 这个应用程序已经存在了一段时间,并且当程序集在我的开发机器以外的任何地方编译和执行时工作正常。 在开发中,它会严重崩溃(在调试器中并仅运行对象),并显示“EXCEL.EXE 中 0x... 处未处理的异常:0x...违反读取位置 0x...

但这里有一个奇怪的部分:

我的第一个方法接口工作正常。上面的所有其他方法都崩溃了。这是代码的近似值:

[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);
        {...}

    }

这似乎是某种环境问题?可能是代码错误,但在其他地方工作正常。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

对岸观火 2024-07-11 18:58:23

你的开发机器是Win64吗? 我在使用 win64 构建应用程序时遇到了问题,如果将构建平台设置为 x86,这些问题就会消失。

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.

过度放纵 2024-07-11 18:58:23

我过去在使用 Office 2003 时曾遇到过这种情况的问题。 一些有帮助的事情:

  • 安装 Office 2003 Service Pack 2 阻止了关闭 Excel 时发生的一些崩溃。

  • 安装 Office 2003 Service Pack 3 修复了在 VSTO2005 应用程序中使用 XP 样式的错误(此处不是您的情况)

  • 运行 Excel VBA CodeCleaner http://www.appspro.com/Utilities /CodeCleaner.htm 定期帮助防止随机崩溃。

  • 从多个线程访问 Excel 对象会很危险,所以我希望您不要这样做。

如果有可能,您也可以尝试使用 Microsoft PSS 开立案例。 如果您能够重现问题,它们就非常好。 在大多数情况下,这种事情是一个错误,所以你不会为此付费:)

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 :)

网白 2024-07-11 18:58:23

您的开发计算机运行的 Office 版本与其他计算机是否不同? 我知道 PIA 有所不同。 因此,例如,如果您在 Office 2003 上进行开发并在 Office 2007 上进行测试(反之亦然),您就会遇到问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文