0
Completed

Better exception message for invalid cast in EntityMultiValueObjectTypeSchemaValidator.CreateValue

Adam van Vliet 14 years ago updated by anonymous 9 years ago 3

A better exception message should be provided for invalid casts in EntityMultiValueObjectTypeSchemaValidator.CreateValue.

When the data type in the connector configuration does not match the data type in FIM, on export, when the value is created the below exception will be thrown.

EntityMultiValueObjectTypeSchemaValidator.cs:line 62 refers to the line where the value is cast to IEnumerable<object>.

A better exception message should be provided.

System.InvalidCastException: Unable to cast object of type 'Unify.Framework.MultiValue`1[Unify.Framework.DistinguishedNameValue]' to type 'System.Collections.Generic.IEnumerable`1[System.Object]'.
   at Unify.Framework.EntityMultiValueObjectTypeSchemaValidator`3.CreateValue(Object dataValue) in S:\hg\Framework\Core\v3.0.4\Source\Entity\Unify.Framework.Entity.Schema\EntityMultiValueObjectTypeSchemaValidator.cs:line 62
   at Unify.Framework.EntitySchemaFieldDefinition.CreateValue(Object dataValue) in S:\hg\Framework\Core\v3.0.4\Source\Entity\Unify.Framework.Entity.Schema\EntitySchemaFieldDefinition.cs:line 36
   at Unify.Framework.EntitySchemaValueTransformer.Transform(IEntity baseValue) in S:\hg\Framework\Core\v3.0.4\Source\ChangeDetection\Unify.Framework.ChangeDetection\EntitySchemaValueTransformer.cs:line 46
   at Unify.Framework.Adapter.<>c__DisplayClass19.<SaveEntities>b__b(<>f__AnonymousType2`2 <>h__TransparentIdentifier6) in S:\hg\Framework\Core\Master\Source\Adapter\Unify.Framework.Adapter\Adapter.cs:line 424
   at System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Unify.Framework.Adapter.SaveEntities(IEnumerable`1 entities, Boolean reflect) in S:\hg\Framework\Core\Master\Source\Adapter\Unify.Framework.Adapter\Adapter.cs:line 419
   at Unify.Framework.Adapter.SaveEntity(IAdapterEntity entity, Boolean reflect) in S:\hg\Framework\Core\Master\Source\Adapter\Unify.Framework.Adapter\Adapter.cs:line 387
   at Unify.Framework.Adapter.SaveEntity(IAdapterEntity entity) in S:\hg\Framework\Core\Master\Source\Adapter\Unify.Framework.Adapter\Adapter.cs:line 372
   at Unify.Framework.CompositeAdapter.SaveEntity(IAdapterEntity entity) in S:\hg\Framework\Core\Master\Source\Adapter\Unify.Framework.Adapter\CompositeAdapter.cs:line 215
   at Unify.Framework.AdapterNotifierDecorator.SaveEntity(IAdapterEntity entityToSave) in S:\hg\Framework\Core\Master\Source\Adapter\Unify.Framework.Adapter\AdapterNotifierDecorator.cs:line 200
   at Unify.Framework.LDIFAdapter.ExportAdapterEntity(IAdapterEntity adapterEntity, Guid adapterId) in S:\hg\Framework\Core\v3.0.4\Source\Adapter\Unify.Framework.Adapter.Remoting\LDIFAdapter.cs:line 118
   at Unify.Framework.LDIFAdapterServiceHostDecorator.ExportAdapterEntity(IAdapterEntity adapterEntity, Guid adapterId) in S:\hg\Framework\Identity Broker\v3.0\Source\Unify.Framework.ConnectEngine\LDIFAdapterServiceHostDecorator.cs:line 69
   at SyncInvokeExportAdapterEntity(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)",Normal

Reassigned due to new project ownership.

Please have a look at this item. Will require creating new unit tests (in the base unit test classes).

Will need to make the method EntityMultiValueObjectTypeSchemaValidator.CreateValue more powerful, eg:

public override IValue CreateValue(object dataValue)
{
	//Value is of correct type when saving
	if (dataValue is TValue)
		return (TValue) dataValue;

	//Create a multivalue when importing
	var dataValueAsEnumerable = (IEnumerable) dataValue;

	IList<T> values = (from object item in dataValueAsEnumerable
					   select (TValueBase) item
					   into castItem select _ValueConversion(castItem)).ToList();
	var convertedValue = new MultiValue<T>
	{
		Value =  values
	};

	return convertedValue;
}

And pass in the type that is mentioned in the exception to test. If that doesn't work straight away, please let me know.

Thanks.

Reassigned for confirmation of completion.