Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

3 Pages123>
Could not load file or assembly after 4.2.0.7 update
davetorutek
#1 Posted : Sunday, December 15, 2019 10:46:32 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/31/2018(UTC)
Posts: 7
Location: New Zealand

Thanks: 2 times
Was thanked: 2 time(s) in 2 post(s)
We have a .netcore 2.2 project that uses AspNetCore.TestHost.TestServer for tests.

As of the latest ncrunch update we get this error in all tests inside a call to a controller via the TestHost (or when registering signalr):
Quote:
System.BadImageFormatException: Could not load file or assembly 'System.IO.Pipelines, Version=4.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)
at Microsoft.AspNetCore.TestHost.ResponseStream..ctor(Func`1 onFirstWriteAsync, Action abortRequest)
at Microsoft.AspNetCore.TestHost.HttpContextBuilder..ctor(IHttpApplication`1 application)
at Microsoft.AspNetCore.TestHost.ClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)


We have another project on the same major version (maybe different minor version - am investigating) that works fine under the latest ncrunch.
If I make a new simple project it also works.
Any ideas on what to try? Will spend some time trying to make a project that can reproduce the error.
Thanks.
davetorutek
#2 Posted : Sunday, December 15, 2019 11:13:27 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/31/2018(UTC)
Posts: 7
Location: New Zealand

Thanks: 2 times
Was thanked: 2 time(s) in 2 post(s)
Managed to reproduce the error (although maybe not the exact same conditions) in a test project

https://github.com/danzel/ncrunchtest20191216
This should make the error as above when trying to run the test.

If you remove this line:
https://github.com/danze...HackApi.Tests.csproj#L8
And restart ncrunch, then it works.
Remco
#3 Posted : Monday, December 16, 2019 3:21:33 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,940

Thanks: 777 times
Was thanked: 997 time(s) in 950 post(s)
Hi, thanks for sharing this with the use case to reproduce it! We're taking a look at this and will get back to you soon.
1 user thanked Remco for this useful post.
davetorutek on 12/16/2019(UTC)
tkarlsen
#4 Posted : Tuesday, December 17, 2019 3:49:33 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/30/2017(UTC)
Posts: 16
Location: United States of America

Was thanked: 4 time(s) in 4 post(s)
We are having similar issues with the latest release. In our case we're on .NET Core 3.1, and we are getting System.IO.FileNotFoundException. Nothing has changed in our project since installing the new version, and it worked fine in the previous version.
Remco
#5 Posted : Wednesday, December 18, 2019 6:09:30 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,940

Thanks: 777 times
Was thanked: 997 time(s) in 950 post(s)
tkarlsen;14231 wrote:
We are having similar issues with the latest release. In our case we're on .NET Core 3.1, and we are getting System.IO.FileNotFoundException. Nothing has changed in our project since installing the new version, and it worked fine in the previous version.


Thanks for confirming this. We've reproduced the problem and are trying to make sense of it. We'll have a fix available for this as soon as we can.
Remco
#6 Posted : Thursday, December 19, 2019 4:58:59 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,940

Thanks: 777 times
Was thanked: 997 time(s) in 950 post(s)
An update on this problem...

It's pretty big. This issue is downstream from some major package reference restructuring performed by MS with the release of .NET Core 3.0 and VS 16.4.

We don't yet know how we're going to solve this, but it's safe to say that we won't have a solution within the next few days. If you're being hit with this problem, all I can recommend at the moment is rolling back your toolset to a working version or experimenting with different project referencing structures (i.e. perhaps direct references to the packages involved) to see if you can suppress the problem. The core issue involves changes that have been introduced in the .NET Core build system around the VS 16.4 releases. It doesn't matter which version of .NET Core you're targeting. VS 16.3 should hopefully be OK (make sure to clear out your 'obj' directories if you roll back to it).
tkarlsen
#7 Posted : Thursday, December 19, 2019 4:25:55 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/30/2017(UTC)
Posts: 16
Location: United States of America

Was thanked: 4 time(s) in 4 post(s)
Remco;14241 wrote:
An update on this problem...

It's pretty big. This issue is downstream from some major package reference restructuring performed by MS with the release of .NET Core 3.0 and VS 16.4.

We don't yet know how we're going to solve this, but it's safe to say that we won't have a solution within the next few days. If you're being hit with this problem, all I can recommend at the moment is rolling back your toolset to a working version or experimenting with different project referencing structures (i.e. perhaps direct references to the packages involved) to see if you can suppress the problem. The core issue involves changes that have been introduced in the .NET Core build system around the VS 16.4 releases. It doesn't matter which version of .NET Core you're targeting. VS 16.3 should hopefully be OK (make sure to clear out your 'obj' directories if you roll back to it).


