草庐IT

c# - 系统参数异常 : Complex DataBinding accepts as a data source either an IList or an IListSource

我正在使用下面的C#代码来填充WinFormsListBox。但是我想隐藏所有系统文件夹。例如$RecyclingBin。但它给了我以下错误。System.ArgumentException:ComplexDataBindingacceptsasadatasourceeitheranIListoranIListSource.作为LINQ的新手,这让我很困惑。谁能告诉我哪里出错了?string[]dirs=Directory.GetDirectories(@"c:\");vardir=fromdindirswhere!d.StartsWith("$")selectd;listBox.Da

c# - Visual Studio 2017 : "Object reference not set to an instance of an object" while loading the project

我在VS解决方案中有一个项目可以在VS2015中正确加载,但它似乎在VS2017(RC2)中已损坏。在解决方案资源管理器中,它显示其“加载失败”,当我尝试重新加载它时,我收到一个错误弹出窗口,消息为“对象引用未设置为对象的实例”。我认为这可能是因为VS2017以某种方式更改了.csproj文件以满足他们的需要,但是在将它与VS2015解决方案中的版本进行比较后我发现它们并没有什么不同。有人遇到过这样的事情吗?以及如何修复它?谢谢。 最佳答案 对于VisualStudio2017的我来说,这些建议都没有奏效。有效的方法是关闭所有Vis

c# - 为什么这个程序会出错? `Object synchronization method was called from an unsynchronized block of code`

这段代码有什么问题?我收到“从未同步的代码块调用对象同步方法”。我在谷歌上发现了一个结果,说我可能在锁定之前释放了一个互斥体,但根据我的输出,情况并非如此。这是互斥锁代码,中间没有其他代码。-edit-对不起大家,贴错了。我的输出1W1W2W代码usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Threading;namespacesqliteTest{classProgram{staticvolatileMutexmut1=newMutex();staticvolatileMutexmut

c# - 尝试读取 xml 文件时的 ASP.Net, "An operation was attempted on a nonexistent network connection"

stringurl="http://www.example.com/feed.xml";varsettings=newXmlReaderSettings();settings.IgnoreComments=true;settings.IgnoreProcessingInstructions=true;settings.IgnoreWhitespace=true;settings.XmlResolver=null;settings.DtdProcessing=DtdProcessing.Parse;settings.CheckCharacters=false;varrequest=(Ht

c# - 内存溢出 : Having an increasing number of Microsoft. CSharp.RuntimeBinder.Semantics

我们目前正在我们的应用程序中寻找一些内存泄漏,当执行一些操作(在我们的应用程序中加载和关闭一个项目)时,我们知道内存总是增加一点点。我们已经找到了很多,但现在,增加最多的10个类是(根据我们的工具ANTSMemoryProfiler8.2):Microsoft.CSharp.RuntimeBinder.Semantics.SYMTBL+KeyMicrosoft.CSharp.RuntimeBinder.Semantics.LocalVariableSymbolMicrosoft.CSharp.RuntimeBinder.Semantics.CONSTVALMicrosoft.CShar

c# - 犀牛模拟 : How to stub a generic method to catch an anonymous type?

我们需要stub一个通用方法,该方法将使用匿名类型作为类型参数来调用。考虑:interfaceIProgressReporter{TReport(TprogressUpdater);}//Unittestarrange:FuncreturnArg=(x=>x);//wewishtoreturntheargument_reporter.Stub(x=>x.Report(null).IgnoreArguments().Do(returnArg);如果在被测方法中对.Report()的实际调用是使用对象作为类型参数完成的,那么这将起作用,但实际上,调用该方法时使用的T是匿名类型。此类型在被测

c# - 错误 : ExecuteReader requires an open and available Connection. 连接的当前状态为打开

我有下面带有DataHelperClass的mvc4网站来执行查询。我的问题有时是,网站以异常为标题。我使用block来处理SqlCommand和SqlDataAdapter但没有成功。请帮助我,对不起我的英语。try{if(_conn.State==ConnectionState.Closed)_conn.Open();using(SqlCommandsqlCommand=newSqlCommand(query,_conn)){sqlCommand.CommandType=CommandType.StoredProcedure;if(parameters!=null)sqlComma

c# - LINQ 到 XML : applying an XPath

有人能告诉我为什么这个程序不枚举任何项目吗?它与RDFnamespace有关吗?usingSystem;usingSystem.Xml.Linq;usingSystem.Xml.XPath;classProgram{staticvoidMain(string[]args){vardoc=XDocument.Load("http://seattle.craigslist.org/sof/index.rss");foreach(varitemindoc.XPathSelectElements("//item")){Console.WriteLine(item.Element("link")

c# - Entity Framework : Check all relationships of an entity for foreign key use

我有一个实体,我们称它为CommonEntity,它有一个在许多其他实体中用作外键的主键。随着应用程序的开发,这些链接将继续增长。我想要一种方法来查看CommonEntity是否可以安全删除(即它未被任何其他实体使用)。我知道我能做到if(!ce.EntityA.Any()&&!ce.EntityB.Any()...&&!ce.EntityN.Any()){//Delete}但我希望有一种方法可以自动检查所有关系,因为我不喜欢每次添加新关系时都必须返回并手动更改此代码的想法。也许EF4+中有一些我不知道的东西?我认为可以使用事务范围来尝试删除对象并在失败时将其回滚,但我不确定这种方法是

c# - ExecuteScalar 调用抛出异常 "Object reference not set to an instance of an object"

在单元测试中调试以下方法时出现以下错误Objectreferencenotsettoaninstanceofanobject点击以下行时result=(int)validateDatabase.ExecuteScalar();方法是publicstaticBooleanValidate(stringargument1,stringargument2){intresult=-1;using(varconnection=newSqlConnection("connectionstring")){SqlCommandvalidateDatabase=newSqlCommand("PROCED