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; }

}

  • Automated resolution only happens within the configuration class, or classes referenced within it (e.g. if you have properties that use other classes).  For the identifiers you have in other situations you can explicitly call the "Resolve" method to force it to resolve, if needed.

    If you are not using the configuration class directly (which is what's recommended), how are you loading/saving the configuration?

  • I am using the classes directly within the Configuration file

    The only difference is that instead of having one file for the Configuration and one other file for the nested config class within the same project, the config class is in another project, which is referenced in the main vaf project

  • I would have expected that to work. Are you referencing the same versions of packages across all projects (e.g. VAF, VAF config, etc.)?

    If you have a simple repro of it then please share and I or someone can take a quick look perhaps. 

  • Hi Craig,

    I created a small project to show you the problem.

    How can I send the repro project to you ?

    Thx

  • Send me a private message on here.  I seem to recall you can attach files.

  • 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;
    }