diff --git a/src/Generator/Passes/MarkUsedClassInternalsPass.cs b/src/Generator/Passes/MarkUsedClassInternalsPass.cs
index 0e3e7426..0c90d1df 100644
--- a/src/Generator/Passes/MarkUsedClassInternalsPass.cs
+++ b/src/Generator/Passes/MarkUsedClassInternalsPass.cs
@@ -57,6 +57,11 @@ namespace CppSharp.Passes
 
                 MarkUsedFieldTypes(decl, visitedDeclarationContexts);
             }
+            foreach (var @base in @class.Bases.Where(
+                b => b.IsClass && b.Class.Ignore && b.Class.Fields.Count > 0))
+            {
+                @base.Class.GenerationKind = GenerationKind.Internal;
+            }
         }
     }
 }
diff --git a/src/Generator/Passes/StripUnusedSystemTypesPass.cs b/src/Generator/Passes/StripUnusedSystemTypesPass.cs
index 4d111cb7..58b6a930 100644
--- a/src/Generator/Passes/StripUnusedSystemTypesPass.cs
+++ b/src/Generator/Passes/StripUnusedSystemTypesPass.cs
@@ -40,7 +40,8 @@ namespace CppSharp.Passes
 
         private bool TryMarkType(Type desugared)
         {
-            var tagType = desugared as TagType;
+            var templateType = desugared as TemplateSpecializationType;
+            var tagType = desugared as TagType ?? templateType?.Desugared.Type as TagType;
             if (tagType != null)
             {
                 var specialization = tagType.Declaration as ClassTemplateSpecialization;
@@ -56,7 +57,6 @@ namespace CppSharp.Passes
                 return true;
             }
 
-            var templateType = desugared as TemplateSpecializationType;
             if (templateType != null)
             {
                 var template = templateType.Template;
diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h
index 5f55bca0..31552a77 100644
--- a/tests/CSharp/CSharp.h
+++ b/tests/CSharp/CSharp.h
@@ -5,6 +5,7 @@
 #include <vector>
 #include <limits>
 #include <string>
+#include <mutex>
 #include "AnotherUnit.h"
 #include "ExcludedUnit.hpp"
 #include "CSharpTemplates.h"
@@ -201,6 +202,7 @@ protected:
     AbstractProprietor(int i);
     int m_value;
     long m_property;
+    std::mutex m_mutex;
 };
 
 class DLL_API Proprietor : public AbstractProprietor