标签: coreclr

如何检查.NET Core中的类型是否是抽象的?

此代码在.NET(4.6及更早版本)中运行良好

var types = typeof(SomeType).GetTypeInfo().Assembly.GetTypes()
from type in types
where !type.IsAbstract
Run Code Online (Sandbox Code Playgroud)

但在.NET Core(DNX Core 5.0)中,它产生了一个编译错误:

错误CS1061'Type'不包含'IsAbstract'的定义,也没有扩展方法'IsAbstract'接受类型'Type'的第一个参数(你是否缺少using指令或汇编引用?)

那么如何在.NET Framework 4.6中以我的方式检查DNX Core 5.0中类型是否是抽象的呢?

在此输入图像描述

reflection abstract-class types .net-core coreclr

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

在.Net Core 2.2中以IActionResult返回HttpResponseMessage的正确方法

在.Net Core 2.2中。我正在创建一个API控制器,该控制器基于有效负载将请求路由到另一个Http端点。

[Route("api/v1")]
public class RoutesController : Controller
{
    [HttpPost]
    [Route("routes")]
    public async Task<IActionResult> Routes([FromBody]JObject request)
    {

      var httpClient = new HttpClient();

      // here based on request httpCLient will make `POST` or `GET` or `PUT` request
      // and returns `Task<HttpResponseMessage>`. Lets assume its making `GET` 
      // call

     Task<HttpResponseMessage> response = await httpClient.GetAsync(request["resource"]);

       ??? what is the correct way to return response as `IActionResult`
    }        
}
Run Code Online (Sandbox Code Playgroud)

基于SO文章中,我能做到这一点

        return StatusCode((int)response.StatusCode, response);
Run Code Online (Sandbox Code Playgroud)

但是我不知道送HttpResponseMessageObjectResult是正确的方法。

我还想确保内容协商将正常进行。

.net-core coreclr asp.net-core asp.net-core-webapi asp.net-core-2.0

10
推荐指数
2
解决办法
8204
查看次数

如何在ASP.Net核心中注入WCF服务客户端?

我有需要从ASP.NET Core访问的WCF服务.我已经安装了WCF Connected Preview并成功创建了代理.

它创建了接口和客户端,如下所示

    [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.3.0.0")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName="ServiceReference1.IDocumentIntegration")]
    public interface IDocumentIntegration
    {

        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IDocumentIntegration/SubmitDocument", ReplyAction="http://tempuri.org/IDocumentIntegration/SubmitDocumentResponse")]
        [System.ServiceModel.FaultContractAttribute(typeof(ServiceReference1.FaultDetail), Action="http://tempuri.org/IDocumentIntegration/SubmitDocumentFaultDetailFault", Name="FaultDetail", Namespace="http://schemas.datacontract.org/2004/07/MyCompany.Framework.Wcf")]
        System.Threading.Tasks.Task<string> SubmitDocumentAsync(string documentXml);
    }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.3.0.0")]
    public interface IDocumentIntegrationChannel : ServiceReference1.IDocumentIntegration, System.ServiceModel.IClientChannel
    {
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.3.0.0")]
    public partial class DocumentIntegrationClient : System.ServiceModel.ClientBase<ServiceReference1.IDocumentIntegration>, ServiceReference1.IDocumentIntegration
    { 
      // constructors and methods here
    }
Run Code Online (Sandbox Code Playgroud)

调用该服务的消费者类如下所示

public class Consumer
{
  private IDocumentIntegration _client;
  public Consumer(IDocumentIntegration client)
  {
    _client = client;
  }

  public async Task Process(string id)
  {  
     await _client.SubmitDocumentAsync(id);
  }
} 
Run Code Online (Sandbox Code Playgroud)

如何在Startup类中使用ConfigureServices方法注册IDocumentIntegration?我想在注册期间设置RemoteAddress和clientCredentials

  public void …
Run Code Online (Sandbox Code Playgroud)

c# .net-core coreclr asp.net-core

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

Typeconverter无法在asp.net核心中运行

我已经Amount存储在数据库中了decimal.我希望用千位分隔符在UI上显示该值.我可以[DisplayFormat(DataFormatString = "{0:N2}", ApplyFormatInEditMode = true)]在amount属性上添加属性,这将显示千位分隔符的数字,但是当我将值POST回服务器时,由于逗号,MVC模型绑定将不起作用.

我创建了一个自定义类型转换器,可以转换decimalstring然后转换stringdecimal

public class NumberConverter : TypeConverter
{
    public override bool CanConvertFrom(
        ITypeDescriptorContext context,
        Type sourceType)
    {
        if (sourceType == typeof(decimal))
        {
            return true;
        }
        return base.CanConvertFrom(context, sourceType);
    }
    public override object ConvertFrom(ITypeDescriptorContext context,
        CultureInfo culture, object value)
    {
        if (value is decimal)
        {
            return string.Format("{0:N2}", value);
        }
        return base.ConvertFrom(context, culture, value);
    }
    public override bool CanConvertTo(ITypeDescriptorContext context,
        Type destinationType)
    {
        if …
Run Code Online (Sandbox Code Playgroud)

asp.net-core-mvc coreclr asp.net-core asp.net-core-1.0

9
推荐指数
1
解决办法
2143
查看次数

CLR与核心CLR

我知道CLR在当前状态下绑定到Windows操作系统,并通过内部使用Win32 API提供各种服务.

由于.NET Core与平台无关,这基本上意味着相同的IL代码可以在不同的OS上运行.CoreCLR OS是否具体?或者是编写CoreCLR代码以根据当前执行环境/ OS采用不同的执行路径?

clr .net-core coreclr

9
推荐指数
1
解决办法
4381
查看次数

是否可以在Windows XP上运行CoreCLR?

现在我们有一个.NET核心的免费开源实现:CoreCLR.它支持Windows和Linux操作系统,计划支持Mac OS.是否可以在Windows XP上运行CoreCLR?

.net windows-xp coreclr

8
推荐指数
2
解决办法
5787
查看次数

在CoreCLR中运行F#

我按照这里描述编译了CoreCLRCoreFX.基本上,我可以编译和运行针对CoreCLR的C#代码. 下一步是尝试编译和运行F#代码.所以我将FSharp.Core 3.1.2.1添加到项目中,并使用以下命令编译了一个示例应用程序:

fsc ^
--noframework ^
--targetprofile:netcore ^
/r:packages\System.Runtime.4.0.20-beta-22703\lib\contract\System.Runtime.dll ^
/r:packages\System.Reflection.4.0.10-beta-22703\lib\contract\System.Reflection.dll ^
/r:packages\System.Collections.4.0.10-beta-22703\lib\contract\System.Collections.dll ^
/r:packages\System.Diagnostics.Debug.4.0.10-beta-22703\lib\contract\System.Diagnostics.Debug.dll ^
/r:packages\System.IO.FileSystem.4.0.0-beta-22703\lib\contract\System.IO.FileSystem.dll ^
/r:packages\System.Linq.Expressions.4.0.10-beta-22703\lib\contract\System.Linq.Expressions.dll ^
/r:packages\System.Console.4.0.0-beta-22703\lib\contract\System.Console.dll ^
/r:packages\System.Runtime.Extensions.4.0.10-beta-22703\lib\contract\System.Runtime.Extensions.dll ^
/r:packages\System.Runtime.InteropServices.4.0.20-beta-22703\lib\contract\System.Runtime.InteropServices.dll ^
/r:packages\System.Text.Encoding.4.0.10-beta-22703\lib\contract\System.Text.Encoding.dll ^
/r:packages\System.Text.RegularExpressions.4.0.10-beta-22703\lib\contract\System.Text.RegularExpressions.dll ^
/r:packages\System.Threading.Overlapped.4.0.0-beta-22703\lib\contract\System.Threading.Overlapped.dll ^
/r:packages\System.Threading.ThreadPool.4.0.10-beta-22703\lib\contract\System.Threading.ThreadPool.dll ^
/r:packages\FSharp.Core.3.1.2.1\lib\portable-net45+netcore45+MonoAndroid1+MonoTouch1\FSharp.Core.dll ^
/out:runtime\HelloWorld.exe HelloWorld.fs
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我构建了FSharp.Core的Profile7.当我运行应用程序时,语句let test = sprintf "Hello, world"失败并出现以下异常:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the …
Run Code Online (Sandbox Code Playgroud)

c# f# coreclr

8
推荐指数
1
解决办法
2724
查看次数

dnxcore50与dnx451的性能比较?(CoreClr与.net Framework)

我试图找到一些关于这两个目标的性能数据进行比较,但没有成功.我对在Windows上运行的asp.net5 Web应用程序感兴趣(例如,或者azure web app).在性能方面是否有任何显着差异,或者从目标角度来看,目标大致相等?

coreclr dnx asp.net-core

8
推荐指数
1
解决办法
4448
查看次数

.net核心中的ServicePointManager.DefaultConnectionLimit?

我正在将.net api 2服务移植到.net核心,我在旧的web api服务中找到了这一行.

ServicePointManager.DefaultConnectionLimit = int.MaxValue;
Run Code Online (Sandbox Code Playgroud)

这行代码增加了连接限制.我不知道它是针对计算机,框架还是应用程序.在阅读了stackoverflow上的这个答案之后,我也意识到将它设置为int.max可能不是最好的主意.但是,我仍然想在我的新.net核心服务中控制它.

如何在.net核心中修改/增加DefaultConnectionLimit.另外,我怎么知道.net核心的默认限制是什么?(如果这是一个有效的问题:))

.net asp.net-core-mvc coreclr dnx asp.net-core

8
推荐指数
1
解决办法
4793
查看次数

Pythonnet 是否支持 .NET Core 或 .NET 5.0

我已经使用 Pythonnet 有一段时间了,但总是反对 .NET Framework 4。* 随着 .NET 5.0 的最新版本,我想迁移我的项目,但我无法使其适用于非框架版本(例如 .NET Core 2.0、.NET 核心 3.0、.NET 5.0)

这是我使用 .NET Framework 4.5 运行的一个非常简单的测试:

namespace TestNet
{
    public class Dummy
    {
        private string _name;

        public Dummy(string name)
        {
            _name = name;
        }

        public string Hello(string name)
        {
            return $"Hello {name}, my name is {_name}";
        }
    }
}

Run Code Online (Sandbox Code Playgroud)

这会生成 TestNet.dll 然后我运行以下 Python 代码:

>>> import clr
>>> clr.AddReference("TestNet")
<System.Reflection.RuntimeAssembly object at 0x000001899ACFABB0>
>>> from TestNet import Dummy
>>> d = Dummy("Bob")
>>> d.Hello("John")
'Hello …
Run Code Online (Sandbox Code Playgroud)

.net c# python python.net coreclr

8
推荐指数
1
解决办法
1365
查看次数