Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeroen Breuer 4861 posts 12135 karma points MVP 3x admin c-trib
    Feb 23, 2017 @ 13:37
    Jeroen Breuer
    0

    Object reference not set to an instance of an object after import with new properties

    Hello,

    I'm using CMS import (3.5.3) with Umbraco 7.5.3 to update existing members. I've added 3 new properties to the member type and also added these as fields in the Excel file and the mapping. When I try to run the import I get the following exception:

    Error while importing data for property 'propAlias', datasource record Email = 'test@test.com', Error :Object reference not set to an instance of an object. 
    

    This is in the log:

     2017-02-23 14:25:23,350 [P11016/D8/T110] ERROR CMSImportLibrary.Providers.ImportProviders.Member.MemberImportProvider - CMSImport:CMSImport: A record failed to import for aliaspropAlias
    System.NullReferenceException: Object reference not set to an instance of an object.
       at CMSImportLibrary.Providers.ImportProviders.Member.MemberImportProvider.(ImportState , Dictionary`2 , AdvancedSettingFieldOptions , String , ImportActions , Member , PropertyInfo , Object  , Boolean  )
       at CMSImportLibrary.Providers.ImportProviders.Member.MemberImportProvider.ImportMembers(ImportState state, ImportStatistics importStatistics, User importAsUser)
     2017-02-23 14:25:23,412 [P11016/D8/T110] INFO  CMSImport.Extensions.Providers.ImportProviders.ImportProvider - CMSImport:Import task Import company finished, Records in datasource: 1, Records  Added 0, Records  Updated 0, Records skipped 0, Records deleted 0, Errors 1, duration 00:00:04 
    

    I don't get the error if I first save the member. So after saving the member it probably has the new properties I've added to the member type. The problem is we've got thousands of members and we can't just save them all. Is this a bug in CMS Import or Umbraco?

    I've checked our events, but they don't do anything with the new attributes and also don't throw any errors when debugging.

    Jeroen

  • Jeroen Breuer 4861 posts 12135 karma points MVP 3x admin c-trib
    Feb 28, 2017 @ 10:12
    Jeroen Breuer
    0

    As suggested on Twitter I tried upgrading to CMS Import 3.6, but I still get the same errors when I try to import.

    Any suggestions on how I can do an import on existing members that have new properties?

    Jeroen

  • Richard Soeteman 3829 posts 11860 karma points MVP
    Feb 28, 2017 @ 14:42
    Richard Soeteman
    0

    It's because CMSImport is using the old Member API since it supports V6 also. And that throws an exception when requesting the property or tries to save the member.

    The second time works on my machine. CMSImport will also get a major release this year where legacy code is removed. Content is already using the content service only members require the legacy code since that service was missing in V6 :-(

    Best,

    Richard

  • Jeroen Breuer 4861 posts 12135 karma points MVP 3x admin c-trib
    Mar 01, 2017 @ 14:12
    Jeroen Breuer
    100

    As a workaround you could save the member during the importing event to make sure a member has all the properties:

    ImportProvider.RecordImporting += RecordImporting;
    
    private static void RecordImporting(object sender, RecordImportingEventArgs e)
    {
        var member = sender as Member;
        if (member != null)
        {
            // Get the member and save him with MemberService.
            // Workaround for https://our.umbraco.org/projects/developer-tools/cmsimport/bugs/84175-object-reference-not-set-to-an-instance-of-an-object-after-import-with-new-properties
            var service = ApplicationContext.Current.Services.MemberService;
            var m = service.GetById(member.Id);
            if (m != null)
            {
                service.Save(m);
            }
    
            // After the member has been saved with the new MemberService we need to get the member with the old API.
            // This way the member should have all the properties.
            member = new Member(member.Id);
        }
    }
    

    Jeroen

  • Jeroen Breuer 4861 posts 12135 karma points MVP 3x admin c-trib
    Apr 05, 2017 @ 10:40
    Jeroen Breuer
    0

    In the logs I now get this exception regularly:

    CMSImport RecordImporting failed.
    System.ArgumentException: Cannot save member with empty name.
       at Umbraco.Core.Services.MemberService.Save(IMember entity, Boolean raiseEvents)
       at Project.Business.Logic.MemberRepository.SaveMember(Int32 memberId)
       at Project.Data.CmsImport.Events.Events.RecordImporting(Object sender, RecordImportingEventArgs e)
    

    It seems related to the workaround for saving the member. Is there a better solution for this problem available?

    Jeroen

  • Richard Soeteman 3829 posts 11860 karma points MVP
    Apr 06, 2017 @ 06:12
    Richard Soeteman
    0

    Hi Jeroen,

    I've created a separate provider (not finished yet) that uses the member service. Can you try with that one? https://www.dropbox.com/s/a9ng74tsn2no5oz/CMSImport.MemberServiceImportProvider.dll?dl=0

  • Jeroen Breuer 4861 posts 12135 karma points MVP 3x admin c-trib
    Apr 06, 2017 @ 14:26
    Jeroen Breuer
    0

    I've tried the provider, but I'm getting this error now:

    Could not load file or assembly 'CMSImport.Resources'

    Do I need an extra dll or NuGet package?

    Jeroen

  • Richard Soeteman 3829 posts 11860 karma points MVP
    Apr 06, 2017 @ 14:30
    Richard Soeteman
    0

    Next week I will officially release 3.7 then the dll will work but just send you a new package over skype as well.

Please Sign in or register to post replies

Write your reply to:

Draft