-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Load custom assembly to ASP .NET Core 2.0 project #6756
Comments
From @troncomputers on August 30, 2017 7:7 From @Tratcher on August 29, 2017 17:23 You should move this to https://github.com/dotnet/corefx. |
From @karelz on August 30, 2017 17:28 Do you have a minimal repro? |
@troncomputers How nip24Library.dll is built? |
From @troncomputers on August 31, 2017 7:20 @karelz Works fine with workaround with Visual Studio public class ReferencesMetadataReferenceFeatureProvider : IApplicationFeatureProvider<MetadataReferenceFeature>
{
public void PopulateFeature(IEnumerable<ApplicationPart> parts, MetadataReferenceFeature feature)
{
var libraryPaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var assemblyPart in parts.OfType<AssemblyPart>())
{
var dependencyContext = DependencyContext.Load(assemblyPart.Assembly);
if (dependencyContext != null)
{
foreach (var library in dependencyContext.CompileLibraries)
{
if (string.Equals("reference", library.Type, StringComparison.OrdinalIgnoreCase))
{
foreach (var libraryAssembly in library.Assemblies)
{
libraryPaths.Add(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, libraryAssembly));
}
}
else
{
foreach (var path in library.ResolveReferencePaths())
{
libraryPaths.Add(path);
}
}
}
}
else
{
libraryPaths.Add(assemblyPart.Assembly.Location);
}
}
foreach (var path in libraryPaths)
{
feature.MetadataReferences.Add(CreateMetadataReference(path));
}
}
private static MetadataReference CreateMetadataReference(string path)
{
using (var stream = File.OpenRead(path))
{
var moduleMetadata = ModuleMetadata.CreateFromStream(stream, PEStreamOptions.PrefetchMetadata);
var assemblyMetadata = AssemblyMetadata.Create(moduleMetadata);
return assemblyMetadata.GetReference(filePath: path);
}
}
} and in Startup.cs services.AddMvc().ConfigureApplicationPartManager(manager =>
{
var oldMetadataRefernceFeatureProvider = manager.FeatureProviders.First(f => f is MetadataReferenceFeatureProvider);
manager.FeatureProviders.Remove(oldMetadataRefernceFeatureProvider);
manager.FeatureProviders.Add(new ReferencesMetadataReferenceFeatureProvider());
}); It's working now when I launch app from Visual Studio, not working after publish and open from IIS server. On page where I'm using nip24 I'm getting HTTP ERROR 500 [EDIT] Fix C# syntax highlight by @karelz |
From @karelz on August 31, 2017 16:0
@troncomputers what does it mean? Console app? Please provide more details on what works. |
From @ericstj on August 31, 2017 17:33 @eerhardt it would seem that this direct file reference isn't making it into the deps file. @troncomputers it'd be good if you can provide an isolated repro solution that demonstrates this. Also, I hate to suggest to move again, but I think this belongs in dotnet/sdk repo, but we can wait until we confirm that. |
I couldn't repro this issue with simple netcoreapp 2.0 console app. I have referenced nip24Library.dll exactly as mentioned above and the app load it just fine. We'll not be able to help here without providing a simple repro project |
From @troncomputers on September 1, 2017 9:56 It is NOT a console app. It's ASP .NET Core web app. Just create a Web Application project with ver. ASP .NET Core 2.0 and add nip24library.dll to reference and try to build/run/compile.
|
From @ericstj on September 1, 2017 14:12 I believe this is the same as dotnet/sdk#1500, https://github.com/dotnet/core-setup/issues/2981. It looks like it's already being tracked for a fix in 2.0.1. |
From @eerhardt on September 1, 2017 14:41 Yes, the error
where BTW - I don't think the fix will make it for |
From @troncomputers on September 2, 2017 22:23 Was Microsoft plannig to support only nuget packages for asp net core web pages or it is just a bug with new technology? |
NuGet packages are certainly the best way to add references to other DLLs because they are better integrated with the build and publish process. Having said that, the issues mentioned earlier are indeed bugs that we are planning to have fixes in upcoming patch releases. |
From @troncomputers on August 30, 2017 7:7
From @troncomputers on August 29, 2017 9:26
Hi!
I'm trying to load custom assembly (nip24Library.dll). This is the C# API for finding companies by VAT Number in Poland.
VS added for me this entry to .csproj file
It looks like the web app doesn't know where this file is. How can I solve this problem?
Copied from original issue: dotnet/aspnetcore#2171
Copied from original issue: dotnet/corefx#23678
The text was updated successfully, but these errors were encountered: