Question
· Jul 5, 2018

<INVALID OREF>zgetFile+8^User.Read.1

Hello everyone,
what does it mean: <INVALID OREF>zgetFile+8^User.Read.1
(getFile is my ClassMethod and Read.cls is my class)?
I just try to read/load a file.

Discussion (8)0
Log in or sign up to continue

Note that this is technically row 8 in the zgetFile entry point of your generated .int code. Caché will generate/update a User.Read.1.int routine when you compile User.Read.cls, thus the ".1" in the error message.

In many cases, the class code and the generated int code will look the same and it won't matter. But to be sure you can always open the generated code in Atelier by right-clicking the class code in the Editor and selecting View Other Code.

I just try some examples from the documentation.

ClassMethod getFile() as %Persistent
{
    set filename = "path/to/file.json"
    set stream = ##class(%Stream.FileCharacter).%New()
    set sc = stream.LinkToFile(filename)    
    set obj = ##class(%DynamicAbstractObject).%FromJSON(stream)
    set jsonObj = [].%FromJSON(filename)
    set i = jsonObj.resultSets.%GetIterator()
    while i.%GetNext(.key , .resultSet ) {
    set i2 = resultSet.rowSet.%GetIterator()
    write resultSet.name,!
    while i2.%GetNext(.key , .rowSet ) {
        write rowSet.%Get(0),!
    }
}

So, row 8 is: set obj = ##class(%DynamicAbstractObject).%FromJSON(stream)
 

You are wrong:   getFile+8 is 

    set i2 = resultSet.rowSet.%GetIterator()


so either resultSet. or resultSet.rowSet is not what you expect it to be.

first you do 

set sc = stream.LinkToFile(filename)

 but you don't check the success code

And with "path/to/file.json" the file name looks more than suspicious to be correct.

next you do set obj=...   but this obj isn't used at all.

next 

set jsonObj = [].%FromJSON(filename)

and there is the fundamental mistake as your variable filename is

set filename = "path/to/file.json"


which is anything else than the expected JSON array

 you may have lost some important lines during cut/paste from your example

 Deserializing from JSON to a dynamic object may have important information for you

Hi, thank you for your response @Robert Camper!

set filename = "path/to/file.json" <- here is my path, for example /home/test.json
That was not the problem. I didn't find the problem in my code.

Anyway I have changed my code to:

Class User.MyClass Extends %CSP.REST
{

XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ]
{
<Routes>
<Route Url="/test" Method="GET" Call="getFile" />
</Routes>
}


ClassMethod getFile() as %Status
{
    set filename = "/home/test.json"
    set newArray={}.%FromJSON(filename)
    write "New entity:"_newArray.%ToJSON()
    }

and I become the output, but at the end there is an error:

[" zDispatchRequest+42^%CSP.REST.1 *Function must return a value at zgetFile+4^User.MyClass.1" ] } ], "summary":"ERROR #5002: Cache error: zDispatchRequest+42^%CSP.REST.1 *Function must return a value at zgetFile+4^User.MyClass.1" }

Do you know what does it mean?

if you define a method   mymethod() as something

You are expected to terminate ist either by QUIT anyvalue  or  RETURN ayvalue

in your example you announce a %Status. so Quit $$$OK would be fine like this

ClassMethod getFile() as %Status
{
    set filename = "/home/test.json"
    set newArray={}.%FromJSON(filename)
    write "New entity:"_newArray.%ToJSON()
    quit $$$OK
    }

if you ommit  as %Status you can allso forget the ending QUIT