Skip to content

Google.Protobuf.ByteString needs to have a constructor with 0 args or only optional args. When mapping to byte[] #3598

@schhwork

Description

@schhwork

Im getting the exception in the title still. I found an old issue #1457 where the same exception was discussed and @jbogard confimed it was a bug or missing feature if i understood that correctly. Ive reproduced this in a spikeproject just to confirm nothing else was affecting it. It seems that the value of my sorceproperty don't matter if its null or not. If i do the conversion outside on automapper it works fine.

Source/destination types

public class Source
{
    public byte[] Bytes { get; set; }
}

public class Destination
{
    public ByteString Bytes { get; set; }
}

Mapping configuration

var mapperConfiguration = new MapperConfiguration(cfg =>
{
    cfg.CreateMap<Source, Destination>();
    cfg.CreateMap<byte[], ByteString>().ConstructUsing(x => ByteArrayToByteString(x));
});

private ByteString ByteArrayToByteString(byte[] arg)
{
    return arg != null ? ByteString.CopyFrom(arg) : null;
}

Version: 10.1.1

Expected behavior

ByteString mapped with contents of byte[]

Actual behavior

Google.Protobuf.ByteString needs to have a constructor with 0 args or only optional args.

Steps to reproduce

var source = new Source(); 

mapper.Map<Destination>(source);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions