我想使用.NET CoreCLR运行一个hello-world控制台应用程序.
到目前为止,我的代码如下.
// Program.cs
using System;
namespace Study
{
public class Program
{
public void Main()
{
Console.WriteLine("Hello world!");
}
}
}
Run Code Online (Sandbox Code Playgroud)
// project.json
{
"frameworks": {
"dnxcore50": { }
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用命令运行此项目:
dnvm use 1.0.0-beta8 -r coreclr
dnx run
Run Code Online (Sandbox Code Playgroud)
但是,这会产生以下错误:
Microsoft.Dnx.Compilation.CSharp.RoslynCompilationException: warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options.
(1,11): DNXCore,Version=v5.0 error CS0246: The type or namespace name 'System' could not be found …Run Code Online (Sandbox Code Playgroud) 我在Mac OS X上安装了最新的.NET Core,并按照教程进行操作
https://dotnet.github.io/getting-started/
Run Code Online (Sandbox Code Playgroud)
首先,我使用'dotnet new'创建了一个示例项目,然后运行命令'dotnet restore'.它失败了以下消息:
Microsoft .NET Development Utility CoreClr-x64-1.0.0-rc1-16231
CACHE https://api.nuget.org/v3/index.json
Restoring packages for /Users/cookie/Documents/Github/t/project.json
GET https://api.nuget.org/v3-flatcontainer/netstandard.library/index.json
NotFound https://api.nuget.org/v3-flatcontainer/netstandard.library/index.json 2388ms
Unable to locate Dependency NETStandard.Library >= 1.0.0-rc2-23616
Writing lock file /Users/cookie/Documents/Github/t/project.lock.json
Restore complete, 2759ms elapsed
Errors in /Users/cookie/Documents/Github/t/project.json
Unable to locate Dependency NETStandard.Library >= 1.0.0-rc2-23616
Feeds used:
https://api.nuget.org/v3-flatcontainer/
Run Code Online (Sandbox Code Playgroud)
我收到404错误
https://api.nuget.org/v3-flatcontainer/netstandard.library/index.json
Run Code Online (Sandbox Code Playgroud)
我在Windows上尝试了相同的方法,但也失败了.任何帮助,将不胜感激!
编辑:这似乎是一个错误,在https://github.com/dotnet/cli/issues/535中讨论过 .最新的安装包现在生成NuGet.config,并成功从myget中检索NETStandard.Library.
例如,我们有一个多维的双维数组
double[,] d = new double[1,2];
d.GetType() 回报 {Name = "Double[,]" FullName = "System.Double[,]"}
d[0,0]被编译为call instance float64 float64[0..., 0...]::Get(int32, int32)IL
如何System.Double[,]生成类型的源代码?它是在CLR中烘焙还是Roslyn负责它的产生?
我有简单的web api开发使用Asp.Net Core,我试图使用HttpClient发布键值对.我尝试了两种方法.
第一种方法
[Route("api/[controller]/[action]")]
public class TransformationController : Controller
{
private IServiceResolver _serviceResolver;
public TransformationController(IServiceResolver serviceResolver)
{
_serviceResolver = serviceResolver;
}
[HttpPost]
[ActionName("Post1")]
public void Post1([FromBody]Dictionary<string, string> data)
{
// do something
}
}
Run Code Online (Sandbox Code Playgroud)
然后我发布如下
[Fact]
public void TestPost1()
{
var content = new Dictionary<string, string>();
content.Add("firstname", "foo");
var httpContent = new FormUrlEncodedContent(content);
var client = new HttpClient();
var result = client.PostAsync("http://localhost:17232/api/Transformation/Post1", httpContent).GetAwaiter().GetResult();
}
Run Code Online (Sandbox Code Playgroud)
但我收到了Unsupported Media Type错误
{StatusCode:415,ReasonPhrase:'Unsupported Media Type',版本:1.1,内容:System.Net.Http.StreamContent,标题:{Date:Mon,29 Aug 2016 19:44:44 GMT Server:Kestrel …
我有ASP.NET核心应用程序.到目前为止,我一直在使用ValidateAntiForgeryToken所有POST动作方法的属性.
现在我想ValidateAntiForgeryToken在控制器级别使用它,因此它可以处理两者POST和GET方法.
下面是样本控制器
[ValidateAntiForgeryToken]
public class SearchController : Controller
{
public SearchController()
{
}
[HttpGet]
public IActionResult Index()
{
return View();
}
[HttpPost]
public IActionResult Save(MyModel model)
{
}
Run Code Online (Sandbox Code Playgroud)
}
当用户访问URL http:// localhost/search时,我不确定Indexaction方法将如何接收forgerytoken?现在我得到错误,Bad Request因为请求中没有包含令牌.
asp.net-mvc antiforgerytoken asp.net-core-mvc coreclr asp.net-core
我通过一个名为Marten的库使用一个postgres数据库和一个.NET应用程序,我有一个IUserLoginStore管理检索用户及其角色的自定义.这似乎工作正常但我在设置授权时遇到问题.
我通过谷歌使用身份验证,它工作正常:
var info = await _signInManager.GetExternalLoginInfoAsync();
var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false);
Run Code Online (Sandbox Code Playgroud)
此操作会抛出访问被拒绝的问题:
[HttpPost()]
[Authorize(Roles = "Admin")]
public JsonResult SubmitArticle([FromBody] ArticleInputModel input) {...}
Run Code Online (Sandbox Code Playgroud)
我已经挖了授权代码,问题似乎是默认ClaimsPrincipal代码:
public virtual bool IsInRole(string role)
{
return false;
}
Run Code Online (Sandbox Code Playgroud)
我应该实现自己的版本ClaimsPrinciple并覆盖它IsInRole,如果我这样做,我怎么把它重新带回应用程序?
private static void ConfigureSecurity(IServiceCollection services)
{
services.AddIdentity<User, Role>()
.AddUserValidator<UserValidator>()
.AddUserStore<MartenUserStore>()
.AddRoleStore<MartenRoleStore>()
.AddDefaultTokenProviders();
}
Run Code Online (Sandbox Code Playgroud) 我有ASP.NET Core API.我已经阅读了这里的文档,展示了如何在asp.net核心中进行集成测试.该示例设置测试服务器,然后调用控制器方法.
但是我想直接测试一个特定的类方法(不是控制器方法)?例如:
public class MyService : IMyService
{
private readonly DbContext _dbContext;
public MyService(DbContext dbContext)
{
_dbContext = dbContext;
}
public void DoSomething()
{
//do something here
}
}
Run Code Online (Sandbox Code Playgroud)
当测试开始时,我希望startup.cs被调用,以便所有依赖项都会被注册.(比如dbcontext)但是我不确定在集成测试中如何解决IMyService?
注意:我想DoSomething()直接测试方法的原因是因为任何控制器都不会调用此方法.我Hangfire在此API中使用进行后台处理.Hangfire的后台处理作业将调用DoSomething()方法.因此,对于集成测试,我想避免使用Hangfire并直接调用DoSomething()方法
我们有 3 个 .net core 应用程序在生产中运行。所有应用程序都托管在 IIS 中。当我验证 TaskManager 时,我注意到其中一个应用程序的内存激增。我想找出是哪个应用程序造成的。任务管理器仅将进程名称显示为dotnet
有没有办法在任务管理器中显示实际的应用程序名称?
当我在VS 2017上运行.NET Core Web API应用程序时,
在输出的调试面板中,继续显示异常抛出:
'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
但是,应用程序运行良好,不会停止或发生故障.
我知道Exception总是意味着需要关心的事情.
那么,如何在运行CoreCLR时搜索未找到的文件?
- - - - - - - 更多 - - - - - - - - - -
'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App\2.0.0\System.Private.Xml.Linq.dll'. Symbols loaded.
'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App\2.0.0\System.Private.Xml.dll'. Symbols loaded.
'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App\2.0.0\System.Resources.ResourceManager.dll'. Symbols loaded.
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 生成正在运行的 .net core 进程的合理大小的gcore核心转储,但该文件大于 20GB。该过程是dotnet wapi.dll使用创建的空项目的二进制文件dotnet new webapi。我认为转储的大小与虚拟内存量有关。
主要问题是如何生成更小的核心转储?
这与我的想法(虚拟内存)有关吗?
我应该限制虚拟内存吗?如何?
coreclr ×10
.net ×5
asp.net-core ×4
c# ×3
.net-core ×2
asp.net ×1
asp.net-mvc ×1
iis ×1
roslyn ×1
xunit ×1