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

Could not load file or assembly 'System.Runtime.Caching' Net Core 2.0 #5

Closed
adragoset opened this issue Nov 2, 2017 · 10 comments
Closed

Comments

@adragoset
Copy link

adragoset commented Nov 2, 2017

I get the following exception when calling
await authenticator.Authenticate(token);
in a netcoreapp2.0 webapi application.

---- System.IO.FileNotFoundException : Could not load file or assembly 'System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Im using nuget package <PackageReference Include="Kerberos.NET" Version="1.5.821.1"/>

Seems like the nuget package is binding to the assembly for net46 applications and not .net core 2.0 apps.

@SteveSyfuhs
Copy link
Collaborator

That appears to be using the .NET 4.6.1 build, which uses the .NET Framework caching library. Try adding a reference to the System.Runtime.Caching assembly to your project.

Alternatively you might try explicitly using the netstandard2.0 version, which instead relies on the Microsoft.Extensions.Caching.Memory Nuget package.

@adragoset
Copy link
Author

adragoset commented Nov 3, 2017

I tried pulling the classes where i was using the Kerberos.Net library into a netstandard2.0 classlib but i was still getting the error when running a simple test in an xunit project.

My current solution was just to roll back to nuget package version 1.5.820.1 which works correctly for now. It seems like nuget cant figure out how to bind the correct version of the assembly for netcoreapp2.0 or netstandard2.0 projects with the latest version of the nuget package.

If i have some time tomorrow ill setup a project that recreates the problem and link it here.

https://github.com/adragoset/Kerberos.Net-Test

@SteveSyfuhs
Copy link
Collaborator

Hmm odd. I wonder if something extra has to be done for xunit to run it. I've used this latest package on a netstandard2.0 project and it worked without issue so I think it could be localized to the tests.

I did try out your project and it seems to have worked:

PS C:\dev\Kerberos.Net-Test-master\Kerberos.Net-Test-master\KerberosNetImplementation.Tests> dotnet xunit
Detecting target frameworks in KerberosNetImplementation.Tests.csproj...
Building for framework netcoreapp2.0...
  KerberosNetImplementation -> C:\dev\Kerberos.Net-Test-master\Kerberos.Net-Test-master\KerberosNetImplementation\bin\Debug\netstandard2.0\KerberosNetImplementation.dll
  KerberosNetImplementation.Tests -> C:\dev\Kerberos.Net-Test-master\Kerberos.Net-Test-master\KerberosNetImplementation.Tests\bin\Debug\netcoreapp2.0\KerberosNetImplementation.Tests.dll
Running .NET Core 2.0.0 tests for framework netcoreapp2.0...
xUnit.net Console Runner (64-bit .NET Core 4.6.00001.0)
  Discovering: KerberosNetImplementation.Tests
  Discovered:  KerberosNetImplementation.Tests
  Starting:    KerberosNetImplementation.Tests
  Finished:    KerberosNetImplementation.Tests
=== TEST EXECUTION SUMMARY ===
   KerberosNetImplementation.Tests  Total: 1, Errors: 0, Failed: 0, Skipped: 0, Time: 0.285s

@adragoset
Copy link
Author

adragoset commented Nov 3, 2017

My Test is a negative test case so a passed result means the library failed with FileNotFound exception.

I cloned Kerberos.Net and ran your tests and those all pass. I suspect that somehow the multi target nuget package is getting mangled or not working correctly rather than there be an issue with the projects code itself. Your project definition and compiler directives look correct however at least according to microsofts documentation on building multi target nuget packages for .net core.

@SteveSyfuhs
Copy link
Collaborator

Was the original error showing up in the web API app, or just the tests?

@adragoset
Copy link
Author

I haven't reached a point in the webapi project where i can do a live test yet mainly because of external dependency on adfs infrastructure that i don't have direct control over configuration on and a handful of other auth services im trying to wrap behind the webapi micro service. Was attempting to mock all that stuff in unit and integration tests.

@SteveSyfuhs
Copy link
Collaborator

I was able to reproduce it by just creating a netcoreapp and trying to create an instance of the TicketReplayValidator class, which fails with a compiler error because it's using the net46 build and that class is internal in net46.

I'm not sure why it's doing that. I've created a Stack Overflow question to see if anyone else has any ideas: https://stackoverflow.com/questions/47098227/nuget-package-targets-net-framework-and-net-standard-2-0-but-standard-projects

@dave-wharton
Copy link

We are facing the same issue. Is there a resolution around this?

@SteveSyfuhs
Copy link
Collaborator

Last I looked, it's a build packaging issue. It's placing the net46 DLL into the Core folder, so it's screwing with references. I haven't had a chance to look into it recently so I will find some time in the next week.

In the mean time you can build the project locally and it'll output the right files.

@SteveSyfuhs
Copy link
Collaborator

This is fixed now. The build output path was causing the same DLL to be used in both locations. You can find these changes in the latest nuget package: 2.1.509.2

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