title: Mapping of protobuf's RepeatedField<T> type
body: <p>Given these source classes (used in an EFCore application) </p>
  
  <pre><code>class StudentCourse
  {
      public int StudentId { get; set; }
      public int CourseId { get; set; }
  }
  
  class Student
  {
      public virtual ICollection&lt;StudentCourse&gt; Courses { get; set; }
  }
  </code></pre>
  
  <p>and the following <code>Protobuf</code> message</p>
  
  <pre><code>message StudentDto {
      repeated int32 courseIds = 1;
  }
  </code></pre>
  
  <p>How am I able to map <code>Student.Courses</code> to <code>StudentDto.CourseIds</code> using <code>AutoMapper</code>?<br>
  So far I tried the following:  </p>
  
  <pre><code>class StudentProfile : Profile
  {
      class Converter : IValueConverter&lt;ICollection&lt;StudentCourse&gt;, RepeatedField&lt;int&gt;&gt;
      {
          public RepeatedField&lt;int&gt; Convert(ICollection&lt;StudentCourse&gt; sourceMember, ResolutionContext context)
          {
              return new RepeatedField&lt;int&gt; { sourceMember.Select(x =&gt; x.CourseId) };
          }
      }
  
      public StudentProfile()
      {
          CreateMap&lt;Student, StudentDto&gt;()
              .ForMember(dst =&gt; dst.CourseIds, o =&gt; o.MapFrom(src =&gt; src.Courses.Select(x =&gt; x.CourseId)));
              //.ConvertUsing(student =&gt; new StudentDto{CourseIds = { student.Courses.Select(x =&gt; x.CourseId)}});
              //.ForMember(dst =&gt; dst.CourseIds, o =&gt; o.ConvertUsing(new Converter(), src =&gt; src.Courses));
      }
  }
  
  class Program
  {
      static void Main(string[] args)
      {
          var student = new Student
          {
              Courses = new List&lt;StudentCourse&gt;
              {
                  new StudentCourse { CourseId = 1, StudentId  = 1 },
                  new StudentCourse { CourseId = 6, StudentId  = 1 },
                  new StudentCourse { CourseId = 11, StudentId = 1 }
              }
          };
  
          IMapper mapper = new Mapper(new MapperConfiguration(cfg =&gt; cfg.AddProfile(new StudentProfile())));
  
          var mapped = mapper.Map&lt;StudentDto&gt;(student);
          // Expecting: {{ "courseIds": [ 1, 6, 11 ] }}
          // Actually: {{ }}
      }
  }
  </code></pre>
  
  <p>The <code>ConvertUsing</code> statement in <code>StudentProfile</code> works and maps the member correctly but as the classes I'm using in my project are far more complex, this is really the last option I would like to use.  </p>
  
  <p>Does anyone of you know the cause and a possible fix for this problem?<br>
  I'm using <code>Google.Protobuf 3.7.0</code> and <code>AutoMapper 8.0.0</code>.</p>
  
  <p><strong>Edit:</strong><br>
  I already checked the execution plan but couldn't find any errors in there.<br>
  For the sake of completeness here I'll attach it here:  </p>
  
  <pre><code>(src, dest, ctxt) =&gt;
  {
      StudentDto typeMapDestination;
      return (src == null)
          ? null
          : {
              typeMapDestination = dest ?? new StudentDto();
              try
              {
                  var resolvedValue =
                  {
                      try
                      {
                          return ((src == null) || ((src.Courses == null) || false))
                              ? null
                              : src.Courses.Select(x =&gt; x.CourseId);
                      }
                      catch (NullReferenceException)
                      {
                          return null;
                      }
                      catch (ArgumentNullException)
                      {
                          return null;
                      }
                  };
  
                  var propertyValue = (resolvedValue == null)
                      ? {
                          var collectionDestination = (ICollection&lt;int&gt;)((dest == null) ? null : typeMapDestination.CourseIds);
  
                          if ((collectionDestination == null) || collectionDestination.IsReadOnly)
                          {
                          }
                          else
                          {
                              collectionDestination.Clear();
                          }
  
                          return new RepeatedField&lt;int&gt;();
                      }
                      : {
                          var passedDestination = (dest == null) ? null : typeMapDestination.CourseIds;
                          var collectionDestination = ((passedDestination == null) || ((ICollection&lt;int&gt;)passedDestination).IsReadOnly)
                              ? new RepeatedField&lt;int&gt;()
                              : passedDestination;
                          collectionDestination.Clear();
  
                          var enumerator = resolvedValue.GetEnumerator();
                          while (true)
                          {
                              if (enumerator.MoveNext())
                              {
                                  var item = enumerator.Current;
                                  collectionDestination.Add(item);
                              }
                              else
                              {
                                  break;
                              }
                          }
  
                          return collectionDestination;
                      };
  
                  return propertyValue;
              }
              catch (Exception ex)
              {
                  throw new AutoMapperMappingException(
                      "Error mapping types.",
                      ex,
                      AutoMapper.TypePair,
                      TypeMap,
                      PropertyMap);
  
                  return null;
              }
  
              return typeMapDestination;
          };
  };
  </code></pre>