The invoked member is not supported in a dynamic assembly

Tags: #<Tag:0x00007f06691130c0> #<Tag:0x00007f0669112fd0> #<Tag:0x00007f0669112f08>

I have configured my MVC application as follows:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.UseHangfire(config =>
        {
            config.UseSqlServerStorage("myconnstring");
            config.UseServer();
        });
    }
}

But I’m getting the following error every time I run my app:

[NotSupportedException: The invoked member is not supported in a dynamic assembly.]    
System.Reflection.Emit.InternalAssemblyBuilder.get_Location() +56       
log4net.Util.SystemInfo.AssemblyLocationInfo(Assembly myAssembly) +88   
log4net.Core.DefaultRepositorySelector.GetInfoForAssembly(Assembly assembly, String& repositoryName, Type& repositoryType) +256    
log4net.Core.DefaultRepositorySelector.CreateRepository(Assembly repositoryAssembly, Type repositoryType, String repositoryName, Boolean readAssemblyAttributes) +270    
log4net.Core.DefaultRepositorySelector.CreateRepository(Assembly repositoryAssembly, Type repositoryType) +58
log4net.Core.DefaultRepositorySelector.GetRepository(Assembly repositoryAssembly) +115    
log4net.Core.LoggerManager.GetLogger(Assembly repositoryAssembly, String name) +180    
log4net.LogManager.GetLogger(Assembly repositoryAssembly, String name) +50    
log4net.LogManager.GetLogger(String name) +55
lambda_method(Closure , String ) +39    
Hangfire.Logging.LogProviders.Log4NetLogProvider.GetLogger(String name) +50    
Hangfire.Logging.LogProvider.GetLogger(String name) +103  
Hangfire.Logging.LogProvider.GetLogger(Type type) +53    
Hangfire.SqlServer.SqlServerObjectsInstaller..cctor() +65

Anyone can help here?

Hello, what version of log4net are you using? After your answer, I’ll create a bug report at
https://github.com/damianh/LibLog.

As a workaround, you can set logging provider manually:

using Hangfire.Logging;
using Hangfire.Logging.Providers;

LogProvider.SetCurrentLogProvider(new ColouredConsoleLogProvider());

I’m using log4net 1.2.9.0

I’ve found version 1.2.9.0 in the Archives section of the downloads page, and also I’ve found the following text:

The 1.2.10 and 1.2.9 releases have been created while log4net was still undergoing incubation

Seems like this version is outdated as there is no corresponding NuGet package. When I installed it, I received the same exception you described above.

Then I tried to install Log4Net 1.2.10 and 2.0.3 from NuGet gallery and all was fine. So, you have the following ways:

  • Upgrade your log4net assembly to a newer one.
  • Write custom Log4Net129 adapter as written here and use plain old method calls instead of reflection.