Following the example here: https://github.com/Microsoft/bond/tree/master/examples/cs/core/decimal
I am trying to use decimal in a struct that is not in the base namespace and get the exception "Expression of type 'System.Decimal' cannot be used for assignment to type 'System.ArraySegment`1[System.Byte]'".
If I keep all structs in the same namespace, everything works great. Is there some type of qualifying I have to do?
I've put together a small project and a couple unit tests to demonstrate: https://github.com/oculuss/BondDecimalExample
TestA has everything in the same namespace. TestB has a few sub-namespaces (and is what breaks).
A BondTypeAliasConverter must be defined "in the same assembly and namespace as the class representing the Bond schema(s) in which the type alias is used or assembly/namespace of one of the types being converted." It cannot be defined in a parent namespace. The search algorithm isn't that smart. :-) Thus, in TestB, you need to put the BondTypeAliasConverter class in the C# namespace "BondExampleB.Global.SecondType.SecondTypeA" (or wherever you've mapped that to in C#).
There are an open design proposal to make this a bit easier. See issue #594 in the Bond GitHub project.
Until something comes from that, if you want to have the same converters for types in different namespaces, you'll need to do something like this:
namespace Util
{
public static class BondTypeAliasConverter
{
public decimal Convert(ArraySegment<byte> blob, decimal unused) { ... }
public ArraySegment<byte> Convert(decimal d, ArraySegment<byte> unused) { ... }
}
}
namespace First
{
public static class BondTypeAliasConverter
{
public decimal Convert(ArraySegment<byte> blob, decimal unused)
{
return Util.BondTypeAliasConverter.Convert(blob, unused);
}
....
}
}
namespace First.Second
{
public static class BondTypeAliasConverter
{
public decimal Convert(ArraySegment<byte> blob, decimal unused)
{
return Util.BondTypeAliasConverter.Convert(blob, unused);
}
....
}
}