ahausladen / JsonDataObjects

JSON parser for Delphi 2009 and newer
MIT License
413 stars 160 forks source link

TJsonBaseObject.ParseFromFile fails on IIS #74

Open fastbike opened 1 year ago

fastbike commented 1 year ago

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;