diff --git a/GUI/Model/Mask/MasksSet.cpp b/GUI/Model/Mask/MasksSet.cpp
index 9e8efc75ee801620003b556ef90d218a6d59f30c..ed01694bff2164ff3956cc171fe107691c6d9ccd 100644
--- a/GUI/Model/Mask/MasksSet.cpp
+++ b/GUI/Model/Mask/MasksSet.cpp
@@ -40,7 +40,7 @@ RegionOfInterestItem* MasksSet::regionOfInterestItem() const
 void MasksSet::writeTo(QXmlStreamWriter* w) const
 {
     for (const MaskItem* t : *this)
-        XML::writeChosen<MaskCatalog>(t, w, Tag::Mask);
+        XML::writeChosen<MaskItem, MaskCatalog>(t, w, Tag::Mask);
 }
 
 void MasksSet::readFrom(QXmlStreamReader* r)
diff --git a/GUI/Model/Sample/CompoundItem.cpp b/GUI/Model/Sample/CompoundItem.cpp
index 669ca7a9d11bfbc2dd002803af63c2a41428925c..c5d6e9514437e3902f7732957ca908ea6a3a9762 100644
--- a/GUI/Model/Sample/CompoundItem.cpp
+++ b/GUI/Model/Sample/CompoundItem.cpp
@@ -63,7 +63,7 @@ void CompoundItem::writeTo(QXmlStreamWriter* w) const
 {
     XML::writeBaseElement<ItemWithParticles>(w, XML::Tag::BaseData, this);
     for (auto* t : m_particles)
-        XML::writeChosen<ParticleCatalog>(t, w, Tag::Particle);
+        XML::writeChosen<ItemWithParticles, ParticleCatalog>(t, w, Tag::Particle);
     XML::writeTaggedValue(w, Tag::ExpandCompoundGroupbox, expandCompound);
 }
 
diff --git a/GUI/Model/Sample/ParticleLayoutItem.cpp b/GUI/Model/Sample/ParticleLayoutItem.cpp
index dee3a350744e1db33504df92c4735d6cf7394ed6..8e9ddca28e6bb77cf8e4a46541735ab4fd5c6cdf 100644
--- a/GUI/Model/Sample/ParticleLayoutItem.cpp
+++ b/GUI/Model/Sample/ParticleLayoutItem.cpp
@@ -101,7 +101,7 @@ void ParticleLayoutItem::writeTo(QXmlStreamWriter* w) const
     m_own_density.writeTo2(w, Tag::OwnDensity);
     XML::writeTaggedElement(w, Tag::InterferenceFunction, m_interference);
     for (auto* t : m_particles)
-        XML::writeChosen<ParticleCatalog>(t, w, Tag::Particle);
+        XML::writeChosen<ItemWithParticles, ParticleCatalog>(t, w, Tag::Particle);
     XML::writeTaggedValue(w, Tag::ExpandLayoutGroupbox, expandParticleLayout);
     XML::writeTaggedValue(w, Tag::ExpandInterferenceGroupbox, expandInterference);
 }
diff --git a/GUI/Model/Sim/InstrumentsSet.cpp b/GUI/Model/Sim/InstrumentsSet.cpp
index 31f0f619a1f1682cf87696025adde09e2d16cc5e..f94a7e351b518d12cd5573da3f17911cb0e5eab1 100644
--- a/GUI/Model/Sim/InstrumentsSet.cpp
+++ b/GUI/Model/Sim/InstrumentsSet.cpp
@@ -30,7 +30,7 @@ InstrumentsSet::~InstrumentsSet() = default;
 void InstrumentsSet::writeTo(QXmlStreamWriter* w) const
 {
     for (const InstrumentItem* t : *this)
-        XML::writeChosen<InstrumentCatalog>(t, w, Tag::Instrument);
+        XML::writeChosen<InstrumentItem, InstrumentCatalog>(t, w, Tag::Instrument);
     XML::writeTaggedValue(w, Tag::CurrentIndex, (int)currentIndex());
 }
 
diff --git a/GUI/Model/Util/UtilXML.h b/GUI/Model/Util/UtilXML.h
index 47aa3aaacad14b6972459d120cc8ddc8c79e62bc..205dc4ef182f7b6b4611054e9b9eb3f0f656f94f 100644
--- a/GUI/Model/Util/UtilXML.h
+++ b/GUI/Model/Util/UtilXML.h
@@ -125,21 +125,21 @@ typename C::BaseItem* readChosen(QXmlStreamReader* r, const QString& tag, Args..
     return t;
 }
 
-template <typename C> void writeItemTo(const typename C::BaseItem* t, QXmlStreamWriter* w)
+template <typename B, typename C> void writeItemTo(const B* t, QXmlStreamWriter* w)
 {
     const uint typeIndex = static_cast<uint>(C::type(t));
-    XML::writeAttribute(w, XML::Attrib::type, typeIndex);
+    writeAttribute(w, Attrib::type, typeIndex);
     // The next line allows to see the name of item type in XML. May be skipped while reading.
-    XML::writeAttribute(w, XML::Attrib::kind, C::uiInfo(C::type(t)).menuEntry);
+    writeAttribute(w, Attrib::kind, C::uiInfo(C::type(t)).menuEntry);
     if (t)
         t->writeTo(w);
 }
 
-template <typename C>
-void writeChosen(const typename C::BaseItem* t, QXmlStreamWriter* w, const QString& tag)
+template <typename B, typename C>
+void writeChosen(const B* t, QXmlStreamWriter* w, const QString& tag)
 {
     w->writeStartElement(tag);
-    XML::writeItemTo<C>(t, w);
+    writeItemTo<B, C>(t, w);
     w->writeEndElement();
 }