我正在使用VS 2008,.Net 3.5和C#开发Web应用程序.解决方案中的大多数项目都是经典的asp.net页面,其中包含一些MVC 1,其余的是共享库.解决方案是一个大约5年的解决方案,并经历了各种开发人员的工作,显然有一些性能和架构问题.
以前,我一直在Win XP机器上使用VS 2008进行该项目,但刚刚使用Win 7 Ultimate转换到新的盒子.为此,我安装了VS 2008,asp.net 3.5.为了支持解决方案的未来工作,我还安装了VS 2010和asp.net 4.0.
使用VS 2008打开新盒子上的解决方案工作正常,并且构建没有错误.但是,当我尝试使用调试器运行它时,我收到以下消息:
"web.config中有一个错误.请在继续之前纠正.(您可以重命名当前的web.config并添加一个新的.)"
我认为新机器上的web.config存在某种环境问题,但错误信息并非"有用".添加新的web.config不是一个选项,因为现有的web.config很长并且涉及(太多而无法在此处发布).
我希望有人有一个或两个关于我可能会寻找缺少元素或更改可能产生此类错误消息的配置的建议.缺乏这一点,我将重新审视这篇文章并提供web.config,希望能引起进一步的帮助.
c# asp.net web-config visual-studio-2008-sp1 visual-studio-debugging
我仍然是超载运营商的新手.在我遇到这个问题之前,我以为自己做得很好.在!=运算符上抛出NullReferenceException.我假设它在CompareTo方法中使用它,但我不完全确定.如果有人能指出我正确的方向,我将非常感激.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
List<Task> tasks = new List<Task>();
tasks.Add(new Task( "first", DateTime.Now.AddHours(2)));
tasks.Add(new Task( "second", DateTime.Now.AddHours(4)));
tasks.TrimExcess();
tasks.Sort();
}
}
public class Task : IComparable
{
public Task()
{
}
public Task(string nameIn, DateTime dueIn)
{
nameOfTask = nameIn;
dateDue = dueIn;
}
DateTime dateDue;
string nameOfTask;
public static bool operator <(Task …Run Code Online (Sandbox Code Playgroud) 我试图了解如何在 ASP.NET Core 6 Web API 控制器上进行集成测试。我尝试遵循我能找到的所有指南、帖子和建议,但由于某种原因,我不断遇到指南中未提及的错误。
\n事件控制器测试.cs
\nnamespace UnitTests.ProjectToBeTested.Controllers\n{\n public class EventControllerTests\n {\n [Fact]\n public async Task EventController_Post_RespondsOkIfRequestContainsCorrectFeilds_SuccessAsync()\n {\n\n // Arrange\n var application = new WebApplicationFactory<Program>();\n\n var client = application.CreateClient();\n ...\nRun Code Online (Sandbox Code Playgroud)\n待测试项目.csproj
\n...\n <ItemGroup>\n <InternalsVisibleTo Include="IntegrationTests" />\n </ItemGroup>\n...\nRun Code Online (Sandbox Code Playgroud)\n运行测试时会抛出以下错误:
\n\n消息:\xe2\x80\x89 System.InvalidOperationException:在\n\ 上找不到方法“public static\nIHostBuilder CreateHostBuilder(string[] args)\”或“public static\nIWebHostBuilder CreateWebHostBuilder(string[] args)\” '程序\'。或者,可以扩展 WebApplicationFactory`1,并可以重写\n\n\'CreateHostBuilder\' 或 \'CreateWebHostBuilder\' 以提供你自己的实例。
\n堆栈跟踪:\xe2\x80\x89 WebApplicationFactory
1.CreateWebHostBuilder() WebApplicationFactory1.EnsureServer()\nWebApplicationFactory1.CreateDefaultClient(DelegatingHandler[] handlers) WebApplicationFactory1.CreateDefaultClient(Uri baseAddress,\nDelegatingHandler[] 处理程序)\nWebApplicationFactory1.CreateClient(WebApplicationFactoryClientOptions options) WebApplicationFactory1.CreateClient()\nEventControllerTests.EventController_Post_RespondsOkIfRequestContainsCorrectFeilds_SuccessAsync()\xe2\x80\x89线\ xe2\x80\x8917\n--- …
在我的情况下,SaveFileDialog不会写任何文件,但我想用来指定命令行应用程序的路径,该应用程序将在与sf对话框中的"已保存"相同的位置创建日志文件.
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "*.txt";
string sfdname = saveFileDialog1.FileName;
if (sfd.ShowDialog() == DialogResult.OK)
{
Path.GetFileName(sfd.FileName);
}
startInfo.Arguments = "--log=" + Path.GetFileName(sfd.FileName);
Run Code Online (Sandbox Code Playgroud) 嗨,我必须设计一个具有简单文本框的Windows窗体.文本框包含类似文本的计时器(00:00格式).
我想每秒刷新页面,并使文本框的内容相应更改.(就像数字时钟一样,运行一小时!).
我想我需要使用System.Windows.Forms.Timer该类,我已经Timer从ToolBox中删除了一个项目到我的表单.
下一步......我需要使用Thread.Sleep(1000)功能......任何想法?
这是我一直在尝试的代码片段.我知道程序中出错了,这thread.sleep()部分甚至会让我的代码运行更糟.我在ToolBox中尝试了Timer的东西,但无法通过.(当我运行代码时,它成功编译,然后应用程序由于脏For-Loops冻结一小时)帮助!
public partial class Form1 : Form
{
Button b = new Button();
TextBox tb = new TextBox();
//System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
public Form1()
{
b.Click += new EventHandler(b_click);
b.Text = "START";
tb.Text = "00 : 00";
//timer1.Enabled = true;
//timer1.Interval = 1000;
tb.Location = new Point(100, 100);
this.Controls.Add(tb);
this.Controls.Add(b);
InitializeComponent();
}
private void refreshTimer_Tick()
{
for (int i = 0; i < 60; i++)
{
for …Run Code Online (Sandbox Code Playgroud) 尝试将String绑定到RichTextBox.Text属性,以便在String值更改时,该更改将反映在RichTextBox中.到目前为止,我没有成功.
string test = "Test";
rtxt_chatLog.DataBindings.Add("Text",test,null);
test = "a";
Run Code Online (Sandbox Code Playgroud)
这在rtxt_chatLog中显示"Test",但不显示"a".
甚至尝试添加rtxt_chatLog.Refresh(); 但这没有任何区别.
更新1:这也不起作用:
public class Test
{
public string Property { get; set; }
}
Test t = new Test();
t.Property = "test";
rtxt_chatLog.DataBindings.Add("Text", t, "Property");
t.Property = "a";
Run Code Online (Sandbox Code Playgroud)
我不正确理解数据绑定吗?
我试图用文本框中的文本过滤一个列表框,realTime.
这是代码:
private void SrchBox_TextChanged_1(object sender, EventArgs e)
{
var registrationsList = registrationListBox.Items.Cast<String>().ToList();
registrationListBox.BeginUpdate();
registrationListBox.Items.Clear();
foreach (string str in registrationsList)
{
if (str.Contains(SrchBox.Text))
{
registrationListBox.Items.Add(str);
}
}
registrationListBox.EndUpdate();
}
Run Code Online (Sandbox Code Playgroud)
以下是问题:
当我运行该程序时,我收到此错误: Object reference not set to an instance of an object
如果我点击退格键,我的初始列表将不再显示.这是因为我的实际物品清单现在减少了,但我怎样才能做到这一点?
你能为我指出正确的方向吗?
int n = 5;
int quorum = Math.Floor(n / 2) + 1;
Run Code Online (Sandbox Code Playgroud)
我期望法定人数具有值3.但这是我在VisualStudio中得到的错误:
以下方法或属性之间的调用不明确:'System.Math.Floor(double)'和'System.Math.Floor(decimal)'
我该如何纠正?我哪里做错了?
我在ContextMenuStrip中有"添加","删除"和"更新"等选项,当用户右键单击ListView时会弹出这些选项.
如果列表视图中没有项目,如何禁用"更新"菜单?
我有一个绑定到数据源的ComboBox但它不会更新绑定,直到控件失去焦点.如何在所选项目更改时获取更新绑定?在下面的屏幕截图中,我希望标签立即更新以反映新的选择.

一些代码:
public enum MyEnum
{
First,
Second
}
public class MyData
{
public String Name { get; set; }
public MyEnum MyEnum { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
样品表格:
public SampleForm()
{
InitializeComponent ();
MyData data = new MyData () { Name = "Single Item" };
this.bindingSource1.DataSource = data;
this.comboBox1.DataSource = Enum.GetValues (typeof (MyEnum));
this.label2.DataBindings.Add ("Text", this.bindingSource1, "MyEnum", true, DataSourceUpdateMode.OnPropertyChanged);
this.comboBox1.DataBindings.Add (new System.Windows.Forms.Binding ("SelectedItem", this.bindingSource1, "MyEnum", true));
this.comboBox1.DataBindings.Add (new System.Windows.Forms.Binding ("SelectedValue", this.bindingSource1, "MyEnum", true));
}
Run Code Online (Sandbox Code Playgroud) c# ×10
winforms ×6
data-binding ×2
.net ×1
.net-6.0 ×1
asp.net ×1
asp.net-core ×1
binary ×1
list ×1
listbox ×1
overloading ×1
richtextbox ×1
string ×1
textbox ×1
timer ×1
web-config ×1
xunit ×1