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 = '[email protected]', 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.
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 :-(
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);
}
}
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?
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:
This is in the log:
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
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
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
As a workaround you could save the member during the importing event to make sure a member has all the properties:
Jeroen
In the logs I now get this exception regularly:
It seems related to the workaround for saving the member. Is there a better solution for this problem available?
Jeroen
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
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
Next week I will officially release 3.7 then the dll will work but just send you a new package over skype as well.
is working on a reply...