autofac / Autofac.ServiceFabric

Autofac integration for Azure Service Fabric. Provides service factory implementations for Actors, Stateful Services and Stateless Services.
MIT License
26 stars 27 forks source link

Access denied in RegisterActor #34

Closed pvivera closed 5 years ago

pvivera commented 6 years ago

I've created a simple app, just the template generated by Visual Studio for .net core, to test this package integration. But I'm experimenting a problem with the following code:

private static void Main()
        {
            try
            {
                var builder = new ContainerBuilder();

                builder.RegisterServiceFabricSupport();
                builder.RegisterActor<TestingActorSystem>();

                using (builder.Build())
                {
                    Thread.Sleep(Timeout.Infinite);
                }
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }

The line builder.RegisterActor(); is throwing:

System.TypeLoadException: Access is denied: 'TestingActorSystem.TestingActorSystem'.
   at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type)
   at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
   at System.Reflection.Emit.TypeBuilder.CreateTypeInfo()
   at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.CreateType(TypeBuilder type)
   at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType()
   at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateType(String name, Type[] interfaces, INamingScope namingScope)
   at Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func`3 factory)
   at Autofac.Extras.DynamicProxy.RegistrationExtensions.EnableClassInterceptors[TLimit,TConcreteReflectionActivatorData,TRegistrationStyle](IRegistrationBuilder`3 registration, ProxyGenerationOptions options, Type[] additionalInterfaces)
   at Autofac.Integration.ServiceFabric.RegistrationExtensions.RegisterServiceWithInterception[TService,TInterceptor](ContainerBuilder builder)
   at Autofac.Integration.ServiceFabric.AutofacActorExtensions.RegisterActor[TActor](ContainerBuilder builder, Func`3 stateManagerFactory, IActorStateProvider stateProvider, ActorServiceSettings settings)
   at TestingActorSystem.Program.Main() in c:\dev\TestActorSystem\TestingActorSystem\Program.cs:line 24}    System.Exception {System.TypeLoadException

Any help?

wasabii commented 6 years ago

Actor has to be public.

pvivera commented 6 years ago

@wasabii Thanks, it worked. I was trying to keep all actors internal as it mentions in this post. https://alexmg.com/posts/introducing-the-autofac-integration-for-service-fabric

alexmg commented 6 years ago

@pvivera Does adding the following help for you?

[assembly: InternalsVisibleTo(InternalsVisible.ToDynamicProxyGenAssembly2)]

tillig commented 5 years ago

Closing due to lack of feedback. If this isn't resolved, we can re-open; or if there's more help needed I might recommend asking on StackOverflow.

ghost commented 5 years ago

Same issue; but with Stateless service