我有一个我正在努力建立的项目.它使用的是C#7.1功能,我可以通过Visual Studio运行它但是当我尝试发布以获取.exe时我得到了错误
Agent.cs(8,30): error CS8107: Feature 'async main' is not available in C# 7.
Please use language version 7.1 or greater. [C:\Users\stuarts\Documents\Visual
Studio 2017\Projects\Agent\Agent\Agent.csproj]
CSC : error CS5001: Program does not contain a static 'Main' method suitable
for an entry point [C:\Users\stuarts\Documents\Visual Studio
2017\Projects\Agent\Agent\Agent.csproj]
Run Code Online (Sandbox Code Playgroud)
csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
<RuntimeFrameworkVersion>2.0.0-*</RuntimeFrameworkVersion>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<ApplicationIcon />
<StartupObject />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RabbitMQ.Client" Version="5.0.1" />
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
我正在建设
__CODE__
同样,这在VS中调试时都有效.为什么从ConsoleApplication项目模板中获取一个简单的.exe太尴尬了!
使用ASP.NET Core 2.1获取以下代码:
[HttpGet("/unresolved")]
public async Task<ActionResult<IEnumerable<UnresolvedIdentity>>> GetUnresolvedIdentities()
{
var results = await _identities.GetUnresolvedIdentities().ConfigureAwait(false);
return results.ToList();
}
Run Code Online (Sandbox Code Playgroud)
因为我本来以为GetUnresolvedIdentities()回报IEnumerable<UnresolvedIdentity>,我可以只返回
return await _identities.GetUnresolvedIdentities().ConfigureAwait(false);
Run Code Online (Sandbox Code Playgroud)
除了我不能,因为我得到这个错误:
CS0029无法将类型隐式转换
'System.Collections.Generic.IEnumerable<Data.Infrastructure.Models.UnresolvedIdentity>'为'Microsoft.AspNetCore.Mvc.ActionResult<System.Collections.Generic.IEnumerable<Data.Infrastructure.Models.UnresolvedIdentity>>'
我需要它.ToList(),这很烦人,因为它是2行而不是1行.
为什么无法ActionResult<T>弄清楚GetUnresolvedIdentities()返回IEnumerable<>并返回那个?
签名GetUnresolvedIdentities是:
Task<IEnumerable<UnresolvedIdentity>> GetUnresolvedIdentities();
Run Code Online (Sandbox Code Playgroud) 我有一个控制器.
public sealed class AccountsController : BaseApiController
{
private readonly IDatabaseAdapter _databaseAdapter;
public AccountsController(IDatabaseAdapter databaseAdapter)
{
_databaseAdapter = databaseAdapter;
}
[AllowAnonymous]
[Route("create")]
public async Task<IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel)
{
if (!ModelState.IsValid)
return BadRequest(ModelState);
if (! await _databaseAdapter.DoesAgentExist(createUserModel.UserName))
return BadRequest();
if (await _databaseAdapter.DoesAgentHaveAccount(createUserModel.UserName))
return BadRequest();
// Create account.
var password = PasswordHelper.GeneratePassword(32);
createUserModel.Password = password;
createUserModel.ConfirmPassword = password;
var user = new ApplicationUser
{
UserName = createUserModel.UserName,
};
var addUserResult = await AppUserManager.CreateAsync(user, createUserModel.Password);
if (!addUserResult.Succeeded)
return GetErrorResult(addUserResult);
var locationHeader = new …Run Code Online (Sandbox Code Playgroud) InvalidOperationException:除非通过设置RequireHttpsMetadata = false禁用开发,否则MetadataAddress或Authority必须使用HTTPS。
我在哪里设置?
我试过了 Startup.ConfigureServices()
if (_hostingEnvironment.IsDevelopment())
services.AddMvc(opts => opts.RequireHttpsPermanent = false);
Run Code Online (Sandbox Code Playgroud)
仍然收到错误。还尝试将其放在Web.Config中只是为了让我在本地调试。
if (_hostingEnvironment.IsDevelopment())
services.AddMvc(opts => opts.RequireHttpsPermanent = false);
Run Code Online (Sandbox Code Playgroud)
都不起作用。我在MS上找不到任何有关此设置的文档!
我正在使用jwt承载身份验证。
我有这个代码:
public UnityResolver(IUnityContainer container)
{
if (container == null) throw new ArgumentNullException("container");
_container = container;
}
Run Code Online (Sandbox Code Playgroud)
Visual Studio显示3个灰点,并建议简化空检查.
它使得方法如下:
_container = container ?? throw new ArgumentNullException("container");
Run Code Online (Sandbox Code Playgroud)
那不构建......
这里发生了什么?为什么它认为它可以简化这个,为什么它将它简化为不构建的东西.
给出的错误是:
1>L:\SL1-(SentiLAN)-SentiLAN v1 - Current System\SentilanCore\WEB API with Plugins\APITest2\App_Start\UnityConfig.cs(31,39,31,44): error CS1525: Invalid expression term 'throw'
1>L:\SL1-(SentiLAN)-SentiLAN v1 - Current System\SentilanCore\WEB API with Plugins\APITest2\App_Start\UnityConfig.cs(31,39,31,44): error CS1002: ; expected
Run Code Online (Sandbox Code Playgroud)
我正在创建一个针对 dotnetcore 2.0 的项目。
根据MSDN,System.DirectoryServices.ActiveDirectory应该可以在.net core 2.0中使用,但我收到一个错误,它无法在System下找到DirectoryServices。
我需要的方法是 GetComputerDomain()
他们是 .net core 2.0 的替代品吗?
我正在寻找替代方案
using System.DirectoryServices.ActiveDirectory
var domain = Domain.GetComputerDomain();
Run Code Online (Sandbox Code Playgroud)
??
我希望能够在 Windows 和 Linux 机器上获取域。
我有一个Azure函数,我想让它从EventHub接收消息(这非常简单并且有效),然后在运行时使用表绑定将该信息放入表存储中。
这是我到目前为止的内容:
public static async Task Run(string eventHubMessage, TraceWriter log, Binder binder)
{
var m = JsonConvert.DeserializeObject<Measurement>(eventHubMessage);
var attributes = new Attribute[]
{
new StorageAccountAttribute("AzureWebJobsTest"),
new TableAttribute(tableName, m.PartitionKey, m.RowKey)
};
using(var output = await binder.BindAsync<MyTableEntity>(attributes))
{
if(output == null)
log.Info($"4. output is null");
else
{
output.Minimum = m.Minimum;
output.Maximum = m.Maximum;
output.Average = m.Average;
output.Timestamp = m.Timestamp;
output.ETag = m.ETag;
output.WriteEntity(/* Need an operationContext*/)
}
}
}
public class MyTableEntity : TableEntity, IDisposable
{
public double Average { get; set;} …Run Code Online (Sandbox Code Playgroud) 有什么用?
System.Threading.Thread.Sleep(-1)
Run Code Online (Sandbox Code Playgroud)
我希望这会引发异常,因为Thread.Sleep的文档说明了这一点
timeout的值为负,不等于Timeout.Infinite(以毫秒为单位),或者大于Int32.MaxValue毫秒.
但是,上面的Thread.Sleep(-1)不会抛出异常.当我看到ReferenceSource时,我看到了
[System.Security.SecuritySafeCritical] // auto-generated
public static void Sleep(int millisecondsTimeout)
{
SleepInternal(millisecondsTimeout);
// Ensure we don't return to app code when the pause is underway
if(AppDomainPauseManager.IsPaused)
AppDomainPauseManager.ResumeEvent.WaitOneWithoutFAS();
}
public static void Sleep(TimeSpan timeout)
{
long tm = (long)timeout.TotalMilliseconds;
if (tm < -1 || tm > (long) Int32.MaxValue)
throw new ArgumentOutOfRangeException("timeout",Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1"));
Sleep((int)tm);
}
Run Code Online (Sandbox Code Playgroud)
看起来它不会在负时间范围内抛出,但只有负时间跨度小于-1.
确实如此
Thread.Sleep(-2);
Run Code Online (Sandbox Code Playgroud)
确实会崩溃.
那么这里的特例是什么呢-1?什么是Thread.Sleep(-1)真正在做什么?
运行测试后,我在Resharper中看到此警告,所有测试均通过。
2018.08.09 11:11:58.524警告元素Data.Tests.Infra.IntegrationTests.ResolvedIdentityTests运行完成后仍处于待处理状态。2018.08.09 11:11:58.524 WARN元素数据.Tests.Infra.IntegrationTests.ResolvedIdentityTests.Reso运行完成后仍处于待处理状态。
它们是集成测试,在测试数据库中设置了一些sql,然后针对该数据库运行测试。
这是完整的测试课程:
namespace Data.Tests.Infra.IntegrationTests
{
using System;
using System.Data.SqlClient;
using System.Threading.Tasks;
using Dapper;
using Infrastructure.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public sealed class ResolvedIdentityTests
{
[ClassInitialize]
public static void Initialise(TestContext context)
{
const string sql = @"insert into infra.tblUnresolvedIdentities
(DeviceId, Fqdn, TimeConflictOccured)
values
('85E33FB5-C321-4EF2-994C-C835F136BA0C', 'unr.test.foo', '2018-08-06 12:16:24.183'),
('D3F32F97-2375-47CC-86E7-37C50ABAC85F', 'unr2.test.foo', '2018-08-06 12:16:24.183')
insert into infra.tblOrg ([Name]) values ('rito')
declare @orgId int = (select OrgId from infra.tblOrg where [Name] = 'rito');
insert into infra.tblSite ([SiteName], [OrgId]) values ('rito.site', @OrgId); …Run Code Online (Sandbox Code Playgroud) 在Clojure中,我们有一个这样的函数
(reductions str ["foo" "bar" "quax"])
=> ["foo" "foobar" "foobarquax"]
Run Code Online (Sandbox Code Playgroud)
或者
(reductions + [1 2 3 4 5])
=> [1 3 6 10 15]
Run Code Online (Sandbox Code Playgroud)
它基本上只是减少但它收集中间结果。
我在 Python 中找不到等价物。是否存在基本库函数。
蟒蛇 3
c# ×9
.net ×2
asp.net-core ×2
.net-core ×1
actionresult ×1
azure ×1
ldap ×1
msbuild ×1
null ×1
python ×1
resharper ×1
unit-testing ×1