For what it's worth, my issues were resolved by going back to the NCrunch 4.1.0.1. Everything else is on the latest version. Visual Studio 16.4.2, .NET Core 3.1, etc. At least for my issue, it was some change in NCrunch that caused things to stop working.
1 user thanked tkarlsen for this useful post.
Remco on 12/19/2019(UTC)
michaelkroes
#8 Posted : Friday, December 20, 2019 8:37:39 PM(UTC)
Rank: NCrunch Developer

Groups: Registered
Joined: 9/22/2017(UTC)
Posts: 208
Location: Netherlands

Thanks: 94 times
Was thanked: 43 time(s) in 41 post(s)
tkarlsen
#9 Posted : Friday, December 20, 2019 11:09:42 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/30/2017(UTC)
Posts: 16
Location: United States of America

Was thanked: 4 time(s) in 4 post(s)


Unfortunately, it's not working for me. I'm still getting a lot of "System.IO.FileNotFoundException: Could not load file or assembly" errors for various assemblies. Maybe it's a different issue? Either way, reverting to 4.1.0.1 solves it.
michaelkroes
#10 Posted : Saturday, December 21, 2019 5:54:11 AM(UTC)
Rank: NCrunch Developer

Groups: Registered
Joined: 9/22/2017(UTC)
Posts: 208
Location: Netherlands

Thanks: 94 times
Was thanked: 43 time(s) in 41 post(s)
Thanks for the quick feedback!

The sample project in this thread does pass with this build, so most likely you have a slightly different setup. My guess it’s still the same problem, I just haven’t fixed it properly.

Is there any chance you could create a sample project for us that fails with the build above? This seems to be really depend on which nuget packages are included and how they are treated as a dependency. The late binding with TestHost also plays a role, so the code needs to be used for it to trigger the run time failure.

If you want the code can be privately submitted via the contact form.

Just for some background: Version 4.1 had some fixes in the same area to fix similar issues. We can’t simply reverse the change, because that breaks other use cases.
michaelkroes
#11 Posted : Monday, December 23, 2019 4:00:41 AM(UTC)
Rank: NCrunch Developer

Groups: Registered
Joined: 9/22/2017(UTC)
Posts: 208
Location: Netherlands

Thanks: 94 times
Was thanked: 43 time(s) in 41 post(s)
tkarlsen
#12 Posted : Monday, December 23, 2019 4:51:18 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/30/2017(UTC)
Posts: 16
Location: United States of America

Was thanked: 4 time(s) in 4 post(s)
michaelkroes;14269 wrote:
We have another build out that fixes a similar error message but has a different cause. This is for netcore WPF projects.

Could you please give that a build a try? If that doesn't work we are going to need that sample project to progress further.


That build doesn't seem to work for me either. Looking at the errors more closely, it seems like it might be tricky to get a sample project together. I suspect it may be related to dynamic loading of assemblies. Most of my tests run fine, but I have an integration test project that uses the database, and Microsoft.Data.SqlClient is throwing the following:

Quote:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.


I also have a (commercial) third party library that uses some WPF stuff, and it throws the following exception:

Quote:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Drawing.Common, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.


I'm pretty sure this library only loads System.Drawing.Common dynamically if it needs it, because it can run without it, but with limited functionality.

It's kind of hard to reproduce these two in a test project since one dependency is the database, and the other dependency is a commercial library. Does that point you in the right direction, though?
michaelkroes
#13 Posted : Monday, December 23, 2019 5:14:15 PM(UTC)
Rank: NCrunch Developer

Groups: Registered
Joined: 9/22/2017(UTC)
Posts: 208
Location: Netherlands

Thanks: 94 times
Was thanked: 43 time(s) in 41 post(s)
Thanks for the clarification. Can you confirm the project type(s) you are using? Ie. Is this an aspnetcore or wpf project? Or both?
tkarlsen
#14 Posted : Monday, December 23, 2019 5:23:11 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/30/2017(UTC)
Posts: 16
Location: United States of America

Was thanked: 4 time(s) in 4 post(s)
michaelkroes;14271 wrote:
Thanks for the clarification. Can you confirm the project type(s) you are using? Ie. Is this an aspnetcore or wpf project? Or both?


The test projects themselves are netcoreapp3.1, but they also include "<FrameworkReference Include="Microsoft.WindowsDesktop.App" />" because of the System.Drawing dependency.
michaelkroes
#15 Posted : Monday, December 23, 2019 5:29:09 PM(UTC)
Rank: NCrunch Developer

