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

The type initializer for 'Moq.Async.AwaitableFactory' threw an exception: Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.1 #1179

Closed
dariusz-wozniak opened this issue Jun 30, 2021 · 6 comments

Comments

@dariusz-wozniak
Copy link

Hi,

Recently, I started having errors when running tests on the Azure DevOps. The error I'm receiving is written below. Please note that me and none of my colleagues don't receive these errors locally.

Error:

System.IO.FileLoadException : Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Stack:

2021-06-30T06:56:05.5745936Z --FileLoadException
2021-06-30T06:56:05.5746420Z at Moq.Async.AwaitableFactory..cctor()
2021-06-30T06:56:05.5746913Z Failed ShouldLeaveOnlySingleLineItemCommand [2 ms]
2021-06-30T06:56:05.5747373Z Error Message:
2021-06-30T06:56:05.5748539Z System.TypeInitializationException : The type initializer for 'Moq.Async.AwaitableFactory' threw an exception.
2021-06-30T06:56:05.5749806Z ----> System.IO.FileLoadException : Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
2021-06-30T06:56:05.5750965Z Stack Trace:
2021-06-30T06:56:05.5777963Z at Moq.Async.AwaitableFactory.TryGet(Type type)
2021-06-30T06:56:05.5779246Z at Moq.ExpressionExtensions.g__IsResult|5_1(MemberInfo member, IAwaitableFactory& awaitableFactory) in C:\projects\moq4\src\Moq\ExpressionExtensions.cs:line 345
2021-06-30T06:56:05.5783024Z at Moq.ExpressionExtensions.g__Split|5_0(Expression e, Expression& r, InvocationShape& p, Boolean assignment, Boolean allowNonOverridableLastProperty) in C:\projects\moq4\src\Moq\ExpressionExtensions.cs:line 299
2021-06-30T06:56:05.5784569Z at Moq.ExpressionExtensions.Split(LambdaExpression expression, Boolean allowNonOverridableLastProperty) in C:\projects\moq4\src\Moq\ExpressionExtensions.cs:line 149
2021-06-30T06:56:05.5785728Z at Moq.Mock.SetupRecursive[TSetup](Mock mock, LambdaExpression expression, Func4 setupLast, Boolean allowNonOverridableLastProperty) in C:\projects\moq4\src\Moq\Mock.cs:line 601 2021-06-30T06:56:05.5787008Z at Moq.Mock.Setup(Mock mock, LambdaExpression expression, Condition condition) in C:\projects\moq4\src\Moq\Mock.cs:line 505 2021-06-30T06:56:05.5787879Z at Moq.Mock1.Setup[TResult](Expression1 expression) in C:\projects\moq4\src\Moq\Mock1.cs:line 454

A few tech details:

  • Project target: NET Framework 4.7.2
  • Moq: 4.16.1
  • Azure Devops Task - Visual Studio Test: 2.170.1
  • Microsoft Test Execution Command Line Tool: 16.10.0
  • NUnit: 3.13.2
  • NUnit Adapter: 4.0.0.0

packages.config entry:

<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />

Binding redirect in app.config:

<dependentAssembly>
	<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
	<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>

.csproj entry:

<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
  <HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>

I had several trials, but none of these helped solving the issue.

I've found Moq 4.16.x for .NET Framework 4.5 uses reference to the System.Threading.Tasks.Extensions 4.2.0.1, not 4.5.4. Could it be an issue in my case?

image

Thanks

@stakx
Copy link
Contributor

stakx commented Jun 30, 2021

There have been many similar issues re: assembly versioning / binding redirects, they usually turn out to be a project configuration problem unrelated to Moq. I suggest you do a search for some possible solutions. I'm going to close this as off-topic; other than staying up-to-date with NuGet dependencies, there's not much we can do.

@stakx stakx closed this as completed Jun 30, 2021
@dariusz-wozniak
Copy link
Author

@stakx: I reviewed GitHub issues and StackOverflow threads for the Moq and other projects, but haven't found working solution.

One thing that is exceptional in case of that exception is that error is happening on the Azure DevOps context, not the local environment one.

@dariusz-wozniak
Copy link
Author

As per above, can you please re-open the issue, @stakx?

@stakx
Copy link
Contributor

stakx commented Jun 30, 2021

No, this is more of an issue with NuGet's ridiculous versioning problems, it's not an issue caused by Moq. The only thing we can do is updating the versions of Moq's dependencies (such as the one on System.Threading.Tasks.Extensions), but even if we don't, you should still be able to resolve the issue by configuring your project differently. (For example, depending on the targeted frameworks, you can often force a specific version of a NuGet package by referencing it in your main project. There's also a few different ways to configure binding redirects for the .NET Framework.) But this isn't the right place to help you do that – this is the issue tracker for Moq. Finally, if the problem only surfaces with Azure DevOps, perhaps it would be better to ask in a place related to that?

@dariusz-wozniak
Copy link
Author

Sure thing, thank you for the info @stakx!

I will continue trying to resolve that.

@denjmpr
Copy link

denjmpr commented Nov 23, 2021

Hi,
This is also reproducible with TeamCity Enterprise 2021.1.1.
I also tried some different approaches found on the web - nothing helped me.
Thanks.

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