Unable to load System.componentModel.annotations


I am hitting a issue i’ve also hit with Unmanaged Exports. The solution there was using fody.costura so every external dll would be embedded.

I’ve included a sample project that shows the issue
Sample Project

Full explainer:

Our goal. Building a Aspnetboilerplate module that depends on their AbpAutoMapperModule that depends on the nuget package Automapper.
Then have that module consumed by delphi.
That’s just the sample, not our actual goal. Automapper will only be used on c# side, not on delphi side.

We have tested Hydra in combination with simple modules and that worked, however when depending on other not self build modules we are hitting some loading issues.

This is the exception we log when trying to load the AbpAutoMapperModule.
Translated it means, cannot load assembly System.ComponentModel.Annotations or one of it’s dependencies. The found manifest does not match the assembly reference.

System.IO.FileLoadException: Kan bestand of assembly System.ComponentModel.Annotations, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a of een van de afhankelijkheden hiervan niet laden. De manifestdefinitie van de gevonden assembly komt niet overeen met de assembly-verwijzing. (Uitzondering van HRESULT: 0x80131040)
Bestandsnaam: System.ComponentModel.Annotations, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
bij System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
bij System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
bij System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
bij System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
bij System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Int32 attributeCtorToken, Boolean mustBeInheritable)
bij System.Reflection.CustomAttribute.IsDefined(RuntimeType type, RuntimeType caType, Boolean inherit)
bij System.RuntimeType.IsDefined(Type attributeType, Boolean inherit)
bij System.Attribute.IsDefined(MemberInfo element, Type attributeType, Boolean inherit)
bij Abp.AutoMapper.AbpAutoMapperModule.<>c.b__5_0(Type type)
bij System.Linq.Enumerable.WhereArrayIterator1.MoveNext() bij System.Linq.Buffer1…ctor(IEnumerable1 source) bij System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)
bij Abp.Reflection.TypeFinder.Find(Func2 predicate) bij Abp.AutoMapper.AbpAutoMapperModule.FindAndAutoMapTypes(IMapperConfigurationExpression configuration) bij Abp.AutoMapper.AbpAutoMapperModule.<CreateMappings>b__4_0(IMapperConfigurationExpression configuration) bij AutoMapper.MapperConfiguration.Build(Action1 configure)
bij Abp.AutoMapper.AbpAutoMapperModule.CreateMappings()
bij Abp.AutoMapper.AbpAutoMapperModule.PostInitialize()
bij Abp.Modules.AbpModuleManager.<>c.b__15_2(AbpModuleInfo module)
bij System.Collections.Generic.List1.ForEach(Action1 action)
bij Abp.Modules.AbpModuleManager.StartModules()
bij Abp.AbpBootstrapper.Initialize()
bij TravelNote.Octopus.OctopusHydraPlugin…ctor() in E:\git\TravelNote\octopusclient\TravelNote.OctopusClient\TravelNote.Octopus.Hydra\OctopusHydraPlugin.cs:regel 26

WRSCH: registratie van assembly-bindingen is uitgeschakeld.
Als u assembly-bindingsfouten wilt registreren, stelt u de registerwaarde [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) in op 1.
Opmerking: er is een prestatiestraf gekoppeld aan de registratie van assembly-bindingsfouten.
Als u deze functie wilt uitschakelen, verwijdert u de registerwaarde [HKLM\Software\Microsoft\Fusion!EnableLog].

So in the sample project provided, you will see the following code in the hydra plugin.
_bootStrapper.Initialize() <= this is where the error happens.

    public OctopusHydraPlugin()
        _bootStrapper = AbpBootstrapper.Create<OctopusHydraModule>( o => 
        catch(Exception e)
            using (FileStream fs = new FileStream(@"d:\log.txt", FileMode.Append, FileAccess.Write))
            using (StreamWriter sw = new StreamWriter(fs))

        //_relationProxy = _bootStrapper.IocManager.IocContainer.Resolve<RelationApiProxy>();

I’ve also provided a Delphi 2007 host application with a button. That button will load the plugin as your docs describe.

Thank you for any help provided, if i need to explain more (probably) just ask :wink:


Thank you for the testcase.
The issue seems to be caused by this:

  • Some of packages used reference different versions of the same assembly (in your case that was System.ComponentModel.Annotations)
  • Reference rebinding configuration is saved into a configuration file
  • Unfortunately this configuration file is ignored by Delphi host when the plugin is loaded
  • Plugin fails to load referenced assemblies and fails

Workaround solution is to take the file TravelNote.Octopus.Hydra.dll.config (plugin .config file), rename it to OctopusClientTester.exe.config and to put this renamed file next to the OctopusClientTester.exe host exe.
This will allow Hydra to load assembly rebinding info and the plugin will be loaded successfully.

We will investigate if it is possible to use the original .config file when a Hydra plugin is loaded.

Sorry for the inconvenience

Thanks, logged as bugs://85336

Awesome support! I’ll try the workaround

bugs://85336 got closed with status fixed.

Also please send your account name to support@ so we’ll be able to provide you a fix download once it is available.

1 Like