Groups: Registered
Joined: 9/22/2017(UTC)
Posts: 208
Location: Netherlands

Thanks: 94 times
Was thanked: 43 time(s) in 41 post(s)
Thanks, that might be the core issue. Couple more questions:

Is the framework reference directly in the project file? Or is it implicitly added by the package?

Do they perhaps also reference an aspnetcore project?
tkarlsen
#16 Posted : Monday, December 23, 2019 5:45:18 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/30/2017(UTC)
Posts: 16
Location: United States of America

Was thanked: 4 time(s) in 4 post(s)
michaelkroes;14273 wrote:
Thanks, that might be the core issue. Couple more questions:

Is the framework reference directly in the project file? Or is it implicitly added by the package?

Do they perhaps also reference an aspnetcore project?


The framework reference is directly in the test project file.

The integration test project (with the SqlClient throwing exceptions) has the framework reference, and also a reference to an ASP.NET Core 3.1 project. (Microsoft.NET.Sdk.Web SDK, and netcoreapp3.1 target framework.)

The regular test project (with the System.Drawing exception) also has the framework reference, but references a regular netcoreapp3.1 library.
michaelkroes
#17 Posted : Monday, December 23, 2019 6:11:18 PM(UTC)
Rank: NCrunch Developer

Groups: Registered
Joined: 9/22/2017(UTC)
Posts: 208
Location: Netherlands

Thanks: 94 times
Was thanked: 43 time(s) in 41 post(s)
tkarlsen;14274 wrote:


The integration test project (with the SqlClient throwing exceptions) has the framework reference...


Which framework reference would that be? Also Microsoft.WindowsDesktop.App?

When I add the framework references to a class library project I get an error, but a different one.

Could not load file or assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

That's because of the runtimeconfig.json. That's something that I can fix. But before that, would you mind selecting a failing test, right click, Advanced, Browse to selected workspace. Then open the windows explorer that was opened. From there navigate to bin\Debug\netcoreapp3.1\nCrunch.TaskRunner.DotNetCore.20.x64.runtimeconfig.json. Edit that file and replace the contents with:

Code:

{
  "runtimeOptions": {
    "tfm": "netcoreapp3.1",
    "framework": {
      "name": "Microsoft.WindowsDesktop.App",
      "version": "3.1.0"
    }
  }
}


Then without changing anything run the test again by right clicking the test and selecting run. I'm curious if that will make the test pass. If not we have another issue on our hands.
michaelkroes
#18 Posted : Monday, December 23, 2019 7:35:24 PM(UTC)
Rank: NCrunch Developer

Groups: Registered
Joined: 9/22/2017(UTC)
Posts: 208
Location: Netherlands

Thanks: 94 times
Was thanked: 43 time(s) in 41 post(s)
I'm building a version that includes a fix for explicit framework references. Netcore 3 introduced transitive references, we added some fixes for this. We didn't have a testcase yet for explicitly added WPF framework references.

It also contains a speculative fix for the other possible assembly resolution issues. I'll post the version here once it's done building.
michaelkroes
#19 Posted : Monday, December 23, 2019 8:29:12 PM(UTC)
Rank: NCrunch Developer

Groups: Registered
Joined: 9/22/2017(UTC)
Posts: 208
Location: Netherlands

Thanks: 94 times
Was thanked: 43 time(s) in 41 post(s)
tkarlsen
#20 Posted : Monday, December 23, 2019 9:26:19 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/30/2017(UTC)
Posts: 16
Location: United States of America

Was thanked: 4 time(s) in 4 post(s)
michaelkroes;14277 wrote:
Here's the new version:


Well some good news! The non-integration test project now works fine. That's the one that is referencing a standard netcoreapp3.1 library and was throwing the System.Drawing exceptions.

However, the integration test library that targets the ASP.NET Core 3.1 app fails with a ton of errors like this one:

Quote:

An error occurred while analysing this project after it was built: System.Exception: Error while discovering test Web.IntegrationTests.Features.Users.Services.UserServiceTests.GetCurrentUserAccessibleUserIdsAsync_Admin_ShouldReturnNull':System.Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.Identity.Stores, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.Extensions.Identity.Stores, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'

System.BadImageFormatException: Could not load file or assembly 'Microsoft.Extensions.Identity.Stores, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)
File name: 'Microsoft.Extensions.Identity.Stores, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' ---> System.BadImageFormatException: Cannot load a reference assembly for execution.


There are a bunch more of errors just like these.
1 user thanked tkarlsen for this useful post.
michaelkroes on 12/24/2019(UTC)
Users browsing this topic
Guest
3 Pages123>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.141 seconds.