first of all, as a side note, you should move var list = mediafiles.ToList(); to outside of the for loop
second of all, can you check if list[i].ContentLink is not throwing the null reference exception itself ?
new ContentReference(currentBlock.Folder) - this also does not look right to me. how does currentBlock.Folder look like?
new ContentReference(currentBlock.Folder) is just where the folder id comes in because and that part is not null and neither is the list[i].ContentLink. Also thanks I missed that the list was being made inside the loop, but that change didnt fix the null exception. I also confirmed that the _contentRepository and the AccessLevel are not throwing null themsevles
my (1) point was not meant to solve the problem, it's just a small thing that I spotted and can't keep quiet - old habit die hard.
so could you trace down there the null ref exception is thrown?
Nope I am not still not sure why it is happening but I found _contentRepository.Service.MoveToWasteBasket() is working fine with the same set up. So I may be able to work around it.
Maybe you can debug it? or turn on debug mode (including the pdb to the bin folder) to see which line is throwing the exception ?
Could it be that your loop is trying to access content that was already deleted?
Maybe do a foreach-loop instead of a for-loop. That will simplify the code, and do forward-only iteration.
Hi,
I have been trying to programmatically delete media files with contentRepository.Delete() and every time I run it I get a NullReference Exception.
the code looks like something like this: