PreserveSig in VS 2005

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have been trying to migrate a VS 2003 project (dll) to VS 2005. I currently
use PreserveSig attribute on all COM visible properties and functions. When
compiling against the 1.1 framework all is well, but against the 2.0
framework I get “fatal error C1093: API call 'DefineCustomAttribute' failed
'0x801311c0' “. I discovered that by removing the PreserveSig attribute on
property definitions, the project compiles, but now my properties are
converted and exposed to COM in the HRESULT format (not desired). Any ideas?

Thanks,
Chris
 
Hi Chris,

I will perform some research on this issue and get back to you ASAP. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Chris,

Sorry for letting you wait.

Can you tell me why don't want the return type to be HRESULT in the IDL?
What exactly do these definitions look like in C# managed code? Do you
return something other than int/uint?

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Jeffrey,
Can you tell me why don't want the return type to be HRESULT in the IDL?

We currently have umanaged clients that are using our library with preserved
signatures.
What exactly do these definitions look like in C# managed code? Do you
return something other than int/uint?

I am not sure what your question is here. I am writing in managed C++ with
an interface definition that looks something like:

[Guid("someGUIDhere")]
public __gc __interface IMyList :
public IList,
public ICollection
{
public:
[PreserveSig] __property int get_Count();
[PreserveSig] __property bool get_IsFixedSize();
[PreserveSig] __property bool get_IsReadOnly();

[PreserveSig] __property Object * get_Item (int index);
[PreserveSig] __property void set_Item (int index, Object *);

[PreserveSig] int Add(Object * value);
[PreserveSig] void Clear();
[PreserveSig] bool Contains(Object * value);
[PreserveSig] int IndexOf(Object * value);
[PreserveSig] void Insert (int index, Object *value);
[PreserveSig] void Remove(Object * value);
[PreserveSig] void RemoveAt (int index);
};

So I am passing ints, bools and pointers. The PreserveSig works as expected
in VS 2003, C# clients see the properties as C# properties, etc.

Thanks,
Chris


"Jeffrey Tan[MSFT]" said:
Hi Chris,

Sorry for letting you wait.

Can you tell me why don't want the return type to be HRESULT in the IDL?
What exactly do these definitions look like in C# managed code? Do you
return something other than int/uint?

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Chris,

Thanks for your feedback!

It seems that you are using some old style CLR syntax in the new VC++2005.
This may be a side area.

Is it possible for you to send a little sample project to help me reproduce
this problem locally? Then I may perform some deep troubleshooting over it.
You may send the reproduce project to: (e-mail address removed)(remove
"online.")

Thanks very much!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Chris,

Additionally, it seems that your old-syntax CLR marks PreserveSig on
properties.

I have also discussed this issue with one COM interop expert internally.
Based on the MSDN document below, PreserveSigAttribute is valid on methods
only(AttributeTargets.Method):
"PreserveSigAttribute Class"
http://msdn2.microsoft.com/en-us/library/system.runtime.interopservices.pres
ervesigattribute.aspx

So it is not supported for properties. In C# if you try and apply it to a
property declaration you will get a compiler error that is worded much
better(in both VS.net2003 and VS2005):
"Attribute 'PreserveSig' is not valid on this declaration type. It is valid
on 'method' declarations only."

Since the PreserveSigAttribute is not supported for properties, we are not
sure why the VC compiler allowed yoru code to compile in VS.NET 2003.

I would recommend you to provide a little sample project to give us a local
reproduce, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top