我使用 .NET 创建了一个新的 .NET 6 辅助服务项目dotnet new worker -n MyProject。然后我创建了一个新的解决方案dotnet sln new -n MySolution。最后我将项目添加到解决方案中dotnet sln add .\MyProject\MyProject.csproj。当我在 Visual Studio 2022 中打开解决方案时,默认 Worker.cs 文件中出现了一堆“错误”:
该项目将构建并运行得很好。问题似乎与 .NET 6 的新隐式使用功能有关。Visual Studio 无法识别红色下划线的项是从其命名空间隐式导入的,并且不必手动引用。错误列表中多了一个错误:
项目“C:\LongDirectoryPathHere\MyProject\obj\MyProject.csproj.nuget.g.targets”未由“C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Current\Bin\amd64\Microsoft”导入。 Common.targets”位于 (35,3),因为该文件不存在。
我查了一下,该文件确实存在。
除了使用速度更快之外,我使用dotnet new而不是在 Visual Studio 中创建解决方案/项目的原因是 Visual Studio 抱怨路径太长,并拒绝创建输出路径长度超过 259 个字符的文件的项目,尽管 Windows 10 支持长达数千个字符的路径。“丢失”文件的完整路径正好是 261 个字符。
这是最大路径问题引起的还是其他原因?
我有一个Task查询活动目录并用结果填充列表的方法。我已经设置了我的任务,以便可以取消它,但是,当调用取消时,任务将继续执行其工作。我知道任务已被取消,因为它返回并且打算在任务返回时执行的操作正在运行,但查询继续在后台运行,使用内存和处理能力。任务可以重复启动和“取消”,任务的每次迭代都会运行并使用资源。我怎样才能让取消真正取消?
private async Task RunQuery(QueryType queryType,
string selectedItemDistinguishedName = null)
{
StartTask();
try
{
_activeDirectoryQuery = new ActiveDirectoryQuery(queryType,
CurrentScope, selectedItemDistinguishedName);
await _activeDirectoryQuery.Execute();
Data = _activeDirectoryQuery.Data.ToDataTable().AsDataView();
CurrentQueryType = queryType;
}
catch (ArgumentNullException)
{
ShowMessage(
"No results of desired type found in selected context.");
}
catch (OutOfMemoryException)
{
ShowMessage("The selected query is too large to run.");
}
FinishTask();
}
private void CancelCommandExecute()
{
_activeDirectoryQuery?.Cancel();
}
Run Code Online (Sandbox Code Playgroud)
public async Task Execute()
{
_cancellationTokenSource = new CancellationTokenSource();
var taskCompletionSource = new …Run Code Online (Sandbox Code Playgroud) 我的 Visual Studio 2017 试用期已过,无法登录解锁程序。身份验证每次都失败,并出现错误:
An error has occurred and we can no longer retrieve information for your account.
Please reenter your credentials.
Run Code Online (Sandbox Code Playgroud)
我检查了 的日志servicehub,他们都说(为了可读性添加了换行符):
Error :
Error starting hub controller:
System.InvalidOperationException:
Controller terminated before accepting connections.
Exit code: -1073741502.
Run Code Online (Sandbox Code Playgroud)
或者
Error :
Exception retrying connect to json rpc:
System.InvalidOperationException:
Controller terminated before accepting connections.
Exit code: -1073741502.
Run Code Online (Sandbox Code Playgroud)
我尝试以管理员身份运行该程序,删除会话令牌,使用不同的 Microsoft 帐户,甚至使用不同的 PC。不同的 PC 问题让我觉得我的网络可能有问题,但我不确定那可能是什么。
我有一个Dictionary以枚举值作为键并返回一个对象作为值.对象构造函数涉及调用一个可能需要很长时间并占用大量内存的方法.现在,即使只需要一个对象,也会创建字典中的每个可能对象.有没有办法只创建键指定的对象?
private DataPreparer SetUpOuDataPreparer()
{
Scope = _activeDirectoryScope.Context;
var activeDirectorySearcher = new ActiveDirectorySearcher(
_activeDirectoryScope);
var ouDataPreparers = new Dictionary<QueryType, DataPreparer>
{
[OuComputers] = new DataPreparer
{
Data = activeDirectorySearcher.GetOuComputerPrincipals(),
Attributes = DefaultComputerAttributes
},
[OuGroups] = new DataPreparer
{
Data = activeDirectorySearcher.GetOuGroupPrincipals(
CancellationToken),
Attributes = DefaultGroupAttributes
},
[OuUsers] = new DataPreparer
{
Data = activeDirectorySearcher.GetOuUserPrincipals(),
Attributes = DefaultUserAttributes
},
[OuUsersDirectReports] = new DataPreparer
{
Data = activeDirectorySearcher.GetOuUsersDirectReports(
CancellationToken),
Attributes = DefaultUserDirectReportsAttributes
},
[OuUsersGroups] = new DataPreparer
{
Data = …Run Code Online (Sandbox Code Playgroud) 我有一个using块IDisposable DirectoryEntry来创建目录条目,访问其中一个属性,然后处置它.但是,目录条目在使用块结束之前被处理.
public static PropertyValueCollection GetProperty(
this Principal principal, string propertyName)
{
using (var directoryEntry = principal.GetAsDirectoryEntry())
{
return directoryEntry.Properties[propertyName];
}
}
public static DirectoryEntry GetAsDirectoryEntry(
this Principal principal)
{
return principal.GetUnderlyingObject() as DirectoryEntry;
}
Run Code Online (Sandbox Code Playgroud)
该错误被抛出return directoryEntry.Properties[propertyName];,表示该目录条目已被释放.我可以删除使用块,代码将工作,但我担心该对象永远不会被处置.我多次调用它,因此创建目录条目的多个实例并且从未处理过?
我是学习Haskell的学生.我的教科书以下面的例子为例:
(*) :: Int -> Int -> Int
m * 0 = 0
m * (n + 1) = m + (m * n)
Run Code Online (Sandbox Code Playgroud)
然后它要求我们以相同的方式重新定义^(正整数取幂)运算符.我假设以下内容可行:
(^) :: Int -> Int -> Int
m ^ 0 = 1
m ^ (n + 1) = m * (m ^ n)
Run Code Online (Sandbox Code Playgroud)
但是,它无法编译,在该(n + 1)位上给出"模式中的解析错误" .出于好奇,我尝试了本书示例中定义的乘法运算符,并给出了相同的错误.
教科书在哪里/如何出错,我该如何纠正呢?
感谢那些指出这个问题在几年前得到解决的人.由于删除了n + k模式匹配的"特征",我如何修改教科书示例以遵循现代良好实践?
简而言之,我现在知道为什么原件不起作用,但它怎么能改变工作呢?