小编Lar*_*ech的帖子

VS 2008中未定义的Web.config错误

我正在使用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

7
推荐指数
2
解决办法
4071
查看次数

如何正确地覆盖平等?

我仍然是超载运营商的新手.在我遇到这个问题之前,我以为自己做得很好.在!=运算符上抛出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)

c# binary overloading operator-keyword

7
推荐指数
1
解决办法
516
查看次数

ASP.NET Core 6 Web API 的集成测试抛出 System.InvalidOperationException

我试图了解如何在 ASP.NET Core 6 Web API 控制器上进行集成测试。我尝试遵循我能找到的所有指南、帖子和建议,但由于某种原因,我不断遇到指南中未提及的错误。

\n

事件控制器测试.cs

\n
namespace 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            ...\n
Run Code Online (Sandbox Code Playgroud)\n

待测试项目.csproj

\n
...\n    <ItemGroup>\n        <InternalsVisibleTo Include="IntegrationTests" />\n    </ItemGroup>\n...\n
Run 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()\nWebApplicationFactory 1.CreateDefaultClient(DelegatingHandler[] handlers) WebApplicationFactory1.CreateDefaultClient(Uri baseAddress,\nDelegatingHandler[] 处理程序)\nWebApplicationFactory 1.CreateClient(WebApplicationFactoryClientOptions options) WebApplicationFactory1.CreateClient()\nEventControllerTests.EventController_Post_RespondsOkIfRequestContainsCorrectFeilds_SuccessAsync()\xe2\x80\x89线\ xe2\x80\x8917\n--- …

c# xunit asp.net-core .net-6.0

7
推荐指数
1
解决办法
6728
查看次数

如何从savefiledialog获取完整路径并在"startInfo.Arguments"中使用?

在我的情况下,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)

c# winforms

6
推荐指数
2
解决办法
4万
查看次数

在WinForm上运行数字时钟

嗨,我必须设计一个具有简单文本框的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)

c# timer winforms

6
推荐指数
1
解决办法
3万
查看次数

将RichTextBox.Text数据绑定到String

尝试将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)

我不正确理解数据绑定吗?

c# string data-binding richtextbox winforms

6
推荐指数
1
解决办法
5233
查看次数

使用TextBox实时过滤ListBox

我试图用文本框中的文本过滤一个列表框,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)

以下是问题:

  1. 当我运行该程序时,我收到此错误: Object reference not set to an instance of an object

  2. 如果我点击退格键,我的初始列表将不再显示.这是因为我的实际物品清单现在减少了,但我怎样才能做到这一点?

你能为我指出正确的方向吗?

c# textbox listbox list winforms

6
推荐指数
1
解决办法
3万
查看次数

C#.NET中方法或属性之间的不一致

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)'

我该如何纠正?我哪里做错了?

c#

6
推荐指数
1
解决办法
1万
查看次数

如何禁用ContextMenuStrip中的菜单项?

我在ContextMenuStrip中有"添加","删除"和"更新"等选项,当用户右键单击ListView时会弹出这些选项.

如果列表视图中没有项目,如何禁用"更新"菜单?

.net c# contextmenustrip winforms

6
推荐指数
2
解决办法
4499
查看次数

ComboBox没有更新所选项目上的DataBindings更改(WinForms)

我有一个绑定到数据源的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# data-binding winforms

6
推荐指数
2
解决办法
2万
查看次数