
291 S.W.3d 351 (2009)
Jason GRELLNER, et al., Appellants,
v.
FOREMOST SIGNATURE INSURANCE COMPANY and Lamar International, Inc., d/b/a Lamar International Realtors, Defendants, and
Green Tree Servicing, LLC, Respondent.
No. ED 92196.
Missouri Court of Appeals, Eastern District, Division Two.
July 14, 2009.
Rick Barry, Kevin J. Dolley, St. Louis, MO, for Appellant.
David G. Wasinger, James S. Cole, Michael Daming, St. Louis, MO, for Respondent.
ROY L. RICHTER, Presiding Judge.
Jason Grellner ("Grellner") appeals the trial court's judgment granting Green Tree Servicing, LLC's ("Green Tree/Conseco") *352 motion to dismiss.[1] We reverse and remand.

I. BACKGROUND
The underlying litigation in this case involves a tort claim by Grellner against Troy Manning ("Manning") for a dangerous condition on Manning's mobile home premises (a meth lab). Grellner determined that Foremost Signature Insurance Company ("Foremost")[2] insured the mobile home, and notified Foremost of the pending suit against Manning as well as Foremost's duty to defend and indemnify Manning. No legal counsel appeared on Manning's behalf and Grellner obtained a $5,000,000 default judgment against him. Manning was judgment-proof, and assigned all his legal claims to Grellner.
In an attempt to collect on his judgment, Grellner instituted the current action against Green Tree/Conseco, Foremost, and Lamar International Realty ("Lamar"). Grellner's Second Amended Petition charged Green Tree/Conseco and Lamar with breach of contract, negligence, and breach of fiduciary duty, and Foremost with breach of duty to defend and vexatious refusal to pay.
The facts giving rise to this litigation began in 1999 when Manning purchased the mobile home at issue from Steve and Angela West ("West"). Green Tree/Conseco, Foremost, and Lamar all participated in effecting the mobile home sale and in transferring the equity from West to Manning. Lamar acted as the real estate agent for both parties and drafted the relevant paperwork.[3] Green Tree/Conseco, acting as Foremost's agent, served as the lending and loan servicing agent. Grellner's Second Amended Petition alleged that Green Tree/Conseco's policies required it to establish insurance coverage for Manning as a condition of the loan and Transfer of Equity Agreement. However, according to Grellner, Green Tree/Conseco failed to create an account in Manning's name and instead continued to maintain one only in West's name.
Due to Green Tree/Conseco's failure to update the name on the account, Foremost did not have notice that the equity in the mobile home had been transferred from West to Manning. Grellner claimed that, since the account remained in West's name, Manning's insurance premiums were paid to Foremost in West's name and placed in Green Tree/Conseco's escrow accounts in the name of West. Grellner alleged that Green Tree/Conseco's conduct resulted in Manning having no insurance coverage, and therefore no defense or indemnification in Grellner's tort suit against him.
Green Tree/Conseco filed a motion to dismiss Grellner's Second Amended Petition in the trial court.[4] The motion to dismiss alleged that, before Green Tree purchased Conseco in June 2003, Conseco *353 Incorporated had filed a voluntary petition for reorganization under Chapter 11 of the United States Bankruptcy Code in December 2002. Green Tree/Conseco's motion asserted that they should be dismissed from the action because Grellner had filed his lawsuit in violation of the Bankruptcy Court's discharge order. Green Tree/Conseco attached to its motion to dismiss the Bankruptcy Court's Order confirming Conseco Incorporated's reorganization pursuant to Chapter 11.
The trial court granted Green Tree/Conseco's motion to dismiss with prejudice and cited Conseco's discharge in bankruptcy as the basis for Green Tree/Conseco's dismissal from the suit. Per Missouri Supreme Court Rule 74.01(b), the trial court certified that there was no just reason for delay and that the judgment as to Green Tree/Conseco was a final and appealable judgment. Grellner appeals.

