Hi,
We are using .NET MarshalByRef remoted object that we use in a COM Interop
scenario. When we try to access a member of the remoted object from COM
returned by a remoting method call, we get the following error:
<VSNET Debugger runtime error>
"Run-Time check failure #0 : The value of ESP was not properly saved across
a function call. This is usually a result of calling a function declared
with one calling convention with a function pointer declared with a
different calling convention."
<VSNET Debugger runtime error/>
Exemple to reproduce this:
<C# Code Class Lib>
[
System.Runtime.InteropServices.Guid("C5DDC244-4CFC-4f15-821B-787F9C0684D5")
]
public interface A
{
B GetB();
}
public class ImplA : A
{
B GetB()
{
B temp;
// Get B through .NET Remoting here...
...
return temp;
}
}
[
System.Runtime.InteropServices.Guid("97286132-A545-4965-9BE3-AC3E2C63ED9E")
]
public interface B
{
C GetC();
}
internal class ImplB : MarshalByRef, B
{
C GetC()
{
return new ImplC();
}
[
System.Runtime.InteropServices.Guid("97286132-A545-4965-9BE3-AC3E2C63ED9F")
]
public interface C
{
string Name{get;}
}
internal class ImplC : MarshalByRef, C
{
string Name
{
get{ return "Eric St-Onge" } };
}
}
<C# Code Class Lib/>
<C++ Win32 Console Client Code>
#include "stdafx.h"
#include <comdef.h>
#import <ClassLibrary1.tlb> auto_search
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
::CoInitialize(NULL);
try
{
ClassLibrary1::APtr smartptr_A;
_com_util::CheckError( smartptr_A.CreateInstance("ClassLibrary1.A") );
ClassLibrary1::BPtr smartptr_B = smartptr_A->GetB();
ClassLibrary1::CPtr smartptr_C = smartptr_B->GetC();
_bstr_t name = smartptr_C->Name; // VSNET Debugger runtime error happen
here!!
std::cout << (const char*)name << std::endl;
}
catch( _com_error e )
{
std::cout << (const char*)(e.ErrorMessage()) << std::endl;
}
::CoUninitialize();
return 0;
}
<C++ Win32 Console Client Code/>
The workaround for this is to do a QueryInterface(C) on the object pointed
by smartptr_C before using it.
This only happens when objects are going through remoting boundaries.
This looks like a bug since the IDL clearly states that the interface
returned by GetC() is of type C and, when using standard COM objects, it is
not required to QueryInterface after the call returns. (if it was the case,
the code generated to produce the smart pointer would have called
QueryInterface on return of the GetC() call).
Is there a bug fix from MS for this or a known workaround using attributes
or something else? Or maybe we are doing something wrong that fools the CCW?
Thanks!
Eric
"Ying-Shen Yu[MSFT]" - 01 Jul 2004 12:52 GMT
Hi Eric,
I followed your description and made a test program on my system, this
issue could be reproduced on .NET v1.1.
I'll forward this issue to the product team to let them investigate it
further.
Thanks for your feedback!
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
"Ying-Shen Yu[MSFT]" - 03 Jul 2004 08:31 GMT
Hi Eric,
I just did a test on a machine with .NET v2.0 beta1installed, and my test
program works correctly. so probably this issue had been fixed in the new
release.
You may try your program on .NET v2.0 to see if it works.
The .NET v2.0 beta 1 setup packages can be downloaded from :
DotNET Framework Version 2.0 Redistributable Package Beta 1 (x86) - 24M
http://go.microsoft.com/fwlink/?linkid=30093&clcid=0x409
DotNET Framework 2.0 SDK Beta 1 x86 - 229M
http://www.microsoft.com/downloads/details.aspx?familyid=916EC067-8BDC-4737-
9430-6CEC9667655C&displaylang=en
If your current workaround does not resolve this problem, please feel free
to reply this thread to let us know.
Thanks!
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
Eric St-Onge - 04 Jul 2004 12:46 GMT
Thanks for the investigation, my current workaround is not acceptable for my
customer and switching to 2.0 Beta neither, is there any hot fix that you
could provide us to fix this issue under .NET v1.1?
Thanks!
Eric
> Hi Eric,
>
[quoted text clipped - 9 lines]
>
> DotNET Framework 2.0 SDK Beta 1 x86 - 229M
http://www.microsoft.com/downloads/details.aspx?familyid=916EC067-8BDC-4737-
> 9430-6CEC9667655C&displaylang=en
>
[quoted text clipped - 12 lines]
> This mail should not be replied directly, please remove the word "online"
> before sending mail.
"Ying-Shen Yu[MSFT]" - 06 Jul 2004 04:35 GMT
Hi Eric,
Thanks for your reply,
I just heard that .NET framework V1.1 sp1 had entered RC stage.
In my quick test, my test program works fine after applying this service
pack. To further confirm if this issue was fixed in this service pack , I'd
like to get a repro sample which was sperated from your program and test it
again using sp1.
We can go on the hotfix process, if this issue is not fixed in sp1. Is it
ok?
Please note the words below my signature before sending the repro sample
program.
Looking forward to your sample, thanks!
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
grubuser - 15 Jul 2004 00:07 GMT
Hi there!
I read this thread and I'm experiencing the same problem and It's happening in a third party software my visual studio .net project is using.
I was wondering if a hot fix was provided for this problem by microsoft, and if so can somebody point me to it.
Cheers,
Ledio
> Hi Eric,
>
[quoted text clipped - 24 lines]
> This mail should not be replied directly, please remove the word "online"
> before sending mail.