Reference to wrong appendix

In my report I have quite a lot of appendices (pdf's). I want to refer to them as A.1, A.2.....and so on It all works fine for A , B and C, but when i refer to any appendix under C, the refrence in the output pdf is printed as C.3.

In the code I use \ref{appendix:....}

\newpage
\pagenumbering{roman}
\appendix
\noappendicestocpagenum
\renewcommand{\appendixtocname}{Vedlegg}

\newpage

\includepdf[pages = 1, scale = 0.72, fitpaper=true, pagecommand ={\section{B}\label{appendix:B}}, linktodoc = true]{B.pdf}

\newpage

\section{C}
\subsection{C.1}
\label{appendix:C.1}
\includegraphics[scale = 2]{C.1.jpg}
\newpage

\subsection{C.2}
\label{appendix:C.2}
\begin{center}
\includegraphics[scale = 0.8]{C.2.jpg}
\end{center}

\newpage

\subsection{C.3}
\includegraphics[scale = 0.9]{C.3.jpg}\label{appendix:C.3}

\newpage
\includepdf[pages = 1, scale = 0.65, fitpaper=true, pagecommand ={\section{D}\subsection{D.1}\label{appendix:D.1}}, linktodoc = true]{D.1.pdf}
\newpage

\includepdf[pages = 1, scale = 0.72, fitpaper=true, pagecommand ={\subsection{D.2}}\label{appendix:D.2}, linktodoc = true]{D.2.pdf}

• I had the labels outside pagecomand{}.., Problem soved – Marte Tostrup May 14 '18 at 16:27

I had the labels outside \pagecomand{...}. Problem soved!
• Your code example has all the \labels within the \pagecommand. So, how does this answer help? – Werner May 14 '18 at 17:05