Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I just upgraded to Castle Core v4.2.0 whilst using Moq v4.7.127 and I am getting an assembly binding error #461

Closed
ghost opened this issue Sep 29, 2017 · 9 comments

Comments

@ghost
Copy link

ghost commented Sep 29, 2017

I just upgraded Castle.Core from v4.1.1 to v4.2.0 whilst using Moq and got an assembly binding error. Why is this happening?

@ghost
Copy link
Author

ghost commented Sep 29, 2017

This is because Castle Core changed the AssemblyVersion attribute to only include major version numbers only so that we can avoid assembly binding errors with future releases/upgrades of Castle Core.

Why is the assembly binding error happening then?

This is because Moq have to release a version compiled against the new AssemblyVersion strategy, they are on it! :)

What do I do in the meantime? I want Castle Core bug fixes.

You can apply this following assembly binding redirect in your App.config.

 <dependentAssembly>
    <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-999.999.999.999" newVersion="4.0.0.0" />
  </dependentAssembly>

Are you using Castle Core features directly?

If not and you are using the latest version of Visual Studio (15.3.5) then you should probably remove the NuGet reference altogether along with it's assembly bindings. This means Castle Core becomes a transitive dependency which you should not have to worry about.

Are you guys versioning properly at all?

Yes we are, we just use the AssemblyFileVersion instead.

image

I am still having issues.

Please post to this issue and we will try to help you.

@ghost ghost changed the title I just upgraded to Castle Core v4.2.0 whilst using Moq v4.7.127 and I am getting an assmbly binding error I just upgraded to Castle Core v4.2.0 whilst using Moq v4.7.127 and I am getting an assembly binding error Sep 29, 2017
@ghost
Copy link
Author

ghost commented Sep 29, 2017

castleproject/Core#307

@stakx
Copy link
Contributor

stakx commented Sep 30, 2017

An updated Moq version built against Castle Core 4.2.0 has been ready since Saturday, unfortunately we're blocked from pushing it to NuGet by appveyor/ci#1825. Will report here again once we've successfully published the update.

@baynezy
Copy link

baynezy commented Oct 3, 2017

@stakx - you know there is a workaround outlined on there support forum. So that you can publish while they fix it.

@stakx
Copy link
Contributor

stakx commented Oct 3, 2017

Moq 4.7.137 has just been published on NuGet. It references Castle Core 4.2.0, so once you upgrade, any version conflicts should resolve itself.

If anyone still has trouble, please let us know here.

@stakx stakx closed this as completed Oct 6, 2017
@stakx
Copy link
Contributor

stakx commented Oct 6, 2017

(I realise it's a little soon to close this notification, but given that the most likely way to cause this problem is to just press something like a "update everything to the latest version" button, this should really be solved now. Thanks again for posting this!)

@ghost
Copy link
Author

ghost commented Oct 6, 2017

No problem! :)

@salixzs
Copy link

salixzs commented Aug 8, 2019

Starting 4.8 Moq just doesn't work on any of build servers with this

Initialization method {Here is a test class] threw exception. System.TypeInitializationException: The type initializer for 'Moq.Mock`1' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Moq.ProxyFactory' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Moq.CastleProxyFactory' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'Castle.Core, Version=4.2.1.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) ---> System.IO.FileLoadException: Could not load file or assembly 'Castle.Core, Version=4.0.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).

I understand that reasons are somewhere there - NuGets, Versions, BindingRedirects, Microsoft way of versioning etc. etc. ... but the fact is - this happens each time I touch Moq.
Currently adding Moq (4.12) to project (we still need full 4.7.2 Framework here) it also adds Castle.Core, System.Runtime.CompilerServices.Unsafe and System.Threading.Tasks.Extensions NuGet packages. I am just tired with this. Changing to alternative mocking library was faster than trying to find and make Moq work again.
Sorry, Moq is great library, but it is just not working anymore.

@stakx
Copy link
Contributor

stakx commented Aug 8, 2019

@salixzs: You appear to be using an older version of Moq. Why not try with the latest one? We've since shed quite a few package dependencies, and both Moq and Castle.Core have migrated to a different assembly versioning approach which should greatly help in avoiding assembly binding errors.

Yes, I'm tired of this, too. I've found however that using the latest tooling and using SDK-style project file format helps a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants