Resolving configuration classes from external DLL

Hi,

I have remarked today that if I have a Configuration class, that uses a class from an external project, the MFIdentifier resolution is not made, is it a normal behaviour ? Is there a way to resolve them ?

I can of course get all the values, but the resolving is not working automatically

If I copy and paste the MFIdentifier declaration in the main Configuration Class, with the exact same property, it works, but that's not what I want to do

Code : 

namespace YYYY.YYYY.YYY

public class Configuration
{

[DataMember]
public List<ResponseMappingConfig> PropertyMappings { get; set; } = new List<ResponseMappingConfig>();

}

ResponseMappingConfig class is a class that come from another Visual studio project. 

Code : 

namespace XXX.XXX.XXX

[DataContract]

public class ResponseMappingConfig

{

[DataMember]

public string MappingName{get;set;}

...

[DataMember]
[MFPropertyDef(AllowEmpty = true)]
public MFIdentifier PropertyDefinition { get; set; }

}

Parents Reply Children
  • This can be done, but it's not a very extensible way at the moment.  The system does not see that it should resolve items because the type is outside of the current assembly.  You have a couple of options:

    1. (I think - I didn't try this) - you could move the configuration class into the shared assembly.  The default list of assemblies to load from includes just the one that the configuration class is in, so this could work.  I suspect it doesn't help with the problem you're trying to solve with the shared assembly though.

    2. You can override a method in your VaultApplication class and give it the assemblies to load types from.  The sample below adds the current assembly and the one for the ExternalClass in the example you gave me, but you could add others here too.

    protected override bool ValidateConfigurationAttributes(
    	Vault vault,
    	Configuration config,
    	out ValidationResultForValidation result
    )
    {
    	// Initialize return/out params.
    	bool isValid = true;
    	result = new ValidationResultForValidation();
    
    	// Identify the assemblies that contain config items.
    	System.Diagnostics.Debugger.Launch();
    	var assemblies = new []
    	{
    		this.GetType().Assembly,
    		typeof(ExternalClass).Assembly
    	};
    
    	// Validate the configuration.
    	isValid = this.MetadataStructureValidator.ValidateItem(vault, this.GetID(), config, result,
    			level: this.ValidationRecursionLimit, containingAssemblies: assemblies);
    
    	// Validate all types in the assembly of the application.
    	foreach (Type type in this.GetType().Assembly.GetLoadableTypes())
    	{
    		// Validate the current type, unless it is nested (they'll be traversed by validation).
    		if (!type.IsDefined(typeof(CompilerGeneratedAttribute), false) && !type.IsNested)
    		{
    			isValid = this.MetadataStructureValidator.ValidateItem(vault, type.FullName, type, result,
    						level: this.ValidationRecursionLimit, containingAssemblies: assemblies) && isValid;
    		}
    	}
    
    	return isValid;
    }