Visual Studio无法写入输出文件’… \ _ \ netj \ Debug \ Foo.Bar.dll“

我在Visual Studio 2010中编译一个大的c#解决方案时遇到了这个错误。每次编译后我都要删除此解决方案使用的项目之一的obj文件夹。 否则我收到以下错误: Could not write to output file ‘…\obj\Debug\Foo.Bar.dll’ The process cannot access the file because it is being used by another process 我一直在寻找互联网上的解决方案,实际上发现/尝试了一些解决方案。 例如:很多开发论坛的人都建议在UserControl (在其他一些来源中)设计器打开时不要开始编译。 其他一些人使用预构建脚本来删除obj文件夹,这个特殊的解决方案是可以接受的,但如果发布的项目是一个广泛使用的库,它的重新编译将导致重新编译“父”项目。

如何从XDocument获取子节点的值

我需要使用linq从XDocument获取子节点的值 1234 123 Main street AL 我试过这个: xDocTest.Root.Elements(“Cust”).Elements(“ACTNumber”) 如果我尝试使用Address而不是ACTNumber,那么它可以工作。 但它没有给出子节点值。

在没有Ajax的asp.net回发之后执行javascript函数

我希望在asp.net回发之后执行一个javascript函数,而不使用ajax。 我在偶数方法中尝试了以下方法但没有运气: Page.ClientScript.RegisterStartupScript(GetType(), “ShowPopup”, “showCheckOutPopIn(‘Livraison’,556);”);

字节的最大长度?

我正在尝试创建一个byte数组,其长度为UInt32.MaxValue 。 这个数组本质上是一个小的(ish)内存数据库: byte[] countryCodes = new byte[UInt32.MaxValue]; 但是,在我的机器上,在运行时,我得到一个System.OverflowException其中“算术运算导致溢出”。 这是怎么回事? 我是否需要使用unsafe块和malloc ? 我如何在C#中做到这一点?

dependency injection,注入参数

我正在使用DI的vNext实现。 如何将参数传递给构造函数? 例如,我有课: public class RedisCacheProvider : ICacheProvider { private readonly string _connectionString; public RedisCacheProvider(string connectionString) { _connectionString = connectionString; } //interface methods implementation… } 和服务注册: services.AddSingleton(); 如何将参数传递给RedisCacheProvider类的构造函数? 例如Autofac: builder.RegisterType() .As() .WithParameter(“connectionString”, “myPrettyLocalhost:6379”);

替代在System.Web中为Owin使用HttpContext

ASP.NET身份validation现在基于OWIN中间件,可以在任何基于OWIN的主机上使用。 ASP.NET Identity 对System.Web没有任何依赖 。 我有一个AuthorizeAttributefilter,我需要获取当前用户并添加一些属性以供操作控制器稍后检索。 问题是我必须使用属于System.Web的HttpContext。 对于Owin有没有HttpContext的替代方案? public class WebApiAuthorizeAttribute : AuthorizeAttribute { public override async Task OnAuthorizationAsync(HttpActionContext actionContext, CancellationToken cancellationToken) { base.OnAuthorization(actionContext); Guid userId = new Guid(HttpContext.Current.User.Identity.GetUserId()); ApplicationUserManager manager = new ApplicationUserManager(new ApplicationUserStore(new ApplicationDbContext())) { PasswordHasher = new CustomPasswordHasher() }; ApplicationUser user = await manager.FindByIdAsync(userId); actionContext.Request.Properties.Add(“userId”, user.LegacyUserId); } } 注意:我发现这个问题 ,似乎是重复的,但要求为NancyFx项目工作的解决方案,这对我来说无效。

定时器不会打勾

我的代码中有一个Windows.Forms.Timer ,我执行了3次。 但是,计时器根本没有调用tick函数。 private int count = 3; private timer; void Loopy(int times) { count = times; timer = new Timer(); timer.Interval = 1000; timer.Tick += new EventHandler(timer_Tick); timer.Start(); } void timer_Tick(object sender, EventArgs e) { count–; if (count == 0) timer.Stop(); else { // Do something here } } 从代码中的其他位置调用Loopy() 。

如果有的话,使用System.Diagnostics.Stopwatch的资源惩罚是什么?

例如 foo() //Some operation bound by an external resource. db,I/O, whatever. 与 var watch = new Stopwatch(); watch.Start(); foo() var time = watch.ElapsedMilliseconds watch.Stop();

C#:向ASP.NET中的Parallel.ForEach()添加上下文

我有一个带静态get属性的静态类,在这个属性中,我这样做: // property body { // HttpContext.Current is NOT null … Parallel.ForEach(files, file => { // HttpContext.Current is null var promo = new Promotion(); … }); … // HttpContext.Current is NOT null } 在视图使用此属性之前,此静态类不会进行类型初始化。 问题是,在Parallel.ForEach()创建new Promotion()时初始化的Promotion的静态构造函数使用HttpContext.Current 。 当promo在此Parallel.ForEach()的范围内实例化时, HttpContext.Current为null ,因此new Promotion()会导致exception。 HttpContext.Current在静态get属性中不为null,因为在视图使用它之前不会调用它(因此它有一个HttpContext.Current )。 如果Promotion在其实例中使用HttpContext.Current而不是静态成员,我可能只是将HttpContext.Current传递给new Promotion()构造函数: var context = HttpContext.Current; Parallel.ForEach(files, file => { var promo […]

VS2008 – 为调试/发布配置输出不同的文件名

使用Visual Studio 2008构建C#应用程序时,是否可以为每个配置设置不同的输出文件名? eg MyApp_Debug.exe MyApp_Release.exe 我尝试了一个后期构建步骤,通过附加当前配置来重命名该文件,但这似乎是一种糟糕的方法。 另外,这意味着当按F5开始调试时,Visual Studio无法再找到该文件。