小编adr*_*nks的帖子

访问settings.settings时"配置系统无法初始化"

自从删除原始settings.settings文件以来,我遇到了无穷无尽的问题,让设置正常运行.我收到get或set方法的"配置系统初始化失败"错误.有任何想法吗?谢谢.

    public static Settings Default {
        get {
            return defaultInstance;
        }
    }

    [global::System.Configuration.UserScopedSettingAttribute()]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Configuration.DefaultSettingValueAttribute("Keywords.log")]
    public string KeywordsLog {
        get {
            return ((string)(this["KeywordsLog"]));
        }
        set {
            this["KeywordsLog"] = value;
        }
    }
Run Code Online (Sandbox Code Playgroud)

问题位于Settings.Designer.cs中

阿德里安班克斯,我怕我不知道如何进一步调试?它已经打破了错误.给出的框的标题是"ConfigurationErrorsException",如果这有任何帮助.

我道歉,我没有意识到你可以在VS中看到更多细节.

System.Configuration.ConfigurationErrorsException was unhandled
  Message="Configuration system failed to initialize"
  Source="System.Configuration"
  BareMessage="Configuration system failed to initialize"
  Line=0
  StackTrace:
       at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
       at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
       at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.RefreshConfig(String sectionName)
       at System.Configuration.ConfigurationManager.RefreshSection(String sectionName)
       at System.Configuration.ClientSettingsStore.ReadSettings(String sectionName, Boolean isUserScoped)
       at System.Configuration.LocalFileSettingsProvider.GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
       at System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider provider)
       at System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName)
       at System.Configuration.SettingsBase.get_Item(String …
Run Code Online (Sandbox Code Playgroud)

c# settings visual-studio-2008

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

跨线程操作无效

调试时我一直收到以下错误.

Cross-thread operation not valid: Control 'richTextBoxReceivedMsg' accessed from a thread other than the thread it was created on.
Run Code Online (Sandbox Code Playgroud)

这是它指向的代码:

public void OnDataReceived(IAsyncResult asyn)
{
    try
{
    SocketPacket socketData = (SocketPacket)asyn.AsyncState;

    int iRx  = 0;

        // Complete the BeginReceive() asynchronous call by EndReceive() method
        // which will return the number of characters written to the stream by the client
        iRx = socketData.m_currentSocket.EndReceive (asyn);

        char[] chars = new char[iRx +  1];
        System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
        int charLen = d.GetChars(socketData.dataBuffer, 0, iRx, …
Run Code Online (Sandbox Code Playgroud)

c# sockets multithreading winforms

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

堆栈跟踪的行号不正确

为什么堆栈跟踪显示"第0行",但仅适用于堆栈跟踪中的一个帧

例如.

...
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at My.LibraryA.Some.Method():line 16
at My.LibraryB.Some.OtherMethod():line 0
at My.LibraryB.Some.Method():line 22
at My.LibraryA.Some.Method():line 10
Run Code Online (Sandbox Code Playgroud)

背景:

我有一个失败的应用程序,并且正在将堆栈跟踪记录到其日志文件中.构建应用程序时,所有程序集都使用完整的调试信息进行编译(项目属性 - >构建 - >高级 - >调试信息 - >完整),因此生成了PDB文件.为了帮助我诊断出错误的来源,我将PDB文件放入应用程序的bin目录中,并重现了异常.每个堆栈帧的所有行号看起来都是正确的,但显示"第0行"作为其来源的行号除外.

.net c# stack-trace line-numbers

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

How to capture part of a screen

I am using the win32 PrintWindow function to capture a screen to a BitMap object.

If I only want to capture a region of the window, how can I crop the image in memory?

Here is the code I'm using to capture the entire window:

[System.Runtime.InteropServices.DllImport(strUSER32DLL, CharSet = CharSet.Auto, SetLastError = true)]
public static extern int PrintWindow(IntPtr hWnd, IntPtr hBltDC, uint iFlags);

public enum enPrintWindowFlags : uint
{
    /// <summary>
    /// 
    /// </summary>
    PW_ALL = 0x00000000,
    /// <summary>
    /// Only …
Run Code Online (Sandbox Code Playgroud)

c# winapi screen-scraping screen-capture

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

IPrincipal.IsInRole()仅在我截断角色名称时起作用 - 为什么?

我的应用程序很大程度上依赖于用户的授权.在其中,我IPrincipal.IsInRole()用来检查用户是否在正确的组中:

IPrincipal principal = Thread.CurrentPrincipal;
bool inRole = principal.IsInRole("mydomainname\some role with a long name");
Run Code Online (Sandbox Code Playgroud)

这在大多数情况下都可以正常工作,但如果主体是a的实例,则会失败(返回错误的结果)WindowsPrincipal.我发现为了使它正常工作,我必须截断我传入的角色的名称,长度为32个字符(包括域名和\):

IPrincipal principal = Thread.CurrentPrincipal; // <- returns a WindowsPrincipal
bool inRole = principal.IsInRole("mydomainname\some role with a lo");
Run Code Online (Sandbox Code Playgroud)

截断角色名称然后正常工作.为什么?这是一个错误/功能/记录的问题吗?我有一个暗示,它可能与Win2000域有关,但无法找到任何信息.

一些额外的信息:
这是一个问题,因为应用程序可以配置为使用活动目录或"自定义"进行授权("自定义"是支持接口的任何授权提供程序 - 可以是基于SQL的,基于文件的等等..).配置自定义时,角色很可能不需要截断,因此我不想在我的代码中处理这种特殊情况.此外,我还有另一部分应用程序使用System.DirectoryServices.AccountManagement命名空间中的类来查找组成员身份.这需要完整的角色名称,如果被截断则不起作用.

.net c# security iprincipal active-directory

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

用户'IIS APPPOOL\Classic .NET AppPool'登录失败

我刚刚将我的网站添加到IIS.经过多次故障排除后,我能够使用Classic .NET App Pool运行它.

但是在需要连接数据库的页面上,我收到错误"用户登录失败'IIS APPPOOL\Class .NET AppPool'

请建议一个解决方法.

asp.net iis

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

间距搞砸了

我的间距在这里怎么样?当标签包含文本时,间距很好但是它们是空的,每个标签之间都有空白.为什么标签包含空文本时会添加额外的空格?

标签中的文字(我希望它看起来像):

标签中没有文字(我不希望它看起来像这样):

关于C#代码背后:

        // On page load
        for (int i = 1; i < 10; i++)
        {
            string ID = i.ToString();
            PopulateLastNameLabel(ID);
        }


        protected void PopulateLastNameLabel(string ID)
        {
            Label lbl = new Label();
            lbl.Width = 70;
            lbl.Height = 20;
            lbl.Text = "";
            lbl.BackColor = System.Drawing.Color.Red;
            lbl.ID = "lastname_" + ID;
            pnlLastNameLabel.Controls.Add(lbl);
        }
Run Code Online (Sandbox Code Playgroud)

在ASP.NET方面:

<asp:Table ID="tblDisplayTable" runat="server">
    <asp:TableRow>
    <asp:TableCell>
    <asp:Panel ID="pnlPrizeNumberLabel" runat="server" Width="80px"></asp:Panel>
    </asp:TableCell>
    <asp:TableCell HorizontalAlign="Center" VerticalAlign="Middle">
    <asp:Panel ID="pnlPrizeDropDownList" runat="server" Width="130px"></asp:Panel>
    </asp:TableCell>
    <asp:TableCell>
    <asp:Panel ID="pnlNickNameLabel" runat="server" Width="70px"></asp:Panel>
    </asp:TableCell>
    <asp:TableCell>
    <asp:Panel …
Run Code Online (Sandbox Code Playgroud)

html c# asp.net

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

我应该如何在自定义异常中存储数据?

在处理自定义异常时,我通常从Exception继承,然后将一些字段/属性添加到我的异常类中以存储一些额外的信息:

public class MyException : Exception
{
    public int ErrorCode{get;set;}

    public MyException()
    {}
}
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,该ErrorCode值存储在异常中,这意味着我必须将其添加到并且如果从SerializationInfo受保护的构造函数中的对象和重写的GetObjectData方法中退出.

异常类具有数据属性,它根据MSDN:

获取键/值对的集合,这些键/值对提供有关异常的其他用户定义信息.

如果我将错误代码存储在其中Data,它将由Exception类(根据Reflector)为我序列化,这意味着我的异常类现在看起来像:

public class MyException : Exception
{
    public int ErrorCode
    {
        get {return (int) Data["ErrorCode"];}
        set {Data["ErrorCode"] = value;}
    }

    public MyException()
    {}
}
Run Code Online (Sandbox Code Playgroud)

这意味着虽然在处理错误代码的获取/设置方面还有一些工作要做(比如处理转换错误和错误代码可能不在字典中的情况),但我不必担心关于序列化/反序列化它.

这只是两种不同的方式来实现同样的事情,还是一种方式比另一种方式有明显的优势(除了我已经提到的那些)?

c# exception-handling exception

5
推荐指数
2
解决办法
991
查看次数

为什么我的字体在Visual Studio 2010中模糊?

我最近切换到Visual Studio 2010.我一直使用好的旧像素化字体,因为我发现它更容易阅读(一个像素是黑色,另一个是白色......完美).

在Visual Studio 2005中,我使用的是位图字体.在VS 2010中似乎你必须使用TTF字体,所以我切换到了proggy字体TTF格式.

但现在我的文字很模糊.这是一个截图:

截图

如何禁用此无用功能?我不希望我的代码看起来"漂亮"我只是想用它:)

fonts visual-studio-2010

5
推荐指数
1
解决办法
2634
查看次数

Visual Studio中的程序集缓存问题

我在visual studio中遇到了汇编缓存问题.我想改变强名称程序集的引用.所以我签署了程序集并且它们已经成功签名,但是当我尝试在visual studio中引用它们时,似乎它仍然会缓存旧版本!我找不到删除旧版本的方法,我甚至更改了版本,VS仍然无法检测到新版本.

有任何想法吗?

谢谢

.net c# visual-studio

5
推荐指数
1
解决办法
8484
查看次数