Realm & AutoFac error "ProcessedByFody"

OK, I was getting an error on realm-tutorial-dotnet and then noticed a real simple example all in Xamarin with no backend and thought let’s see if the same error happens. The project works fine, but when I add AutoFac and set it up to do DI boom. This is what I use in a potential distributable app and think Real is the E-Ticket for the app. Anyway I am registering the entire assembly:

builder.RegisterAssemblyTypes(dataAccess)
                .AsImplementedInterfaces()
                .AsSelf();

This causes an error. I guess that means I need to independently register the Fody component? I see nothing about anyone having problems with this specific thing. Any ideas?

Autofac.Core.Activators.Reflection.NoConstructorsFoundException
  Message=No accessible constructors were found for the type 'QuickJournal_ProcessedByFody'.
  Source=Autofac
  StackTrace:
  at Autofac.Core.Activators.Reflection.DefaultConstructorFinder.GetDefaultPublicConstructors (System.Type type) [0x0002e] in /_/src/Autofac/Core/Activators/Reflection/DefaultConstructorFinder.cs:56 
  at Autofac.Core.Activators.Reflection.DefaultConstructorFinder.FindConstructors (System.Type targetType) [0x00000] in /_/src/Autofac/Core/Activators/Reflection/DefaultConstructorFinder.cs:47 
  at Autofac.Core.Activators.Reflection.ReflectionActivator.ConfigurePipeline (Autofac.Core.IComponentRegistryServices componentRegistryServices, Autofac.Core.Resolving.Pipeline.IResolvePipelineBuilder pipelineBuilder) [0x0001c] in /_/src/Autofac/Core/Activators/Reflection/ReflectionActivator.cs:86 
  at Autofac.Core.Registration.ComponentRegistration.BuildResolvePipeline (Autofac.Core.IComponentRegistryServices registryServices, Autofac.Core.Resolving.Pipeline.IResolvePipelineBuilder pipelineBuilder) [0x00047] in /_/src/Autofac/Core/Registration/ComponentRegistration.cs:278 
  at Autofac.Core.Registration.ComponentRegistration.BuildResolvePipeline (Autofac.Core.IComponentRegistryServices registryServices) [0x0002a] in /_/src/Autofac/Core/Registration/ComponentRegistration.cs:249 
  at Autofac.Core.Registration.ComponentRegistryBuilder.Build () [0x00024] in /_/src/Autofac/Core/Registration/ComponentRegistryBuilder.cs:92 
  at Autofac.ContainerBuilder.Build (Autofac.Builder.ContainerBuildOptions options) [0x00038] in /_/src/Autofac/ContainerBuilder.cs:166 
  at QuickJournal.App..ctor () [0x00036] in C:\Realm_Tests\QuickJournal\QuickJournal\QuickJournal\App.xaml.cs:28 
  at QuickJournal.Droid.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00019] in C:\Realm_Tests\QuickJournal\QuickJournal\QuickJournal.Android\MainActivity.cs:19 
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00010] in /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-30/mcw/Android.App.Activity.cs:2713 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.7(intptr,intptr,intptr)

Is there no one who has run into this? Is no one using AutoFac with Realm?

Hello @Michael_Gamble ,

Thank you for raising this query.

This does appear like an autofac issue at a first glance. It seems to register an attribute in the DI container for perhaps no reason.

Could you please share some code that can help us investigate more details?

I look forward to your response.

Cheers :performing_arts:

I had forgoten entirely about this post. Just recently I got back into using Realm/Atlas for my small Xamarin app. And thought I would share here the solution. Instead of using each container, class and registering it he uses GetExecutingAssembly, I got this from an Udemy class I took and thought it pretty slick but frankly didn’t really understand the process. For some reason a coup;e of Realm Classes kept throwing errors. Adding them to the builder seperately seemed to do the trick. Thought I’d share incase anyone else runs into this!

builder.RegisterAssemblyTypes(dataAccess)
                .Where(x => !x.Name.Contains("RealmModuleInitializer"))
                .Where(x => !x.Name.Contains("ProcessedByFody"))
                .AsImplementedInterfaces().AsSelf();
1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.