autofac / Autofac.Extras.DynamicProxy

Interceptor and decorator support for Autofac IoC via Castle DynamicProxy
MIT License
106 stars 33 forks source link

Dynamic Proxy integration 4.3.0 doesn't work with Castle.Core 4.2.1 #25

Closed MonkSoul closed 6 years ago

tillig commented 6 years ago

Can you provide a bit more info here? Is there an error message? Some reproduction you can show to illustrate the problem?

hikalkan commented 6 years ago

I'm getting this exception for registrationBuilder.EnableClassInterceptors() method.

Message: System.IO.FileNotFoundException : Could not load file or assembly 'Castle.Core, Version=4.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc'. The system cannot find the file specified.

image

I'm using Castle.Core v4.2.1 as shown in the image above.

tillig commented 6 years ago

You may need to add an assembly binding redirect to your app.config. NuGet sometimes misses that. https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions

hikalkan commented 6 years ago

I've already <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> in my csproj file.

hikalkan commented 6 years ago

Even adding this didn't help:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Getting the exception on runtime, it's not a build problem. So, it may not be related to nuget.

tillig commented 6 years ago

Binding redirects are a runtime thing (note the runtime element).

Is there a small repro project I can see?

tillig commented 6 years ago

Also, have you tried clearing cached items like the .vs folder? That can sometimes help.

hikalkan commented 6 years ago

Yes, I cleared it. I also published it and run under IIS to see the difference. Result is same.

Is there a small repro project I can see?

No, but nice idea, I can try with a simpler test project when I have time.

tillig commented 6 years ago

I was able to repro this in a small console app. Unclear why it's popping up yet or what to do about it, but at least I see it.

tillig commented 6 years ago

OK, it turns out this is a Castle.Core problem. TL;DR: They wanted to switch from changing their assembly version strategy so it's pinned at 4.0.0.0... but they did that after having released 4.1.0.0. As of Castle.Core 4.2.0, the Castle.Core package version changes but the assembly version doesn't. And they chose to go backwards to 4.0.0. assembly version instead of stopping at 4.1.0.0 and pinning there... or restarting at 5.0.0.0.

What a nightmare.

I guess the right way to handle this is to update to 4.2.1 here so the bound assembly version lines up...? This is going to be a nightmare of trickle down problems. Sigh. But I can't see any way around it. Really wish they hadn't done that without incrementing the major version.

hikalkan commented 6 years ago

OMG! Then upgrading dependency to 4.2.1 seems the best way.

tillig commented 6 years ago

I released v4.4.0 of Autofac.Extras.DynamicProxy that uses Castle.Core 4.2.1. I also added docs about this issue. That's the best I can do from this end.

For folks hitting this in the future, I recommend taking it up with the Castle.Core crew. This is out of the control of Autofac.

hikalkan commented 6 years ago

Thank you @tillig for fast reaction. I just tested and it worked :)

alexmg commented 6 years ago

Nice work @tillig. I've updated Autofac.ServiceFabric to this new release. 👍