Conrail officials and the Kenney administration have spent the last five months pursuing a shared goal: finding a way to clean up a half-mile stretch of train tracks in Kensington and Fairhill where heroin addicts often go to die.

For a time, both sides seemed to believe they would be able to jointly address the nightmares that have lurked alongside the tracks for decades -- a sea of used needles and trash, grimy makeshift shelters, the constant specter of death and desperation. But those efforts hit a wall and have now taken a contentious turn.

On Thursday morning, Kenney chided Conrail during a community meeting at a Salvation Army shop in Kensington for its "failure to clean and secure their own property," and announced that the Department of Licenses and Inspections had issued multiple property-maintenance code violation notices to the rail company over the condition of the land around the tracks.

Kenney said the city had spent tens of millions of dollars to fight drug trafficking in the area during the last decade.

"However, if we are going to make real progress, we need Conrail to be a partner in this effort," he said.

The rail company will have 30 days to respond to the L&I violations, which cite inadequate fencing, multiple unlawful and dangerous structures, poor sanitation, and overgrown vegetation. The city indicated it was prepared to take legal action to force Conrail to act.

The Department of Public Health  on Thursday labeled the area a public health nuisance, a designation that came almost two months after an Inquirer and Daily News project showed what was happening at the gorge, which runs from Second Street and Indiana Avenue to Kensington Avenue.

According to the Medical Examiner's Office, 17 people who died from drug overdoses in 2016 were found near the tracks, and 29 nonfatal overdoses were treated by city medics at the site.

Conrail officials were surprised by Kenney's tough public stance.

The company said in a statement that it had been engaged in "productive good-faith discussions" with the city and neighborhood community groups to craft possible solutions to the problems.

"Recently, however, the city has cut off dialogue with Conrail and pursued a more adversarial approach," the statement read in part. "We continue to work with community organizations on this intractable social issue and, with their support, hope to move toward a more comprehensive solution soon."

So what prevented the two sides from reaching an agreement in the first place? The answer depends on whom you talk to.

Email records obtained by the Inquirer and Daily News show that representatives from the city and Conrail were amicably discussing terms of a memorandum of understanding in December.

They conducted a joint inspection of the railway site, and as of last month were mulling over a term sheet with a block-by-block plan to remediate the area.

According to a copy of the term sheet, Conrail was expected to do the bulk of the heavy lifting: removing and disposing of needles, hazardous materials, debris, and overgrown vegetation, and repairing and installing fences.

The city, meanwhile, was expected to haul away and dispose of nonhazardous materials, increase police patrols in the area, secure the four bridges that cross the rail line, and add barriers on sidewalks to prevent the new fencing from being tampered with.

The discussions reached a standstill late last month.

"There were conversations and correspondences, but there's been no commitment from Conrail as to moving forward with a plan," said a source familiar with the city's position.

"We had to do something [Thursday] because those conversations stalled. Hopefully Conrail will come to the table in a real way."

A Conrail source who agreed to speak anonymously said the city "kept shifting the target. We'd have in-person meetings where we'd feel like [both sides] had an idea of what we're going to do, and then they'd follow up with a letter that was completely contrary to what we'd all agreed to."

With the city and the rail company turning to saber-rattling, the gorge and its ills will remain.

"Basta ya. Enough is enough," said City Councilwoman Maria Quiñones-Sánchez, whose district includes the Conrail tracks.

"This is about responsibility and accountability, from Conrail and from the city, and we need to make sure that state and federal officials and agencies are at the table in a real, meaningful way."