草庐IT

exception_class

全部标签

c# - 公共(public)静态字符串 MyFunc() 上的 "Expected class, delegate, enum, interface or struct"错误。什么 's an alternative to "字符串”?

当我尝试使用以下静态函数时出现错误。错误:Expectedclass,delegate,enum,interface,orstruct函数(和类):namespaceMyNamespace{publicclassMyClass{//SomeotherstaticmethodsthatuseClasses,delegates,enums,interfaces,orstructspublicstaticstringMyFunc(stringmyVar){stringmyText=myVar;//DosomestuffwithmyTextandmyVarreturnmyText;}}}这导致

c# - OOPS 概念 : What is the difference in passing object reference to interface and creating class object in C#?

我有一个类CustomerNew和一个接口(interface)ICustomer:publicclassCustomerNew:ICustomer{publicvoidA(){MessageBox.Show("Classmethod");}voidICustomer.A(){MessageBox.Show("Interfacemethod");}publicvoidB(){MessageBox.Show("ClassMethod");}}publicinterfaceICustomer{voidA();}我对这两行代码很困惑。ICustomerobjnew=newCustomerNe

c# - System.Drawing Out of Memory Exception on Main() 方法 - C#

我的程序是一个CRM,我使用了RadRibbonBar、许多带图像的按钮、RadGridView(其中一些列包含图像)和许多其他包含图像的控件。这是一个mdi父/子程序。在许多情况下,当加载一个mdi子项或使用一些GridView时,程序会挂起并给我这个错误:OutOfMemoryExceptionoccurredinSystem.Drawing.dll我在某些部分尝试了GC.Collect()但没有成功。对于设置图像,没有代码!例如,为按钮设置图像我在visualstudio中使用了它的属性。我在可视模式下使用属性面板以这种方式设置了所有其他控件图像。这些是一些与绘图相关的设计器代码

c# - 系统.ComponentModel.Win32Exception : Access is denied Error

我正在使用C#代码启动和停止窗口服务,但出现此错误。System.ComponentModel.Win32Exception:Accessisdenied我的代码:publicvoidStartService(stringserviceName,inttimeoutMilliseconds){ServiceControllerservice=newServiceController(serviceName);try{TimeSpantimeout=TimeSpan.FromMilliseconds(timeoutMilliseconds);service.Start();service

c# - ASP.net Web API : change class name when serializing

我有一个产品的数据传输对象类publicclassProductDTO{publicGuidId{get;set;}publicstringName{get;set;}//Otherproperties}当Asp.net序列化JSON(使用JSON.NET)或XML中的对象时,它会生成ProductDTO对象。但是,我想在序列化期间更改名称,从ProductDTO到Product,使用某种属性:[Name("Product")]publicclassProductDTO{[Name("ProductId")]publicGuidId{get;set;}publicstringName{

c# - 低级差异 : non-static class with static method vs. 静态类与静态方法

我想知道使用具有静态方法的非静态类与具有相同静态方法的静态类的一般好处(或缺点)是什么,除了我不能使用非静态类中的静态方法作为扩展方法。例如:classNonStaticClass{publicstaticstringGetData(){return"Thiswasinvokedfromanon-staticclass.";}}与此相比:staticclassStaticClass{publicstaticstringGetData(){return"Thiswasinvokedfromastaticclass.";}}使用一种方法优于另一种方法对性能/内存有何影响?注意:假设我不需要

c# - Win32Exception: 目录名无效

我正在尝试以不同的用户身份运行一个进程,该用户在2台运行Vista且启用了UAC的不同计算机中具有管理员权限,但在其中一台计算机中我收到Win32Exception,提示“目录名称无效”谁能告诉我我的代码有什么问题?varmyFile="D:\\SomeFolder\\MyExecutable.exe";varworkingFolder="D:\\SomeFolder";varpInfo=newSystem.Diagnostics.ProcessStartInfo();pInfo.FileName=myFile;pInfo.WorkingDirectory=workingFolder;

c# - 使用 Assembly.GetType ("MyCompany.Class1.Class2") 返回 null

我正在尝试使用Assembly.GetType("MyCompany.Class1.Class2")从字符串中动态获取类型。Assembly.GetType("MyCompany.Class1");按预期工作。如果我将一个类嵌入到另一个类中,例如:namespaceMyCompany{publicclassClass1{//.....publicclassClass2{//.....}}}并尝试获取类型Class2Assembly.GetType("MyCompany.Class1.Class2")将返回一个空值。我正在使用.NETFrameworks3.5SP1有谁知道我做错了什么以

c# - 这是捕获非特定异常(例如 System.Exception)的坏习惯吗?为什么?

我目前正在进行代码审查,下面的代码让我大吃一惊。我看到此代码存在多个问题。你是否同意我的观点?如果是这样,我该如何向我的同事解释这是错误的(顽固型...)?捕获一般异常(Exceptionex)使用“if(exissomething)”而不是另一个catchblock我们吃SoapException、HttpException和WebException。但是,如果Web服务失败,则没有什么可做的。代码:try{//CalltoaWebService}catch(Exceptionex){if(exisSoapException||exisHttpException||exisWebEx

c# - 如何解决 Exception :Call was rejected by callee. (Exception from HRESULT : 0x80010001 (RPC_E_CALL_REJECTED)) in C#?

我在控制台应用程序中编写了一个C#代码来打开两个excel并将数据从一个excel复制并粘贴到另一个excel。在目标excel的可见性为真之前,它工作正常。但是我需要在执行时隐藏excel。所以我将可见性更改为false。喜欢,_destExcelApp=newExcel.ApplicationClass();_destExcelApp.Visible=false;现在它显示了一个异常Callwasrejectedbycallee.(ExceptionfromHRESULT:0x80010001(RPC_E_CALL_REJECTED))如何解决这个问题?