草庐IT

error_stream

全部标签

c# - 为什么这不触发 "Ambiguous Reference Error"?

publicclassA{publicvirtualstringGo(stringstr){returnstr;}}publicclassB:A{publicoverridestringGo(stringstr){returnbase.Go(str);}publicstringGo(IListlist){return"list";}}publicstaticvoidMain(string[]args){varob=newB();Console.WriteLine(ob.Go(null));}http://dotnetpad.net/ViewPaste/s6VZDImprk2_CqulF

c# - 如何修复 'compiler error - cannot convert from method group to System.Delegate' ?

publicMainWindow(){CommandManager.AddExecutedHandler(this,ExecuteHandler);}voidExecuteHandler(objectsender,ExecutedRoutedEventArgse){}错误1​​参数2:无法从“方法组”转换为“System.Delegate” 最佳答案 我猜有多个具有不同签名的ExecuteHandler。只需将您的处理程序转换为您想要的版本:CommandManager.AddExecuteHandler(this,(Action)

c# - 将 Stream 转换为 IEnumerable。如果可能当 "keeping laziness"

我收到一个Stream并需要将IEnumerable传递给另一个方法。publicstaticvoidstreamPairSwitchCipher(StreamsomeStream){...someStreamAsIEnumerable=...IEnumerablereturned=anotherMethodWhichWantsAnIEnumerable(someStreamAsIEnumerable);...}一种方法是读取整个Stream,将其转换为字节数组并将其传入,因为Array实现了IEnumerable。但如果我能以这样一种方式传递它,在传递它之前我不必阅读整个Stream

c# - 如何从字符串对象中获取 System.IO.Stream

我有字符串对象。我需要将此数据传递给XYZ类型的另一个对象。但是这个XYZ类型的对象只采用System.IO.Stream。那么如何将字符串数据转换成流,让XYZ类型的对象可以使用这个字符串数据呢? 最佳答案 您必须选择一种文本编码来将字符串转换为字节数组,然后使用MemoryStream调用您的函数。例如:using(System.IO.MemoryStreamms=newSystem.IO.MemoryStream(System.Text.Encoding.UTF16.GetBytes(yourString))){XYZ(ms)

c# - .mdf"failed with the operating system error 2(系统找不到指定的文件。)

protectedvoidregister_Click(objectsender,EventArgse){AddUser(userName.Text,password.Text,confirm.Text);}voidAddUser(stringname,stringpass,stringconfirm){Useru=newUser(name,pass,confirm);if(u.Valid){using(vardb=newSiteContext()){db.User.Add(u);db.SaveChanges();}}}}publicclassUser{publicintUserId{

c# - 我想念 C# 中 Visual Basic 的 "On Error Resume Next"。我现在应该如何处理错误?

在VisualBasic中,我只在程序头部编写了OnErrorResumeNext,整个项目中的错误都被抑制了。在C#中,我非常怀念这个特性。对每个过程的常用try-catch处理不仅非常耗时,而且会带来不良影响。如果遇到错误,即使已处理,代码也不会从错误发生的地方继续。使用OnErrorResumeNext,代码从错误点继续,仅跳过导致错误的函数调用。我还没有深入了解C#,但也许C#中存在比原始try-catch更好的错误处理。我还想知道发生错误的模块或函数名称以及错误消息中的行号。据我所知,Exception类不提供该功能。任何想法(管理,当然,不涉及我自己的应用程序中的任何流程类

c# - 如何找到asp :Login LoginError error type

当asp:Login控件的LoginError事件触发时,我如何找到错误发生的原因?是否有类似e.ErrorType的属性告诉我登录失败的原因?或者我是否必须像本教程中那样手动检查所有内容:http://www.asp.net/security/tutorials/validating-user-credentials-against-the-membership-user-store-cs或http://www.aspnettutorials.com/tutorials/controls/howto-errors-login-asp4-csharp.aspx

c# - 使用 HttpRequestMessage 或 Stream 上传 REST 文件?

为REST客户端上传文件的更好方法是什么?来自WCFWebAPI文档[WebInvoke(UriTemplate="thumbnail",Method="POST")]publicHttpResponseMessageUploadFile(HttpRequestMessagerequest){来自多个论坛帖子:WCFRESTFileuploadwithadditionalparameters[WebGet(UriTemplate="",Method="POST"]publicstringUploadFile(StreamfileContents)我知道,第一种方法允许直接从普通的HTM

c# - 如果打开自定义错误,是否不会触发 global.asax Application_Error 事件?

如果您在Web配置中将自定义错误设置为RemoteOnly-这是否意味着global.asax中的MVC应用程序级错误事件-Application_Error不会因错误而触发?我刚刚注意到,当我的应用程序出现某个错误时,我正在远程查看该站点,但没有记录任何错误。但是,当我访问服务器上的应用程序并发生相同的错误时,会记录错误。这是自定义错误配置设置:编辑只是出于人们的兴趣——我最终完全关闭了自定义错误并在Application_Error中处理重定向,如下所示:protectedvoidApplication_Error(objectsender,EventArgse){Exceptio

c# - 具有 Stream 类型成员的对象的 JSON.NET 序列化?

希望这是一个我忽略的简单修复。我有一个对象传递到事件处理程序中,我想使用JSON.NET序列化该对象,如下所示:publicvoidOnEvent(IEventObjectfoo){//Serializefootostring/diskhere?vardata=JsonConvert.SerializeObject(foo,Formatting.Indented);}foo的一个或多个成员似乎是流。我已经认识到Streams不可序列化,因为它们是对数据而非数据本身的抽象。这是有道理的。我不知道如何序列化这个对象:a)将流转换成数据并序列化b)忽略流并序列化其余成员一个重要的警告是我无权