XAML Verification

Since R2 2023 SP1 the XamlFormatProvider automatically verifies the types used in the imported XAML. It makes sure that all used types are from for the trusted assemblies. This mechanism prevents any unknown types loading and is enabled by default.

Disable the default verification

If you are sure that the imported XAML can be trusted for example it comes internally form your organization you can disable the default verification. This can be achieved by using the PreProcessingXaml event.

Example 1: Disable the default XAML validation

XamlFormatProvider provider = new XamlFormatProvider(); 
provider.ImportSettings.PreProcessingXaml += (s, args) => {  
 
    args.SkipXamlValidation = true; 
}; 

Add custom assembly to the allowed assemblies.

If you have a custom types that are saved in your XAML you can include them in the allowed assemblies collection. This way the verification process will succeed.

Example 2: Add assemblies to the AllowedAssemblies collection

XamlFormatProvider provider = new XamlFormatProvider(); 
provider.ImportSettings.AllowedAssemblies.Add("MyAssemblyName"); 

See Also

In this article