.ner core InvalidOperationException: Cannot find compilation library location for package 'xxx' 和 Sq...

原文地址:传送门

1.InvalidOperationException: Cannot find compilation library location for package 'xxx'问题:

为了asp.net核心2.0项目已经成功找到外部程序集.NETStandard2.0,你需要重写一个内置的MetadataReferenceFeatureProvider。为此,我们需要添加以下类:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection.PortableExecutable;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.DependencyModel;
 
namespace Microsoft.AspNetCore.Mvc.Razor.Compilation
{
    /// <summary>Провайдер нужен для компенсации бага компиляции представлений при подключении сборок .NetStandart2.0</summary>
    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);
            }
        }
    }
}

并用下面的代码替换你的启动“services.AddMvc()”:

services.AddMvc() // Следующий патч нужен для компенсации бага компиляции представлений при подключении сборок .NetStandart2.0
    .ConfigureApplicationPartManager(manager =>
    {
        manager.FeatureProviders.Remove(manager.FeatureProviders.First(f => f is MetadataReferenceFeatureProvider));
        manager.FeatureProviders.Add(new ReferencesMetadataReferenceFeatureProvider());
    });

 

2.SqlException: 'OFFSET' 附近有语法错误。 在 FETCH 语句中选项 NEXT 的用法无效。问题:

这个原因是EF core 生成的分页语法SQL 2008不支持,要修改注册DbContext的方式

services.AddDbContext<FZTX_DBContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("FZTXDatabase"), o => o.UseRowNumberForPaging()));

 

转载于:https://www.cnblogs.com/jiyang2008/p/8488729.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值