• .ner core InvalidOperationException: Cannot find compilation library location for package 'xxx' 和 SqlException: 'OFFSET' 附近有语法错误。 在 FETCH 语句中选项 NEXT 的用法无效。问题


    原文地址:传送门

    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()));
  • 相关阅读:
    spring相关资源
    spring mvc获取request HttpServletRequest
    spring中文乱码问题
    haskell读写文件相关(含二进制)
    grade web的构建约定 convention
    李洪强iOS开发之-实现点击单行View显示和隐藏Cell
    Animated progress view with CAGradientLayer(带翻译)
    关于CAShapeLayer
    CAShapeLayer的使用
    用缓动函数模拟物理动画
  • 原文地址:https://www.cnblogs.com/jiyang2008/p/8488729.html
Copyright © 2020-2023  润新知