title: Orchard CMS ContentManager.New<>() Specified Cast Was Invalid
body: <p>I am in the early stages of developing a new module. </p>
  
  <p>Much of it is laid out in terms of the models etc. Also have the migrations all set up and my database now has the tables for my module.</p>
  
  <p>I am encountering the following error when calling <code>ContentManager.New&lt;myPart&gt;</code> and would like some help please.</p>
  
  <p>Error is this:</p>
  
  <pre><code>An unhandled exception has occurred and the request was terminated. Please refresh the page. If the error persists, go back
  Specified cast is not valid.
  System.InvalidCastException: Specified cast is not valid. 
  at Orchard.ContentManagement.ContentCreateExtensions.New[T]
                (IContentManager manager, String contentType) 
  </code></pre>
  
  <p>The chunk of code that fires the exception is this:</p>
  
  <pre><code>public static T New&lt;T&gt;(this IContentManager manager, string contentType) where T : class, IContent {
              var contentItem = manager.New(contentType);
              if (contentItem == null)
                  return null;
  
              var part = contentItem.Get&lt;T&gt;();
              if (part == null)
                  throw new InvalidCastException();
  
              return part;
          }
  </code></pre>
  
  <p>Here are the various parts to my module that are related to the operation i am struggling with:</p>
  
  <p><strong>ContentPart</strong> </p>
  
  <pre><code>public class GoogleMapsSettingsPart : ContentPart&lt;GoogleMapsSettingsPartRecord&gt;
  {
      public string ApiKey { 
          get { return Record.ApiKey; }
          set { Record.ApiKey = value; }
      }
  }
  </code></pre>
  
  <p><strong>ContentPartRecord</strong></p>
  
  <pre><code>public class GoogleMapsSettingsPartRecord : ContentPartRecord
  {
      public virtual string ApiKey { get; set; }
  }
  </code></pre>
  
  <p><strong>Handler</strong></p>
  
  <pre><code>public GoogleMapsSettingsPartHandler(IRepository&lt;GoogleMapsSettingsPartRecord&gt; repository)
          {
              Filters.Add(StorageFilter.For(repository));
          }
  </code></pre>
  
  <p><strong>Migration for this table</strong></p>
  
  <pre><code>// Settings Table
  SchemaBuilder.CreateTable("GoogleMapsSettingsPartRecord", table =&gt; table
         .ContentPartRecord()
         .Column("ApiKey", DbType.String, c =&gt; c.WithLength(60))
  );
  </code></pre>
  
  <p><strong>Some of the code from the controller for this model etc</strong></p>
  
  <pre><code>public AdminController(IContentManager contentManager, IShapeFactory shapeFactory, IServiceLocatorService serviceLocatorService, INotifier notifier)
          {
              _contentManager = contentManager;
              _serviceLocatorService = serviceLocatorService;
              _notifier = notifier;
              Shape = shapeFactory;
              T = NullLocalizer.Instance;
          }
  
  
          /// &lt;summary&gt;
          /// Display Settings
          /// &lt;/summary&gt;
          /// &lt;returns&gt;&lt;/returns&gt;
          public ActionResult Settings()
          {
              var settings = _serviceLocatorService.GoogleMapsSettings;
              var editor = CreateSettingsEditor(settings);
              var model = _services.ContentManager.BuildEditor(settings);
  
              return View((object)model);
          }
  </code></pre>
  
  <p><strong>Finally - the Services where my call throws this exception</strong></p>
  
  <pre><code>private GoogleMapsSettingsPart _settings;
          public GoogleMapsSettingsPart GoogleMapsSettings
          {
              get {
                  if (_settings == null)
                  {
                      _settings = _contentManager.Query&lt;GoogleMapsSettingsPart, GoogleMapsSettingsPartRecord&gt;().List().FirstOrDefault();
  
                      if (_settings == null)
                      {
                          _settings = _contentManager.New&lt;GoogleMapsSettingsPart&gt;("GoogleMapsSettings");
                      }
                  }
                  return _settings;
              }
          }
  </code></pre>
  
  <p>The actual line where the exception happens is <code>_settings = _contentManager.New&lt;GoogleMapsSettingsPart&gt;("GoogleMapsSettings");</code> </p>
  
  <p>I have tried all sorts of stuff in place of "GoogleMapsSettings" though nothing is working.</p>
  
  <p>I'm pretty sure at this point it's something simple, though it's avoiding me..My limited knowledge of Orchard is stumping me</p>
  
  <p>Any help would be appreciated :)</p>