Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Nancy 2.0 Razor viewer has issues with .NET standard assemblies #2802

Open
Lennartos opened this issue Oct 15, 2017 · 1 comment
Open

Nancy 2.0 Razor viewer has issues with .NET standard assemblies #2802

Lennartos opened this issue Oct 15, 2017 · 1 comment

Comments

@Lennartos
Copy link

Description

RazorAssemblyProvider.cs line 83 only checks the name and not assembly version.
As soon as some nuget references have more modern dependencies you get multiple assemblies like system.runtime which makes the .SingleOrDefault fail.

Steps to Reproduce

.NET 4.7 solution with rancy & razor viewengine - add nuget for sendgrid 9.9.
sendgrid has dependencies for System.Net.Http, which needs
System.Security.Cryptography.X509Certificates
which needs:
System.Security.Cryptography.Algorithms
which needs:
System.Runtime (>= 4.3.0)
which will cause the error as System.runtime 4.0 also is loaded.

  • Nancy version: 2.0
  • Nancy host ASP.NET
  • .NET Framework version: 4.7
@jdixon-86
Copy link

jdixon-86 commented Aug 28, 2018

+1

What about this to make sure you get the latest one? This would be assuming the version you are duplicating would be newer than the one on the OS:

//
// Old
//
private IEnumerable < Assembly > GetDefaultAssemblies() {
 var loadedAssemblies = new HashSet < Assembly > ();

 foreach(var assemblyDefinition in this.defaultAssemblyDefinitions) {
  var assembly = AppDomain.CurrentDomain.GetAssemblies() ** .SingleOrDefault ** x => x.GetName().Name.Equals(assemblyDefinition, StringComparison.OrdinalIgnoreCase));

 if (assembly != null) {
  loadedAssemblies.Add(assembly);
 }
}

return loadedAssemblies;
}

//
// New
//
private IEnumerable < Assembly > GetDefaultAssemblies() {
 var loadedAssemblies = new HashSet < Assembly > ();

 foreach(var assemblyDefinition in this.defaultAssemblyDefinitions) {
  var assembly = AppDomain.CurrentDomain.GetAssemblies().OrderByDescending(x => x.GetName().Version).FirstOrDefault(x => x.GetName().Name.Equals(assemblyDefinition, StringComparison.OrdinalIgnoreCase));

  if (assembly != null) {
   loadedAssemblies.Add(assembly);
  }
 }

 return loadedAssemblies;
}

jdixon-86 added a commit to Know-More-IT/Nancy that referenced this issue Aug 28, 2018
Duplicate dependencies causes an error. See issue NancyFx#2802
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

2 participants