Skip to content

TJsonBaseObject.ParseFromFile fails on IIS #74

@fastbike

Description

@fastbike

This is a very strange bug - it only manifests itself under our ISAPI application running on IIS (Windows Server) but not on IIS (Windows 10 professional)

Anyway, making a call to TJsonBaseObject.ParseFromFile returns nil in the error case.
Changing the implementation code as below fixes the problem and the text is parsed correctly into a JSON object.

class function TJsonBaseObject.ParseFromFile(const FileName: string; Utf8WithoutBOM: Boolean{$IFDEF SUPPORT_PROGRESS}; AProgress: PJsonReaderProgressRec{$ENDIF}): TJsonBaseObject;
var
  Stream: TFileStream;
begin
  Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
  try
    // add this line
    Stream.Seek(0, soBeginning);
    Result := ParseFromStream(Stream, nil, Utf8WithoutBOM{$IFDEF SUPPORT_PROGRESS}, AProgress{$ENDIF});
  finally
    Stream.Free;
  end;
end;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions