volosoft / castle-windsor-ms-adapter

Castle Windsor ASP.NET Core / Microsoft.Extensions.DependencyInjection Adapter
https://www.nuget.org/packages/Castle.Windsor.MsDependencyInjection
MIT License
85 stars 29 forks source link

Bump Castle.Windor to 3.4.0 #4

Closed gabrielrobert closed 7 years ago

gabrielrobert commented 7 years ago

Hey,

I'm trying to call this piece a code for tests purposes:

 var serviceProvider = WindsorRegistrationHelper.CreateServiceProvider(
                IocManager.IocContainer,
                services
);

However, my project is using Aspnetboilerplate and it references Castle.Windor version 3.3.4. When I try to start tests (after fresh update, throught csproj-based project in VS17), I have this problem:

Message: System.IO.FileLoadException : Could not load file or assembly 'Castle.Windsor, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Exactly on the first piece of code I provided.

It happens in this context:

private void SetupInMemoryDb()
        {
            var services = new ServiceCollection()
                .AddEntityFrameworkInMemoryDatabase();

            var serviceProvider = WindsorRegistrationHelper.CreateServiceProvider(
                IocManager.IocContainer,
                services
            );

            var builder = new DbContextOptionsBuilder<TestProjectDbContext>();
            builder.UseInMemoryDatabase().UseInternalServiceProvider(serviceProvider);

            IocManager.IocContainer.Register(
                Component
                    .For<DbContextOptions<TestProjectDbContext>>()
                    .Instance(builder.Options)
                    .LifestyleSingleton()
            );
        }
hikalkan commented 7 years ago

That seems a common .net library version mismatch problem. Have you tried to add an assembly redirect to your config file?

gabrielrobert commented 7 years ago
<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Castle.Windsor" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
        <bindingRedirect oldVersion="0.0.0.0-3.3.0.0" newVersion="3.4.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

This redirect do not seems to work. It's in my app.config file at the root of the test project. I tried this solution before asking, maybe something i'm missing?

hikalkan commented 7 years ago

I could not understand why it happens (since we have no problem), but it would be better to release a new version depends on 3.4.