Debugging .Net4 COM registered assembly from Win32 caller in Visual Studio 2010

大憨熊 提交于 2019-12-07 08:56:54

问题


This is a very simple setup, I can't believe but I didn't find anybody with the same problem so far...

Create a .Net4 class library in VS2010. Create a simplest possible COM object:

[ComVisible(true)]
[Guid("CD157EBC-C89D-40b6-B531-E85FF4B3AE9A")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IAcorn
{
    bool Foo(string moo);
}


[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[Guid("854B7690-C1C4-40c4-8059-B4F3450B30D0")]
public class Acorn : IAcorn
{
    public Acorn()
    {
    }

    public bool Foo(string moo)
    {
        return true;
    }
}

Set "Register for COM interop" option for the assembly. Set "platform target" to x86.

Create a Win32 client using Delphi, import the object, instantiate it using normal instantiation (translates to CoCreateInstance(ClassID, nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, IUnknown, Result))

Run the Win32 application, everything works fine.

Try to debug the COM object from VS2010. Set the class library Debug option to start an external program, point to the executable you just created. When you launch the Win32 app from VS210, the program crashes (with StackOverflow) at the attempt to instantiate the COM.

Change the Target framework to .Net 3.5 Launch the debugging from VS2010, everything works including debugging.

Note - This is also a problem when using either CLR Hosting or unmanaged export COM instantiation. Both methods work with .Net4 but debugging is not possible.

The question is standard - why does this happen and is there a workaround?


回答1:


The .NET framework and Delphi may set or expect different values in the FPU control word.

That problem can be avoided by setting the register explicitly, before calling .NET code and resetting it after the .NET code is done:

How can I set and restore FPU CTRL registers?



来源:https://stackoverflow.com/questions/6102882/debugging-net4-com-registered-assembly-from-win32-caller-in-visual-studio-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!