sam holder

sam holder

  • NA
  • 3
  • 0

Strange behaviour when accessing .net library through com

Apr 16 2008 9:41 AM
Hi,

I have a strange issue.  I have a method:

public String[] MethodA()
        {
            List<String> result = new List<string>();
            result.Add(ObjectA.Instance.Name);
            result.Sort();
            return result.ToArray();                     
        }

this is in a .NET 2.0 c# library which is com enabled and I am consuming in a C++ MFC application.
When I call the method in the C++ app safearray I am using to hold the results is corrupted.  The Name property is a string.

If I modify the method like so:

public String[] MethodA()
        {
            List<String> result = new List<string>();
            result.Add("MyString");
            result.Sort();
            return result.ToArray();                     
        }

then when I call it it returns the correct information and I can use the safearray with no problems.

I have tried several options for modifying the method including calling ToSting() on the name, creating a string variable first setting this to be the name, then adding the string to the list, creating a stringBuilder, adding the Name to that then adding StringBuilder.ToString() to the list, but all fail in the same way.

Does anyone have any idea why this might be?  Can anyone offer any potential solution?

Thanks

Sam

Answers (2)