C++ Reflection Problems

R

Ray Deese

Hi

I have quite a strange problem that I can't seem to overcome on my own. I have a managed C++ web service which has one webmethod. This method returns an array of a class with 1 property in it. This array is created by another class which has IEnumerable and IEnumerator as its base class so that I can DataBind this type in the consuming application. The web service compiles fine but when you run it, it returns the following errors in the stack trace

[NullReferenceException: Object reference not set to an instance of an object.

[InvalidOperationException: There was an error reflecting 'QuickSortResult'.

[InvalidOperationException: Method CService.QuickSort can not be reflected.

[InvalidOperationException: Unable to handle request.

[InvalidOperationException: Failed to handle request.

I have created 2 different projects, a console application and a class library - both of those would compile the same code (mines the system::web stuff) just fine - the console app would run nicely and the class library was able to be referenced inside of another application and invoked. So suffice to say, I'm stuck! Here is the pertinent code below

Number.h simply implement a class with a single property with get & set implemente

-----------------------------------------------------------------
//numbers.
namespace numbersnamespac

__gc public class numbers : public IEnumerable, public IEnumerato

private
static int position = -1;

public:
number *enumerator[];

numbers(

enumerator = new number * [NUM_ITEMS]

------------------------------------------------------------------------
//Main.h
__gc public class CServic
{
public:
[WebMethod
numbers* QuickSort();
------------------------------------------------------------------------
//Main.cp
numbers* CService::QuickSort(
{
//non important code is left ou

numbers *sdata = new numbers()

for (i = 0; i < NUM_ITEMS; i++
sdata->enumerator = new number(__numbers);

return sdata


Any help/suggections are much appreciated, my email address is listed as well in case you would like to contact me that way

Thanks in advance
-Ra
 
M

[MSFT]

Hi Ray,

From your code, I haven't found the definition for "__numbers". Is it
possible that this array or one of its items is null value at runtime and
cause the problem?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
M

[MSFT]

Hi Ray,

Have you checked if every item in the arry "__numbers" have actual value?
This may be the cause of error "Object reference not set to an instance of
an object.". Additionally, the error also may be related to Serializtion
process of the web service. You may test follow code with sdata to if it
will generate errors:

XmlSerializer* serializer = new XmlSerializer(__typeof(numbers));

TextWriter* writer = new StreamWriter(filename);

serializer->Serialize(writer, sdata);
writer->Close();

This can help find if it can pass the Serializer of web service.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top