I read Hyperlink with answers and have tried to apply the technique to my environments that I have defined using the ntheorem package.

In the MWE below the answer links correctly go to the questions, but the questions do not go to the answers. How can this be fixed?

\documentclass{report}
\usepackage{ntheorem}
\usepackage{changepage}
\usepackage{lipsum}
\usepackage{hyperref}

\makeatletter
\newtheoremstyle{hanging}%
\makeatother

% problem environment
\newlength{\problabel}
\theoremstyle{hanging}
\theoremprework{%
\hypertarget{prob:\theproblem}{}%
\settowidth{\problabel}{\textbf{\theproblem} }%
\newtheorem{problem}{}

% solution environment
\Newassociation{sol}{Soln}{solutionfilehandle}
\renewenvironment{Soln}[1]
{}

\begin{document}

\Opensolutionfile{solutionfilehandle}[ans1]

\section{Problems}
\begin{problem}
\lipsum[1]
\begin{sol}
First solution.
\end{sol}
\end{problem}

\begin{problem}
\lipsum[2]
\begin{sol}
second solution.
\end{sol}
\end{problem}

\Closesolutionfile{solutionfilehandle}
\newpage
\section{Solutions}
\input{ans1}
\end{document}

EDIT: It also helped to have the target first:

% solution environment
\Newassociation{sol}{Soln}{solutionfilehandle}
\renewenvironment{Soln}[1]