代码非常简单---问题是groupPath字符串中有一个无效字符(确切地说是'/').
我想要做的事情(至少作为一个停止差距)是跳过DirectoryEntries我无法获得cn - 无论为什么.
但是,当我运行此代码时,catch块不会运行,而是我得到:服务器无法运行.和未处理的System.Runtime.InteropServices.COMException.
为什么catch阻止不会捕获此异常.
try
{
using (DirectoryEntry groupBinding = new DirectoryEntry("LDAP://" + groupPath))
{
using (DirectorySearcher groupSearch = new DirectorySearcher(groupBinding))
{
using (DirectoryEntry groupEntry = groupSearch.FindOne().GetDirectoryEntry())
{
results.Add(string.Format("{0}", groupEntry.Properties["cn"].Value.ToString()));
}
}
}
}
catch
{
Logger.Error("User has bad roles");
}
Run Code Online (Sandbox Code Playgroud)
附加观察:代码实际上是在一个自定义的RoleProvider中,好奇的是,如果我在一个简单的winforms应用程序中引用这个提供程序,并使用相同的输入调用这个相同的方法,那么catch块就会完全按照它的设想执行.我认为这表明有关.NET异常与COM异常的建议答案并不准确.虽然我无法理解为什么从WebDev服务器执行时此代码无法捕获
如果我已经开始进行更改,然后意识到我应该先分支,我假设如果我"从逐个工作区"创建一个分支,我将在分支中获得一个带有工作区版本的新分支.但它似乎没有那样工作,所以我现在对使用Team Foundation Server 2008进行"从版本"分支的不同选项感到困惑.
考虑以下代码,第一个演示当我们完成对IEnumerable字符串的迭代时执行"清理".第二遍是让我悲伤的原因.我需要能够在到达结束之前放弃IEnumerable,然后执行清理代码.但是如果你运行这个,你会发现在第二次通过时,清理工作永远不会发生.
放弃像这样的IEnumerable的首选方法是什么?
static void Main(string[] args)
{
// first pass
foreach (String color in readColors())
Console.WriteLine(color);
// second pass
IEnumerator<string> reader = readColors().GetEnumerator();
if (reader.MoveNext())
{
Console.WriteLine(reader.Current);
reader.Dispose();
}
}
static IEnumerable<string> readColors()
{
string[] colors = { "red", "green", "blue" };
for (int i = 0; i < colors.Length; i++)
yield return colors[i];
Console.WriteLine("Cleanup goes here");
}
Run Code Online (Sandbox Code Playgroud) 我们在Visual Studio 2010 中使用SQL Server数据库项目模板.作为集成测试的一部分,我想首先启动数据库的全新部署.但是,如果没有手动右键单击项目并选择"部署",那么获取部署的数据库的新副本似乎并不简单.
此项目类型的文档似乎稀疏到不存在.也许我正在寻找错误的地方.如果可能,请提供方法参考.
更新:
我们的集成测试在Visual Studio中编写为单元测试.因此,目标是按下Run Tests按钮,然后部署数据库,然后运行针对它的测试.
Resharper真的抱怨像WCF服务引用之类的东西生成的reference.cs等文件.如何让Resharper完全跳过这些文件?
在测试单例类时,我们需要单个实例在每次测试后"消失".有没有办法配置nunit在每次测试后重新创建测试应用程序域,或者至少在每次测试后?
我使用HTTP轮询双工WCF通道跟踪了Tomek Janczuk的Pub/sub示例,但我注意到当客户端通过关闭浏览器而断开连接时,服务在下一次回调时没有注意到.我原本应该预料到一个例外,或者说某个端点不再存在.
你怎么知道客户何时离开,以便停止向该客户发布?
在MVVM模式之后,我试图通过View连接子窗口的显示以响应来自View Model的请求.
使用MVVM-Light Messenger,View将注册请求以在View的构造函数中显示子窗口,如下所示:
InitializeComponent();
Messenger.Default.Register<EditorInfo>(this, (editorData) =>
{
ChildWindow editWindow = new EditWindow();
editWindow.Closed += (s, args) =>
{
if (editWindow.DialogResult == true)
// Send data back to VM
else
// Send 'Cancel' back to VM
};
editWindow.Show();
});
Run Code Online (Sandbox Code Playgroud)
使用Lambda订阅ChildWindow Closed事件会导致垃圾回收问题.或者换句话说,当(如果有的话)editWindow将被取消引用并因此成为垃圾收集的候选者时.
我的理解是Thread.Abort应该在被阻塞的线程上引发一个ThreadAbortException,但是在处理时似乎不是这种情况TcpListener.AcceptSocket.以下是该问题的最基本说明:
class Program
{
static void Main(string[] args)
{
Thread thread = new Thread(Listen);
thread.Start();
Thread.Sleep(1000); // give it a second to get going
Console.WriteLine("Aborting listener thread");
thread.Abort();
thread.Join();
Console.WriteLine("Listener thread finished press <enter> to end app.");
Console.ReadLine();
}
static void Listen()
{
try
{
Console.WriteLine("Starting to listen");
TcpListener listener = new TcpListener(IPAddress.Any, 4070);
listener.Start();
Socket socket = listener.AcceptSocket();
Console.WriteLine("Connected!");
return;
}
catch (ThreadAbortException exception)
{
Console.WriteLine("Abort requested");
}
}
}
Run Code Online (Sandbox Code Playgroud)
该thread.Abort()呼叫应停止AcceptSocket并执行ThreadAbortException处理.但这并没有发生. …
我正在寻找有关如何扩展现有Cognito身份验证流程以包含其他"已启用身份提供商"的文档.
目前我们做以下事情
var userPool = new CognitoUserPool(poolId, clientId, provider);
var user = new CognitoUser(username, clientId, userPool, provider);
var context = await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest { Password = string.IsNullOrEmpty(temppassword) ? password : temppassword });
如果结果context.AuthenticationResult不为null,那么我们将离开比赛,并且我可以使用context.AuthenticationResult.IdToken作为后续调用AWS API Gateway端点的OAuthBearerToken,这些端点受同一Cognito用户池保护.
所有这一切都很有效,但现在我们正在尝试启用其他身份提供商(首先使用Auth0),我现在对如何获取API网关将从Cognito识别的IdToken感到茫然,对于其中的用户而言其中一个已启用的身份提供商.
c# ×4
.net ×2
silverlight ×2
aws-sdk-net ×1
mvvm-light ×1
nunit ×1
resharper ×1
roleprovider ×1
sockets ×1
tfs ×1
wcf ×1