II. DISCUSSION
This Court reviews the grant of a motion to dismiss de novo. Lynch v. Lynch, 260 S.W.3d 834, 836 (Mo. banc 2008).
In its Order, Judgment and Decree dismissing Green Tree/Conseco from the case, the trial court stated that the basis for the dismissal was Conseco's bankruptcy discharge and the supporting exhibits attached to the motion.
"In ruling on a motion to dismiss, the trial court can only consider the pleadings, and appellate review is also limited to the pleadings." L.C. Dev. Co., Inc. v. Lincoln County, 26 S.W.3d 336, 339 (Mo.App. E.D. 2000).
In granting Green Tree/Conseco's motion to dismiss based on Conseco's bankruptcy discharge and supporting exhibits, the trial court considered matters outside of the pleadings. Per Missouri Supreme Court Rule 55.08, a discharge in bankruptcy is an affirmative defense, and affirmative defenses necessarily include facts outside the pleadings. See City of Peculiar v. Effertz Bros. Inc., 254 S.W.3d 51, 59 (Mo. App. W.D.2008) (citing Black's Law Dictionary for the proposition that "[a]n affirmative defense contemplates additional facts not included in the allegations necessary to support plaintiff's case. . . ."). Moreover, "[a]n affirmative defense is a defendant's assertion raising new facts and arguments that, if true, will defeat the plaintiff's or prosecutor's claim, even if all the allegations in the complaint are true." Velda City v. Williams, 41 S.W.3d 915, 918 (Mo. App. E.D.2001).
While a trial court is not permitted to review matters outside the pleadings in ruling on a motion to dismiss, its hands are not entirely tied in this respect. Missouri Supreme Court Rule 55.27(a) allows trial courts to treat a motion to dismiss for failure to state a claim as a motion for summary judgment when the moving party includes matters outside the petition for the court's consideration. While the language of the Rule limits this "conversion" to motions to dismiss for failure to state a claim upon which relief can be granted, our courts have also endorsed converting a motion to dismiss into a motion for summary judgment when the motion to dismiss is based on an affirmative defense. See Dwyer v. Meramec Venture Assocs., L.L.C., 75 S.W.3d 291, 292 n. 1 (Mo.App. E.D.2002) (converting a motion to dismiss predicated on a bankruptcy discharge into a motion for summary judgment because the court considered matters outside the petition, namely the debtor's discharge in bankruptcy); see also Snelling v. Southwestern Bell Tel. Co., 996 S.W.2d 601, 604 (Mo.App. E.D.1999) (stating that, "the trial court considered and granted SWBT's motion to dismiss based on this affirmative defense and converted it to a motion for summary judgment").
Before a trial court may treat a motion to dismiss as a motion for summary judgment, *354 however, it must notify the parties that it is going to do so and give the parties an opportunity to present all materials pertinent to a motion for summary judgment. Turner Eng'g, Inc. v. 1491155 Weldon Parkway, L.L.C., 40 S.W.3d 406, 408 (Mo.App. E.D.2001).
Because the trial court considered the bankruptcy discharge, a matter clearly outside the pleadings, we believe that Green Tree/Conseco's motion to dismiss should have been treated as a motion for summary judgment. Thus, we reverse and remand with directions to the trial court to allow Green Tree/Conseco to re-file its motion in compliance with Missouri Supreme Court Rule 74.04(c), the Rule governing summary judgment, and to order the opposing party, Grellner, to follow the requirements of Rule 74.04 as well.

III. CONCLUSION
The judgment of the trial court is reversed and remanded for further proceedings consistent with this opinion.
LAWRENCE E. MOONEY and GEORGE W. DRAPER III, JJ., Concur.
NOTES
[1]  Green Tree alleges that it purchased Conseco's assets free and clear of all liens, claims, and encumbrances in June 2003. Though Conseco subsequently changed it name to Green Tree Servicing, LLC, for the sake of clarity we will reference Green Tree as Green Tree/Conseco throughout this opinion.
[2]  Green Tree is Foremost's agent.
[3]  Grellner claimed that Lamar did not accurately complete the mobile home sale paperwork, and that the resulting Transfer of Equity Agreement that Lamar submitted to Green Tree contained missing notations relating to purchase price and insurance coverage information.
[4]  Foremost and Lamar also filed motions to dismiss Grellner's petition. The trial court denied the motions in part and granted them in part, without prejudice, and allowed Grellner 20 days in which to file an amended petition with respect to Foremost and Lamar.
