The writ is returnable to the court of the county in which the land lies, in all cases where land is the subject of controversy, and in all other cases to the court of the county where the defendant resides, or, if against a public officer or corporation, in the county in which the office is kept or corporation does business.