Set value of file field using entity_metadata_wrapper non working I have a custom entity with a file field accepting multiple values.
I would like to set file values according to
https://www.drupal.org/docs/7/api/entity-api/entity-metadata-wrappers#example-value-set-save but none of the two methods are working here.
I always get this error

error  php  Error: Call to a member function set() on null in include().


I am running Drupal 7, file_entity module enabled. Here follows the code:

$file = file_load(8172);
$wrapper = entity_metadata_wrapper('sys_ind', 13718);
$wrapper-&gt;field_allegati-&gt;file-&gt;set( $file );
$wrapper-&gt;save();
Fixed! Thanks to this post Save a new value with entity_metadata_wrapper to an entity field which is an array

$file = file_load(8172);
$node = entity_load('sys_ind', array(13718));
$wrapper = entity_metadata_wrapper('sys_ind', '13718');

$wrapper-&gt;field_allegati[NULL]-&gt;file-&gt;set( $file ); # This worked

$wrapper-&gt;save();


so the fix is using NULL (at least in multivalue field like mine is), not 0 or any other index nor [].