autofac / Autofac.Extensions.DependencyInjection

Autofac implementation of the interfaces in Microsoft.Extensions.DependencyInjection.Abstractions, the .NET Core dependency injection abstraction.
MIT License
196 stars 47 forks source link

FileLoadException: Strong name signature could not be verified. #81

Closed CNBoland closed 4 years ago

CNBoland commented 4 years ago

Describe the bug Upgraded MVC5 project from Autofac 5.2 to 6.0, including Autofac.Extensions.DependencyInjection from 6.0.0 to 7.0.1. Project builds, but on load results in the runtime exception described below.

To reproduce I'd have to build a sample site with relevant pieces and include as attachment. Hopefully the description here is sufficient enough to identify if problem is with the signed assembly or with my project somehow.

Full exception with stack trace:

[FileLoadException: Could not load file or assembly 'Autofac.Extensions.DependencyInjection' or one of its dependencies. Strong name signature could not be verified.  The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]

[FileLoadException: Could not load file or assembly 'Autofac.Extensions.DependencyInjection, Version=7.0.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. Strong name signature could not be verified.  The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +232
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +113
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +23
   System.Reflection.Assembly.Load(String assemblyString) +35
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +48

[ConfigurationErrorsException: Could not load file or assembly 'Autofac.Extensions.DependencyInjection, Version=7.0.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. Strong name signature could not be verified.  The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +767
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +256
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +58
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +287
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +69
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +137
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +172
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +854

[HttpException (0x80004005): Could not load file or assembly 'Autofac.Extensions.DependencyInjection, Version=7.0.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. Strong name signature could not be verified.  The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +532
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +111
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +724

Assembly/dependency versions:

<!-- <?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Antlr" version="3.5.0.2" targetFramework="net472" />
  <package id="Autofac" version="6.0.0" targetFramework="net472" />
  <package id="Autofac.Extensions.DependencyInjection" version="7.0.1" targetFramework="net472" />
  <package id="Autofac.Extras.NLog" version="3.0.0" targetFramework="net472" />
  <package id="Autofac.Mvc5" version="6.0.0" targetFramework="net472" />
  <package id="Autofac.Mvc5.Owin" version="6.0.0" targetFramework="net472" />
  <package id="Autofac.Owin" version="6.0.0" targetFramework="net472" />
  <package id="Autofac.WebApi2" version="6.0.0" targetFramework="net472" />
  <package id="Autofac.WebApi2.Owin" version="6.0.0" targetFramework="net472" />
  <package id="bootstrap" version="3.4.1" targetFramework="net472" />
  <package id="BouncyCastle" version="1.8.6.1" targetFramework="net472" />
  <package id="elmah" version="1.2.2" targetFramework="net472" />
  <package id="Elmah.Contrib.WebApi" version="1.0.10.25" targetFramework="net472" />
  <package id="elmah.corelibrary" version="1.2.2" targetFramework="net472" />
  <package id="EntityFramework" version="6.4.4" targetFramework="net472" />
  <package id="GeoAPI" version="1.7.5" targetFramework="net472" />
  <package id="GeoAPI.CoordinateSystems" version="1.7.5" targetFramework="net472" />
  <package id="GeoAPI.Core" version="1.7.5" targetFramework="net472" />
  <package id="jQuery" version="3.5.1" targetFramework="net472" />
  <package id="jQuery.Validation" version="1.19.2" targetFramework="net472" />
  <package id="MailKit" version="2.9.0" targetFramework="net472" />
  <package id="Microsoft.AspNet.Cors" version="5.2.7" targetFramework="net472" />
  <package id="Microsoft.AspNet.Identity.Core" version="2.2.3" targetFramework="net472" />
  <package id="Microsoft.AspNet.Identity.EntityFramework" version="2.2.3" targetFramework="net472" />
  <package id="Microsoft.AspNet.Identity.Owin" version="2.2.3" targetFramework="net472" />
  <package id="Microsoft.AspNet.Mvc" version="5.2.7" targetFramework="net472" />
  <package id="Microsoft.AspNet.Razor" version="3.2.7" targetFramework="net472" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net472" />
  <package id="Microsoft.AspNet.WebApi" version="5.2.7" targetFramework="net472" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.7" targetFramework="net472" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.7" targetFramework="net472" />
  <package id="Microsoft.AspNet.WebApi.Cors" version="5.2.7" targetFramework="net472" />
  <package id="Microsoft.AspNet.WebApi.Owin" version="5.2.7" targetFramework="net472" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.7" targetFramework="net472" />
  <package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net472" />
  <package id="Microsoft.Azure.NotificationHubs" version="4.1.0" targetFramework="net472" />
  <package id="Microsoft.Bcl.AsyncInterfaces" version="1.1.1" targetFramework="net472" />
  <package id="Microsoft.Extensions.Caching.Abstractions" version="3.1.8" targetFramework="net472" />
  <package id="Microsoft.Extensions.Caching.Memory" version="3.1.8" targetFramework="net472" />
  <package id="Microsoft.Extensions.Configuration" version="3.1.8" targetFramework="net472" />
  <package id="Microsoft.Extensions.Configuration.Abstractions" version="3.1.8" targetFramework="net472" />
  <package id="Microsoft.Extensions.Configuration.Binder" version="3.1.8" targetFramework="net472" />
  <package id="Microsoft.Extensions.DependencyInjection" version="3.1.8" targetFramework="net472" />
  <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="3.1.8" targetFramework="net472" />
  <package id="Microsoft.Extensions.Http" version="3.1.8" targetFramework="net472" />
  <package id="Microsoft.Extensions.Http.Polly" version="3.1.8" targetFramework="net472" />
  <package id="Microsoft.Extensions.Logging" version="3.1.8" targetFramework="net472" />
  <package id="Microsoft.Extensions.Logging.Abstractions" version="3.1.8" targetFramework="net472" />
  <package id="Microsoft.Extensions.Options" version="3.1.8" targetFramework="net472" />
  <package id="Microsoft.Extensions.Primitives" version="3.1.8" targetFramework="net472" />
  <package id="Microsoft.IdentityModel.Logging" version="6.7.1" targetFramework="net472" />
  <package id="Microsoft.IdentityModel.Tokens" version="6.7.1" targetFramework="net472" />
  <package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.11" targetFramework="net472" />
  <package id="Microsoft.Owin" version="4.1.1" targetFramework="net472" />
  <package id="Microsoft.Owin.Cors" version="4.1.1" targetFramework="net472" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="4.1.1" targetFramework="net472" />
  <package id="Microsoft.Owin.Security" version="4.1.1" targetFramework="net472" />
  <package id="Microsoft.Owin.Security.Cookies" version="4.1.1" targetFramework="net472" />
  <package id="Microsoft.Owin.Security.OAuth" version="4.1.1" targetFramework="net472" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net472" />
  <package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.3" targetFramework="net472" />
  <package id="MimeKit" version="2.9.2" targetFramework="net472" />
  <package id="Modernizr" version="2.8.3" targetFramework="net472" />
  <package id="NetTopologySuite" version="2.1.0" targetFramework="net472" />
  <package id="NetTopologySuite.CoordinateSystems" version="1.15.3" targetFramework="net472" />
  <package id="NetTopologySuite.Core" version="1.15.3" targetFramework="net472" />
  <package id="NetTopologySuite.Features" version="2.1.0" targetFramework="net472" />
  <package id="NetTopologySuite.IO.GeoJSON" version="2.0.3" targetFramework="net472" />
  <package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" />
  <package id="NLog" version="4.7.5" targetFramework="net472" />
  <package id="NLog.Elmah" version="4.0" targetFramework="net472" />
  <package id="NLog.MailKit" version="3.3.0" targetFramework="net472" />
  <package id="NLog.Web" version="4.9.3" targetFramework="net472" />
  <package id="Owin" version="1.0" targetFramework="net472" />
  <package id="Polly" version="7.2.1" targetFramework="net472" />
  <package id="Polly.Extensions.Http" version="3.0.0" targetFramework="net472" />
  <package id="Portable.BouncyCastle" version="1.8.8" targetFramework="net472" />
  <package id="Respond" version="1.4.2" targetFramework="net472" />
  <package id="Swashbuckle.Core.Net45" version="5.2.1" targetFramework="net472" />
  <package id="Swashbuckle.Net45" version="5.2.1" targetFramework="net472" />
  <package id="System.Buffers" version="4.5.1" targetFramework="net472" />
  <package id="System.ComponentModel.Annotations" version="4.7.0" targetFramework="net472" />
  <package id="System.Diagnostics.DiagnosticSource" version="4.7.1" targetFramework="net472" />
  <package id="System.IO" version="4.3.0" targetFramework="net472" />
  <package id="System.Memory" version="4.5.4" targetFramework="net472" />
  <package id="System.Net.Http" version="4.3.4" targetFramework="net472" />
  <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
  <package id="System.Runtime" version="4.3.1" targetFramework="net472" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.7.1" targetFramework="net472" />
  <package id="System.Security.Cryptography.Algorithms" version="4.3.1" targetFramework="net472" />
  <package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net472" />
  <package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net472" />
  <package id="System.Security.Cryptography.X509Certificates" version="4.3.2" targetFramework="net472" />
  <package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />
  <package id="WebActivatorEx" version="2.2.0" targetFramework="net472" />
  <package id="WebGrease" version="1.6.0" targetFramework="net472" />
</packages> -->

Additional context Project has been working with latest versions of the Autofac 5.x stack. Problem occurred after upgrading to 6.x.

alistairjevans commented 4 years ago

Thanks for raising the issue; it looks like when we changed the build to run on Linux, it accidentally turned on delay-signing.

Just to absolutely double and triple check, would you mind grabbing the latest CI build from MyGet, with the corrected signing option, 7.0.2-develop-00488, and see if that works with your project?

If it does, we'll get a 7.0.2 release out.

CNBoland commented 4 years ago

I updated to the MyGet preview and am now getting this error:

_[MissingMethodException: Method not found: 'Void Autofac.Core.IComponentRegistration.add_Preparing(System.EventHandler1<Autofac.Core.PreparingEventArgs>)'.] Autofac.Extras.NLog.NLogModule.AttachToComponentRegistration(IComponentRegistryBuilder componentRegistry, IComponentRegistration registration) +0 Autofac.Core.Registration.ComponentRegistryBuilder.add_Registered(EventHandler1 value) in /home/appveyor/projects/autofac/src/Autofac/Core/Registration/ComponentRegistryBuilder.cs:154 Autofac.Module.Configure(IComponentRegistryBuilder componentRegistry) in /home/appveyor/projects/autofac/src/Autofac/Module.cs:67 Autofac.ContainerBuilder.Build(IComponentRegistryBuilder componentRegistry, Boolean excludeDefaultModules) in /home/appveyor/projects/autofac/src/Autofac/ContainerBuilder.cs:219 Autofac.ContainerBuilder.Build(ContainerBuildOptions options) in /home/appveyor/projects/autofac/src/Autofac/ContainerBuilder.cs:161 APA.MAP.RegistrationServices.Sec.AutofacConfig.Configure(HttpConfiguration httpConfig) in C:\Projects\Repos\MAP\APA.MAP\APA.MAP.RegistrationServices.Sec\App_Start\AutofacConfig.cs:44 APA.MAP.RegistrationServices.Sec.WebApiApplication.ApplicationStart() in C:\Projects\Repos\MAP\APA.MAP\APA.MAP.RegistrationServices.Sec\Global.asax.cs:35

I'm using Autofac v6.0 from NuGet.

alistairjevans commented 4 years ago

It looks like the Autofac.Extras.NLog project is not compatible with Autofac v6; that package isn't one of ours, so will need updating.

Check out the breaking changes list for Autofac v6.

CNBoland commented 4 years ago

Yes, I see that now. I maintain Autofac.Extras.NLog and updated it recently for compatibility with Autofac 6.0, so I'll address it there and report back here. Thank you for looking into this.

alistairjevans commented 4 years ago

No worries; we'll get the proper release of 7.0.2 out soon.

tillig commented 4 years ago

I'm in the process of pushing 7.0.2 out now.