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

After v4.8.0 upgrade and tests failing with missing netstandard, version=2.0.0.0 #567

Closed
salixzs opened this issue Jan 5, 2018 · 16 comments

Comments

@salixzs
Copy link

salixzs commented Jan 5, 2018

After upgrading to Moq 4.8 on build server (where we do not have anything netstandard 2.0) started to fail with this:

Information: [xUnit.net 00:00:10.0169373]       System.TypeInitializationException : The type initializer for 'Moq.DefaultValueProvider' threw an exception.
Information: [xUnit.net 00:00:10.0170013]       ---- System.IO.FileNotFoundException : Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
Information: [xUnit.net 00:00:10.0174190]       Stack Trace:
Information: [xUnit.net 00:00:10.0175399]         C:\projects\moq4\Source\DefaultValueProvider.cs(59,0): at Moq.DefaultValueProvider.get_Empty()
Information: [xUnit.net 00:00:10.0176097]         C:\projects\moq4\Source\Mock.Generic.cs(144,0): at Moq.Mock`1..ctor(MockBehavior behavior, Object[] args)
Information: [xUnit.net 00:00:10.0176671]         C:\projects\moq4\Source\Mock.Generic.cs(128,0): at Moq.Mock`1..ctor(MockBehavior behavior)
Information: [xUnit.net 00:00:10.0177262]         C:\projects\moq4\Source\Mock.Generic.cs(112,0): at Moq.Mock`1..ctor()

Could this be related to recently added
<dependency id="System.Threading.Tasks.Extensions" version="4.4.0" />

packages.config:

  <package id="Castle.Core" version="4.2.1" targetFramework="net462" />
  <package id="Moq" version="4.8.0" targetFramework="net462" />
  <package id="System.Threading.Tasks.Extensions" version="4.4.0" targetFramework="net462" />
  <package id="xunit.abstractions" version="2.0.1" targetFramework="net462" />
  <package id="xunit.core" version="2.3.1" targetFramework="net462" />
  <package id="xunit.extensibility.core" version="2.3.1" targetFramework="net462" />
  <package id="xunit.extensibility.execution" version="2.3.1" targetFramework="net462" />
  <package id="xunit.runner.visualstudio" version="2.3.1" targetFramework="net462" developmentDependency="true" />

Solution targets Full .Net Framework 4.6.2

@salixzs salixzs changed the title After v4.8.0 upgrade and tests failing with missing missing netstandard, version=2.0.0.0 After v4.8.0 upgrade and tests failing with missing netstandard, version=2.0.0.0 Jan 5, 2018
@stakx
Copy link
Contributor

stakx commented Jan 5, 2018

@salixzs: Thanks for reporting. I am almost certain this is a duplicate of #566. (It's not an actual problem with Moq, but with .NET tooling: see dotnet/standard#481.)

See solution posted in #566 (comment) and a more detailed explanation in #566 (comment).

If this doesn't help then I'm afraid that according to #566 (comment), you might have to install .NET 4.7.1 or .NET Core support on the build server, or downgrade Moq to 4.7.145.

Could you please briefly report whether the fix works for you?

@salixzs
Copy link
Author

salixzs commented Jan 8, 2018

Solution did not worked for me, but I understood and got your point. Tried to traverse dependency tree to pinpoint exact problem, but either I am too stupid or I don't dig in right direction.
Next step I will try to convert solution to new project file structure (maybe even targetting netstandard).
I will close this and will try to remember to add solution which will help me to succeed.
Many thanks for your Moq and Your support. Was using it for years and plan to continue in any next projects.

@salixzs salixzs closed this as completed Jan 8, 2018
@stakx
Copy link
Contributor

stakx commented Jan 8, 2018

@salixzs - Thanks for your understanding.

I would definitely recommend the new "SDK-style" project file format, using <PackageReference> instead of packages.config, and a recent version of Visual Studio 2017. That alone is what probably helps best with a lot of current NuGet-related problems. On top of that, upgrading to .NET 4.7.1 might help because .NET 4.7.1 already "includes" support for .NET Standard.

I'm really sorry that you and others have to go through this kind of problem, I wish I could help more. But I also feel that this can probably only be fixed by Microsoft.

@stakx
Copy link
Contributor

stakx commented Jan 8, 2018

@salixzs - just published an updated Moq 4.8.1 on NuGet, based on the idea in #566 (comment).

Could you please check whether this resolves the issue you're having?

@salixzs
Copy link
Author

salixzs commented Jan 9, 2018

This time it worked. All tests pass without missing file exception.
Thank You very much.

@clottman
Copy link

clottman commented Jan 10, 2018

I'm having a similar issue on Moq 4.8.1, explicitly that System.Threading.Tasks.Extensions cannot be found. It was working before we updated from a lower version (pre 4.8.0).

System.TypeInitializationException: The type initializer for 'Moq.DefaultValueProvider' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.1.0.0, 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).

Downgrading back to 4.7.145 resolves the issue for me.

@stakx
Copy link
Contributor

stakx commented Jan 10, 2018

@clottman - the same has been reported in #566 (comment) except for the assembly minor version. Can you perhaps post test code that repeoduces this over in #566 - thank you!

@gerektoolhy
Copy link

Had same issue as @clottman with Moq 4.8.2. Downgrading to 4.7.145 fixed that.

@VinS101
Copy link

VinS101 commented Apr 17, 2018

I also downgraded to 4.7.145 after trying so many things. With Moq 4.8.2, I was able to fix it locally, but the tests kept failing on our TeamCity server.

@Mies75
Copy link

Mies75 commented Sep 3, 2018

The problem reported by @clottman still has not been fixed in Moq 4.9.0. Binding redirects have not solved the problem.

@Mies75
Copy link

Mies75 commented Sep 3, 2018

Instead of downgrading Moq, I have chosen to downgrade System.Threading.Tasks.Extensions to 4.3 (4.1.0.0).

@markjsc
Copy link

markjsc commented Sep 6, 2018

@Mies75 - Downgrading System.Threading.Tasks.Extensions to 4.3 worked for me also. Thanks for the suggestion!

@godrose
Copy link

godrose commented Oct 30, 2018

What if I have another package that specifies a version of System.Threading.Tasks.Extensions>4.3.0?
Is there any magic redirect or Moq fix that will sort this out?

@voroninp
Copy link

I've experimented a bit.

If package System.Threading.Tasks.Extensions is explicitly added to the project, Moq fails on loading System.ValueType.

It looks like there are really some problems with transitive dependencies resolution. =(

I had similar issue when tried to test a project targeted for NetStadnard2.0.
My MsTest project had old format and targeted .net 4.7.2
Types from tested project could not be initialized because referenced packages were not copied.
As soon as I changed project format to a new one, it started to work.

@Gonnagle
Copy link

Gonnagle commented Nov 22, 2018

Struggled to the same issue with project targeting net461, but using the new csproj format. Apparently was able to resolve it by adding Binding Redirects for System.Threading.Tasks.Extensions.

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

Actually used Paket to generate the BRs...

@Serg046
Copy link

Serg046 commented May 28, 2019

The same issue with Moq.4.11.0, TC server and console runner. I fixed it by downgrading but I'll try to upgrade a proj file later too

stevenengland added a commit to stevenengland/DeepLinkR that referenced this issue Jul 28, 2019
@devlooped devlooped locked and limited conversation to collaborators Sep 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests