标签: .net-core

从.net标准类库中引用UWP库

我有一些项目的解决方案:

  • 客户端应用程序 - UWP项目
  • device sdk - UWP项目(因为蓝牙API)
  • 客户端应用程序 - ASP.Net Core 1.1针对.Net Core 2.0
  • 客户端应用插件
  • 一些具有共享模型和接口类的项目.

我想尽可能多地使用.net标准项目(对于共享项目,最好是插件),因为它们更轻量级,可以编辑而无需在Visual Studio中卸载它们.

从UWP项目引用.net标准1.4库很好,但是从.net标准1.4项目引用UWP项目会导致错误:

Project DeviceSDK is not compatible with netstandard1.4 (.NETStandard,Version=v1.4).
Project DeviceSDK supports: uap10.0.15063 (UAP,Version=v10.0.15063)
Run Code Online (Sandbox Code Playgroud)

这有什么解决方法吗?

c# .net-core uwp .net-standard

0
推荐指数
1
解决办法
805
查看次数

StructureMap和.Net Core

我正在创建一个准系统.NET Core web api项目(从下面的空白模板开始)https://andrewlock.net/removing-the-mvc-razor-dependencies-from-the-web-api-template-in-asp-网核心/

下面的代码工作正常,直到我添加了StructureMap.现在,我收到了这个错误.

StructureMap.StructureMapConfigurationException:没有注册默认实例,无法自动确定类型'System.IServiceProvider'

没有为System.IServiceProvider指定配置

1.)Container.GetInstance()

在StructureMap.SessionCache.GetDefault(Type pluginType,IPipelineGraph pipelineGraph),位于WebApplication4.Startup.ConfigureServices(IServiceCollection服务)上的StructureMap.Container.GetInstanceT ---从抛出异常的上一个位置开始的堆栈跟踪---在System.Runtime Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()中的Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()中的Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)上的.ExceptionServices.ExceptionDispatchInfo.Throw()

有任何想法吗?

请注意:我们没有使用,builder.AppMvc()因为我们正试图尽可能减少这个api.

这是相关的代码.

    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        var builder = services.AddMvcCore();
        builder.AddApiExplorer();

        builder.AddAuthorization();
        builder.AddFormatterMappings();
        builder.AddJsonFormatters();
        builder.AddCors();

        // Register the Swagger generator, defining one or more Swagger documents
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
        });

        var container = ContainerConfigurator.Configure();

        return container.GetInstance<IServiceProvider>();
    }

    // This method gets called by the runtime. Use this method to …
Run Code Online (Sandbox Code Playgroud)

c# structuremap .net-core asp.net-core

0
推荐指数
1
解决办法
1942
查看次数

在每次执行中随机数和生成相同的数字序列

下面的片段随机数和每次执行中更改数字序列:

Enumerable.Range(1, 1000).OrderBy(r => Guid.NewGuid()).ToList();
Run Code Online (Sandbox Code Playgroud)

但是我想要随机数字并在每次执行应用程序时生成相同的数字序列?

.net c# .net-core

0
推荐指数
1
解决办法
301
查看次数

dotnet核心中的重复错误消息

重现步骤

dotnet new console
(introduce a bug in Program.cs)
dotnet restore
dotnet build
Run Code Online (Sandbox Code Playgroud)

典型的输出为:

Microsoft (R) Build Engine version 15.1.548.43366 Copyright (C) Microsoft Corporation. All rights reserved.

Program.cs(5,5): error CS0116: A namespace cannot directly contain members such as fields or methods [/Users/xxx/Documents/myproj/myproj.csproj]

Build FAILED.

Program.cs(5,5): error CS0116: A namespace cannot directly contain members such as fields or methods [/Users/xxx/Documents/myproj/myproj.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.77
Run Code Online (Sandbox Code Playgroud)

您可以看到错误CS0116被报告两次。

我的问题是:有没有办法避免重复报告错误?

msbuild .net-core visual-studio-code dotnet-cli

0
推荐指数
1
解决办法
450
查看次数

为什么最近实现了String.StartsWith(char),而不是String.Contains(char)?

String.StartsWith(char)String.EndsWith(char)C#7.0 .NET Core 2.0 中新实现.

为什么String.Contains(char)没有实施?

我通常会听到String.Contains(char)自己使用创建扩展的常见论点String.IndexOf(c) != -1.但我不喜欢创建简单的扩展,特别是如果我打算为了可读性而创建一个扩展,这就是我认为这些新的重载是为了(以及为什么我批准了这些更改:)).

c# string .net-core

0
推荐指数
1
解决办法
359
查看次数

在C#中解密RSA时出现Internal.Cryptography.CryptoThrowHelper.WindowsCryptographicException

我在C#dotnet核心测试RSA.我创建了两个RSA对象,一个用于加密,另一个用于解密.我从第一个rsa对象导出公钥,并将其导入另一个对象.当第二个解密密码数组时,它会抛出Internal.Cryptography.CryptoThrowHelper.WindowsCryptographicException.代码如下:

        String plainstr = "Hello World";

        RSA rsa1 = RSA.Create();
        RSA rsa2 = RSA.Create();
        rsa1.KeySize = 1024;
        rsa2.KeySize = 1024;

        byte[] cipherbytes = rsa1.Encrypt(Encoding.ASCII.GetBytes(plainstr), RSAEncryptionPadding.Pkcs1);
        //If the parameter is true, it works well. But when I use it in an actual project, I won't pass the private key.
        RSAParameters parameters = rsa1.ExportParameters(false);
        rsa2.ImportParameters(parameters);
        //Exception is here.
        byte[] plaintbytes = rsa2.Decrypt(cipherbytes, RSAEncryptionPadding.Pkcs1);
        Console.WriteLine(Encoding.ASCII.GetString(plaintbytes));
        Console.ReadKey();
Run Code Online (Sandbox Code Playgroud)

c# rsa .net-core

0
推荐指数
1
解决办法
827
查看次数

c#命名空间不能直接包含字段或方法等成员

任何人都能说出这里有什么问题吗?我只是创建一个文件夹调用模型并添加新类BaseEntity,我得到错误.直到现在我添加新课时没有收到此错误...

在此输入图像描述

c# .net-core

0
推荐指数
1
解决办法
705
查看次数

EFCore在dbcontext的生命周期中使用单个dbconnect

我正在使用EFCore将数据传输到后端数据库,我要求SaveChanges每增加一定数量的新对象添加到数据集中,我从EFCore调试日志中注意到它将关闭连接并在每次调用时打开一个新连接SaveChanges:

Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection|DEBUG|Opening connection to database ...
Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection|DEBUG|Beginning transaction with isolation level 'Unspecified'.
Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection|DEBUG|Committing transaction
Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection|DEBUG|Closing connection to database...
.... the logs repeats forever
Run Code Online (Sandbox Code Playgroud)

那么无论如何只需要在一个生命周期中使用一个连接DbContext

c# entity-framework entity-framework-core .net-core

0
推荐指数
1
解决办法
725
查看次数

Linux上的.NET Core中的后台作业

我正在开发.NET Core Web API,我有一个上传excel文件的操作,这应该读取文件,处理它并将内容保存到SQL Server数据库,当然可以插入一行excel多个表,之前创建的表结构用于存储所有数据,这不是简单的转储或批处理过程.

除了API,我们为客户端开发了一个Angular 4应用程序,因此从Angular组件上传文件,到目前为止一切都很好

问题是,有人可以上传一个非常巨大的文件的API,我们正在考虑的一种方式来处理后台进程的文件,因此客户端用户只会选择文件并点击上传文件时,API应该排队的文件后台任务将处理文件并执行需要执行的操作以保存到数据库.

所有基础设施(API,客户端和数据库)都将部署到Linux环境中.问题是:这是一个好方法吗? linux中有什么东西可以用吗?

我已经读过关于RabbitMQ的内容,但我不确定它,或者是否有更好或更适合这种情况的东西.

你们怎么处理类似的情况?

感谢您的回答和建议.

rabbitmq .net-core asp.net-core asp.net-core-1.1 angular

0
推荐指数
1
解决办法
464
查看次数

如何仅从LINQ中的序列(IEnumerable)中过滤元素

例如:{ 1,2,3,4,5,3,6}.Filter(i => i.Equals(3))将成为{1,2,4,5,3,6}

我目前的方式:

array
.TakeWhile(i => !i.Equals(min))
.Concat(array.SkipWhile(i => !i.Equals(min)).Skip(1))
Run Code Online (Sandbox Code Playgroud)

我希望有一种比这更优雅(更短)的方式

.net c# linq .net-core

0
推荐指数
1
解决办法
250
查看次数