Tag: 运行时错误

System.Security.SecurityException:请求类型为’System.Security.Permissions.EnvironmentPermission,mscorlib’的权限失败

当我尝试运行“已发布”的本地网站时,我收到以下错误。 Server Error in ‘/’ Application. ——————————————————————————– Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application’s trust level in the configuration file. Exception Details: System.Security.SecurityException: Request for the permission of type ‘System.Security.Permissions.EnvironmentPermission, […]

什么“方法…… ClassInitialize有错误的签名……”是什么意思?

在我的Visual Studio 2012解决方案中,我有一个用于unit testingC ++ / CLI代码的C#项目,例如 … using System.IO; using Stuff; namespace MyCLIClassTest { [TestClass] public class MyCLIClassTest { public MyCLIClassTest() {} [ClassInitialize] public static void Setup(TestContext testContext) { } [TestMethod] public void LibraryAccessTest() { … } } } 现在,C#测试都失败了,消息如“方法MyCLIClassTest.MyCLIClassTest.ClassInitialize有错误的签名。该方法必须是静态的,公共的,不返回值,并且应该采用TestContext类型的单个参数。” 删除ClassInitializer后,我得到“无法为类MyCLIClassTest.MyCLIClassTest设置TestContext属性。错误:System.ArgumentException:类型为’Microsoft.VisualStudio.TestPlatform.MSTestFramework.TestContextImplementation’的对象无法转换为类型’Microsoft.VisualStudio.TestTools .UnitTesting.TestContext” ..

单个方法即扩展方法之间的调用是模糊的

我有一个类似的扩展方法 public static class Extension { public static string GetTLD(this string str) { var host = new System.Uri(str).Host; int index = host.LastIndexOf(‘.’), last = 3; while (index >= last – 3) { last = index; index = host.LastIndexOf(‘.’, last – 1); } var domain = host.Substring(index + 1); return domain; } } 我称之为 string domain […]

捕获完全意外的错误

我有一个ErrorRecorder应用程序,它打印出错误报告,并询问用户是否要将该报告发送给我。 然后,我有主应用程序。 如果发生错误,它会将错误报告写入文件,并要求ErrorRecorder打开该文件以向用户显示错误报告。 所以我使用Try / Catch捕获了大部分错误。 但是,如果发生完全意外的错误并关闭我的程序,该怎么办? 有没有像全局/覆盖方法或类似的东西,它告诉程序“在关闭之前,如果发生意外错误,请调用”ErrorRecorderView()“方法”

程序随机获取System.AccessViolationException

好的,所以我在调试时遇到了很多问题。 我正在使用VS2013 Pro和Windows 8.1。 两者都是最新的。 问题是,当我开始调试时,它会抛出此错误的一半时间: System.Windows.Forms.dll中发生了未处理的“System.AccessViolationException”类型exception 附加信息:尝试读取或写入受保护的内存。 这通常表明其他内存已损坏。 它也不是我的代码的错。 我做了一个简单的测试作为例子如下。 请注意,我没有从此应用程序引用System.Windows.Forms。 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { List testing = new List(); for(int i =0; i < 50; i++) { testing.Add(i); } for (int i = 0; i < 50; i++) […]

C#编译错误:“在创建窗口句柄之前,无法在控件上调用Invoke或BeginInvoke。”

我刚刚发布了一个关于如何让代理人在另一个表单上更新文本框的问题。 正当我以为我有使用Invoke的答案时…这种情况发生了。 这是我的代码: 主要表格代码: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; using System.Data.OleDb; using System.Collections.Specialized; using System.Text; using System.Threading; delegate void logAdd(string message); namespace LCR_ShepherdStaffupdater_1._0 { public partial class Main : Form { public Main() { InitializeComponent(); } public void add(string message) { this.Log.Items.Add(message); } public void logAdd(string […]