This project is read-only.

NullReferenceException in EntityClient.cs line 156


I am receiving a NullReferenceException from the client.dll at line 156 of EntityClient.cs.
I have a timer setup to periodically call the Sample" function. The first call yields a set of results as desired but subsequent calls fail with the NullReferenceException. I have tried 2 OpenNETCF.MTConnect.Client.dll files that each claim to be version 1.0.12224.0, however one is 28.5 kb and the other 32.5 kb. Both generate the same error consistently

When I use this app to connect to "", I do not get that error.

Does this indicate a problem with my agent or adapter on the machine? Any idea what?

System.NullReferenceException: Object reference not set to an instance of an object.
at OpenNETCF.MTConnect.EntityClient.Sample(Int32 maxItems) in E:\d\shared\TFS06\mtconnect\OpenNETCF.MTConnect.Client\Clients\EntityClient.cs:line 156


sgtdcorbett wrote Jun 17, 2014 at 6:12 PM

By providing a value of 16 for the MaxItems in the call to the Sample function, I am now getting results. Why does the error occur when not sending a value for MaxItems? I see in the code that 100 is passed as the default value.

sgtdcorbett wrote Jun 18, 2014 at 5:16 PM

I believe my problem was related to the buffer size which was set very low on my agent.

ctacke wrote Jun 18, 2014 at 5:57 PM

Still it's interesting. A low buffer size shouldn't cause the error, it should simply cause data being thrown on the floor. That's not necessarily the best thing from an app perspective, but if you give those limitations, it at least shouldn't be throwing.

sgtdcorbett wrote Jun 18, 2014 at 7:31 PM

Thanks for the reply. I was able to recreate the problem situation by lowering the buffer and calling sample without limiting the maxitems (therefore it is calling /sample?count=100 and generating an error xml).
I stepped through the code and the problem starts with the RestConnector.Get call. The xml result (below) describes the error but has no sequenceID so the "next" value ends up as -1. The Sample function does not check for next == -1 and the xml !=string.empty so it doesn't return null (154 of entityclient.cs). Line 155 then results in stream being null and then the error is thrown on 156.

<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<MTConnectError xmlns:m=\"\" xmlns=\"\" xmlns:xsi=\"\" xsi:schemaLocation=\" /schemas/MTConnectError_1.2.xsd\">\n <Header creationTime=\"2014-06-18T18:18:12Z\" sender=\"VTC-200C\" instanceId=\"1403115081\" version=\"\" bufferSize=\"16\"/>\n <Errors>\n <Error errorCode=\"OUT_OF_RANGE\">'count' must be less than or equal to 16.</Error>\n </Errors>\n</MTConnectError>\n