小编Sta*_*opo的帖子

42
推荐指数
3
解决办法
4万
查看次数

.net core GraphQL、GraphQL.SystemTextJson:不支持“System.Type”实例的序列化和反序列化

在 ASP.NET core 5 应用程序中,我将 GraphQL 与 GraphQL.SystemTextJson 结合使用。当我尝试返回结果时,出现 System.NotSupportedException,提示“不支持‘System.Type’实例的序列化和反序列化,应该避免,因为它们可能会导致安全问题。”。

我怀疑 DocumentWriter 的配置中缺少某些内容。

在ConfigureServices中是这样配置的:

    public void ConfigureServices(IServiceCollection services)
    {

        services.AddControllers();

        ...

        services.AddScoped<IDocumentWriter, DocumentWriter>();
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

更新:

为了完整起见,按照@AndrewSilver的要求,我报告了整个代码(改编自https://www.red-gate.com/simple-talk/dotnet/net-development/building-and-consuming-graphql-api-in -asp-net-core-3-1/并移植到 .net core 5.0)。

    public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {

        services.AddControllers();
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new OpenApiInfo { …
Run Code Online (Sandbox Code Playgroud)

jsonserializer graphql asp.net-core

24
推荐指数
1
解决办法
5万
查看次数

使用Visual Studio 2015调试WPF应用程序时出现XamlParseException

我正在使用我曾经使用VS 2012进行调试的WPF应用程序.由于我切换到Visual Studio 2015,我无法再调试它.在运行时,我得到System.Windows.Markup.XamlParseException,应用程序崩溃.需要注意的是,通过双击其图标启动时,编译后的可执行文件可以正确运行.我甚至可以在VS 2015中通​​过在启动后附加流程来调试它.

在我的应用程序中,我使用了xceed.wpf.toolkit.

例外是:

System.Windows.Markup.XamlParseException occurred
  HResult=-2146233087
  LineNumber=58
  LinePosition=15
  Message='Initialization of 'Xceed.Wpf.Toolkit.BusyIndicator' threw an exception.' Line number '58' and line position '15'.
  Source=PresentationFramework
  StackTrace:
       at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
       at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
       at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
       at [...].InitializeComponent()
  InnerException: 
       HResult=-2146233088
       LineNumber=0
       LinePosition=0
       Message=Initialization of 'Xceed.Wpf.Toolkit.Core.VersionResourceDictionary' threw an exception.
       Source=System.Xaml …
Run Code Online (Sandbox Code Playgroud)

debugging wpf visual-studio-2015

10
推荐指数
1
解决办法
2358
查看次数

ASP.NET Core 3.0:禁用 ASP0000 不要在“ConfigureServices”中调用“IServiceCollection.BuildServiceProvider”

我有一个 ASP.NET Core 3.0 应用程序。在 Startup 类中,在方法中

public void ConfigureServices(IServiceCollection services)
Run Code Online (Sandbox Code Playgroud)

我想配置身份验证,以便 JWT 由我的 ISecurityTokenValidator 实现处理:CustomJwtSecurityTokenHandler。为此,我需要获取实现类的实例 CustomJwtSecurityTokenHandler,其构造函数需要注入一些服务。出于这个原因,我需要打电话:

var serviceProvider = services.BuildServiceProvider();
Run Code Online (Sandbox Code Playgroud)

为了创建一个“临时” serviceProvider 来获取我的带有注入参数的 CustomJwtSecurityTokenHandler 实例。

我最终得到了这个代码(效果很好!):

services.AddAuthentication(authenticationOptions =>
{
    authenticationOptions.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
    authenticationOptions.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(jwtBearerOptions =>
{
    jwtBearerOptions.SecurityTokenValidators.Clear();

    CustomJwtSecurityTokenHandler customJwtSecurityTokenHandler;
    {
        // create a temporary serviceProvider, in order to retrieve a CustomJwtSecurityTokenHandler (supposed to be registered as addin!).
        var serviceProvider = services.BuildServiceProvider();
        customJwtSecurityTokenHandler = serviceProvider.GetService<CustomJwtSecurityTokenHandler>();
    }

    //below line adds the custom validator class
    jwtBearerOptions.SecurityTokenValidators.Add(customJwtSecurityTokenHandler);
});
Run Code Online (Sandbox Code Playgroud)

只是,从方法 ConfigureServices 中调用 …

c# asp.net-core

10
推荐指数
0
解决办法
4713
查看次数

构建配置:任何CPU与混合平台

以下构建配置有什么区别:

  • 任何CPU
  • 混合平台

请注意,这是一个与构建配置不同的问题:混合平台VS任何CPU:根据接受的答案,在一般意义上,询问有关"构建配置设置"的建议; 在这里,我问的是具体的"混合平台"的用途,以及它与"任何CPU"的区别.

谢谢!

build visual-studio buildconfiguration

6
推荐指数
0
解决办法
3174
查看次数

2017年Visual Studio社区无法启动.例外:无法加载文件或程序集'Microsoft.VisualStudio.TelemetryForPPT

在Visual Studio 2017中打开解决方案时,我得到一个弹出窗口说:

An exception has been encountered. This may be caused by an extension.
You can get more information by examining the file '[...]\AppData\Roaming\Microsoft\VisualStudio\15.0_ce1eea42\ActivityLog.xml'.
Run Code Online (Sandbox Code Playgroud)

指定的文件报告与程序集Microsoft.VisualStudio.TelemetryForPPT相关的几个错误:

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.TelemetryForPPT, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. File name: 'Microsoft.VisualStudio.TelemetryForPPT, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at GoToDef.GoToDefMouseHandlerProvider.GetAssociatedProcessor(IWpfTextView view) at Microsoft.VisualStudio.Text.Editor.Implementation.InputController.<UpdateMouseHandlers>b__7_0(IMouseProcessorProvider p) at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.InstantiateExtension[TExtension,TMetadata,TExtensionInstance](Object errorSource, Lazy`2 provider, Func`2 getter) WRN: Assembly binding logging is turned OFF. To enable assembly bind failure …
Run Code Online (Sandbox Code Playgroud)

startup productivity-power-tools visual-studio-2017

6
推荐指数
1
解决办法
2818
查看次数

REST API 设计中的高级分页、排序和过滤

在 REST API 中,使用 URI 查询参数处理集合的排序、过滤和分页被认为是一种很好的做法,例如:

GET /employees?offset=30&limit=15&name=Mary&sort=-surname
Run Code Online (Sandbox Code Playgroud)

不幸的是,在某些“高级”情况下,参数的数量可能会“爆炸”,因此该解决方案不再可行。

回到前面的例子,假设我们想对许多其他字段应用一些更复杂的过滤器(例如:地址包含“NY”,年龄 > 30,年龄 <= 40,(婚姻状况是“已婚” AND 工资<100000USD ) 或(婚姻状况为“离婚”且薪水>=100000USD),以及许多其他……)。

显然,在这种情况下,一组简单的查询参数是不合适的。

这种情况应该如何设计?也许客户端应该发送包含一些表示查询的结构化数据的 POST?关于如何设计此类查询,是否存在或多或少的标准协议?

谢谢!

rest

5
推荐指数
1
解决办法
3861
查看次数

Sql Server LIKE 查询中需要转义哪些字符

SQL Server 查询中的 LIKE 运算符对于匹配自定义模式非常有用。然而,有时需要从模式中转义某些字符或子字符串,例如与号“%”、下划线“_”、方括号“[”和“]”等。

事实上,我正在使用参数化查询,但它不能解决 LIKE 情况,因为例如搜索_意味着“任何字符”。

在转义此类模式时必须考虑的字符集是什么?能否提供 C# 函数来执行安全转义?

c# sql-server prepared-statement

5
推荐指数
1
解决办法
2万
查看次数

覆盖子类中的“标准”方法时,pylint W0622(重新定义内置)

在 Python 中,许多方法使用“标准化”名称定义参数变量,例如:

def __exit__(self, type, value, traceback):
Run Code Online (Sandbox Code Playgroud)

在上面的行中,变量类型导致 pylint 警告 (W0622) 正在重新定义内置函数:Redefining built-in 'type' (redefined-builtin)

有很多方法可以解决这个问题并使 pylint 满意(重命名变量,添加 pylint 指令(#pylint: disable=W0622)以忽略问题等)。

在这些情况下,保持良好的代码质量并使 pylint 满意的最佳/首选/建议/常规使用方法(如果有)是什么?

python warnings coding-style software-quality pylint

5
推荐指数
1
解决办法
4284
查看次数

SQL:有效地将增量数附加到字符串,避免重复

我有一组记录(表[#tmp_origin])在字符串字段中包含重复的条目([Names]).我想将[#tmp_origin]的全部内容插入到目标表[#tmp_destination]中,该表不允许重复,并且可能已包含项目.

如果目标表中不存在源表中的字符串,则只需将in插入目标表中即可.如果目标表中的条目已存在且原始表中的条目值相同,则在将字符串插入目标表之前,必须将字符串附加的增量编号附加到该字符串.

在此示例脚本中,使用游标实现了以这种方式移动数据的过程:


-- create initial situation (origin and destination table, both containing items) - Begin

    CREATE TABLE [#tmp_origin] ([Names] VARCHAR(10))
    CREATE TABLE [#tmp_destination] ([Names] VARCHAR(10))
    CREATE UNIQUE INDEX [IX_UniqueName] ON [#tmp_destination]([Names] ASC)



    INSERT INTO [#tmp_origin]([Names]) VALUES ('a')
    INSERT INTO [#tmp_origin]([Names]) VALUES ('a')
    INSERT INTO [#tmp_origin]([Names]) VALUES ('b')
    INSERT INTO [#tmp_origin]([Names]) VALUES ('c')


    INSERT INTO [#tmp_destination]([Names]) VALUES ('a')
    INSERT INTO [#tmp_destination]([Names]) VALUES ('a_1')
    INSERT INTO [#tmp_destination]([Names]) VALUES ('b')

-- create initial situation - End

    DECLARE @Name VARCHAR(10)

    DECLARE NamesCursor CURSOR …

sql sql-server performance

3
推荐指数
1
解决办法
627
查看次数

msbuild失败:MSB3086,MSB3091:找不到"AL.exe","resgen.exe"

在64位Windows 7计算机上,我从http://msdn.microsoft.com/en-us/windows/desktop/aa904949.aspx安装了.Net framework 4.5.1和Windows SDK for Windows 8.1

在尝试构建解决方案时,我收到以下错误(这似乎是相关的):

错误MSB3086:任务无法使用SdkToolsPath""或注册表项"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx40Tools-x86"找到"AL.exe".确保已设置SdkToolsPath,并且该工具位于SdkToolsPath下正确的处理器特定位置,并且已安装Microsoft Windows SDK

错误MSB3091:任务失败,因为找不到"resgen.exe",或者未安装正确的Microsoft Windows SDK.任务是在注册表项HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx35Tools-x86的InstallationFolder值中指定的位置下的"bin"子目录中查找"resgen.exe".您可以通过执行以下操作之一来解决问题:1)安装Microsoft Windows SDK.2)安装Visual Studio 2010. 3)手动将上述注册表项设置为正确的位置.4)将正确的位置传递给任务的"ToolPath"参数.

我尝试了建议的解决方案(除了安装VS:不允许在该机器上),许多其他人在互联网上找到,例如重新安装SDK,在注册表中执行一些黑客攻击,设置环境变量,在项目中添加标签,尝试多个命令line切换到msbuild进程,并遵循以下线程:

运行MSBuild无法读取SDKToolsPath

失败的构建,因为它找不到AL.exe

tfs 2012构建任务失败,因为找不到"resgen"

但他们都没有解决问题.

这个问题类似于:

/sf/ask/1655877121/

没有答案!

任何建议将不胜感激!

.net msbuild sdk windows-7-x64

2
推荐指数
1
解决办法
1万
查看次数

如何在反应传单上添加刻度?

我正在使用与图书馆传单的反应,但我想在我的地图上添加以公里为单位的比例尺。

我该怎么做才能做到这一点?

这是我的代码:

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Map, TileLayer, Marker, Popup } from 'react-leaflet';
import './styles.css';

class App extends Component {
  state = {
    center: [51.505, -0.091],
    zoom: 13,
  };

  render() {
    return (
      <div>
        <Map center={this.state.center} zoom={this.state.zoom}>
          <TileLayer
            attribution='&amp;copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
            url="https://{s}.tile.osm.org/{z}/{x}/{y}.png"
          />
          <Marker position={this.state.center}>
            <Popup>
              A pretty CSS3 popup. <br /> Easily customizable.
            </Popup>
          </Marker>
        </Map>
      </div>
    );
  }
}

const rootElement = document.getElementById('root');
ReactDOM.render(<App />, rootElement);
Run Code Online (Sandbox Code Playgroud)

这是链接: …

javascript leaflet reactjs react-leaflet

2
推荐指数
1
解决办法
2269
查看次数