Tag: c#

Visual Studio 2017缺少exe文件

(我使用的是Visual Studio 2017) 我开始了一个小型的控制台应用 一个Discord C#bot。 所以我总是用Visual Studio启动这个程序。 完成后,我想将.exe文件放在服务器上,以保持这个机器人整天保持在线状态。 在目录中,没有.exe文件。 所以我再次启动了应用程序,看到这个控制台是从另一个路径打开的 “C:\ Program Files \ dotnet”,此.exe称为“dotnet.exe” 当我想手动启动这个.exe文件时,它立即关闭(可能是因为缺少代码行Console.ReadLine();我不知道)。 有人能告诉我,在Visual Studios设置中要更改什么,在我的控制台应用程序的正确目录中有一个.exe文件? 附图显示了我的bin目录,通常是.exe文件。 有一个.dll文件,但我需要.exe ..

从EF选择返回元组

如何使用EF4在Select中检索元组? var productCount = (from product in context.products select new Tuple(product, products.Orders.Count)); 要么 var productCount = (from product in context.products select Tuple.Create(product, products.Orders.Count)); entity framework说第一种情况不能使用空构造函数,而第二种情况则不能识别Tuple.Create方法。

尝试通过Office 365发送电子邮件时SMTP 5.7.57错误

我正在尝试设置一些代码以通过Office 365经过身份validation的SMTP服务发送电子邮件: var _mailServer = new SmtpClient(); _mailServer.UseDefaultCredentials = false; _mailServer.Credentials = new NetworkCredential(“test.user@mydomain.com”, “password”); _mailServer.Host = “smtp.office365.com”; _mailServer.TargetName = “STARTTLS/smtp.office365.com”; // same behaviour if this lien is removed _mailServer.Port = 587; _mailServer.EnableSsl = true; var eml = new MailMessage(); eml.Sender = new MailAddress(“test.user@mydomain.com”); eml.From = eml.Sender; eml.to = new MailAddress(“test.recipient@anotherdomain.com”); eml.Subject = “Test message”; […]

WPF RichTextBox语法突出显示问题

大家好我一直在研究一个带有文本编辑器的WPF应用程序这个文本编辑器应该应用一些样式或着色一些标记(关键字)来突出显示它并使其显而易见,,,问题是我非常努力但是我仍然得到相同的结果,即用户在关键字被设置样式后输入整个文本中的一个关键字! 试想一下,如果你在“C#”中键入“string”关键字,它之后的整个文字将会变成蓝色。 这是我使用的代码: static List tags = new List(); static List specials = new List(); static string text; #region ctor static MainWindow() { string[] specialWords = { “string”, “char”, “null” }; tags = new List(specialWords); // We also want to know all possible delimiters so adding this stuff. char[] chrs = { ‘.’, ‘)’, ‘(‘, […]

将JSON对象反序列化为C#列表

我正在尝试使用Bill Reiss的教程在C#中反序列化给定的JSON文件。 对于非列表中的XML数据,此方法非常有效,但我希望使用以下结构反序列化JSON文件: public class Data { public string Att1 { get; set; } public string Att2 { get; set; } public string Att3 { get; set; } public string Att4 { get; set; } } public class RootObject { public List Listname { get; set; } } 我的问题是使用JSON.Net创建/将数据放入列表,然后在XAML页面上显示列表的能力。 到目前为止我的想法(这是行不通的): var resp = await client.DoRequestJsonAsync(“URL”); […]

在一个WCF服务中托管多个合同

是否可以在一个WCF服务中托管多个服务合同? 如果是这样,怎么样? 我一直在谷歌搜索和一些post说你可以做(​​但不是如何)和其他人说,这是不可能的。 当我运行服务器时,我收到此错误: 在服务“ConsoleAppWcfServer.FooService”实现的合同列表中找不到合同名称“ConsoleAppWcfCommon.IBarService”。 这是我的服务器代码: static void Main(string[] args) { string serviceAddress = “net.tcp://localhost:8088/FooBarService”; // I’m stuck here as I have to pick *one* service ServiceHost selfServiceHost = new ServiceHost(typeof(FooService)); // I can add both endpoints here, but this is what gives me the error. selfServiceHost.AddServiceEndpoint(typeof(IFooService), new NetTcpBinding(), serviceAddress); selfServiceHost.AddServiceEndpoint(typeof(IBarService), new NetTcpBinding(), serviceAddress); selfServiceHost.Open(); […]

获得excel应用程序进程ID

我正在用c#创建一个excel应用程序。 由于我将紧急维护excel文件,我想保持其处理程序打开。 我想保留excel进程ID,以便在系统崩溃时能够终止它。 如何在创建Excel时获取Excel Pid?

如何正确地提供PDF文件

我使用的是.NET 3.5 ASP.NET。 目前,我的网站以下列方式提供PDF文件: context.Response.WriteFile(@”c:\blah\blah.pdf”); 这很好用。 但是,我想通过context.Response.Write(char [], int, int)方法来提供它。 所以我尝试通过发送文件 byte [] byteContent = File.ReadAllBytes(ReportPath); ASCIIEncoding encoding = new ASCIIEncoding(); char[] charContent = encoding.GetChars(byteContent); context.Response.Write(charContent, 0, charContent.Length); 这没用(例如浏览器的PDF插件抱怨文件已损坏)。 所以我尝试了Unicode方法: byte [] byteContent = File.ReadAllBytes(ReportPath); UnicodeEncoding encoding = new UnicodeEncoding(); char[] charContent = encoding.GetChars(byteContent); context.Response.Write(charContent, 0, charContent.Length); 这也没用。 我错过了什么?

两个字符串C#之间的区别

可以说我有两个字符串: string s1 = “hello”; string s2 = “hello world”; 有没有办法让我得到一个string s3 = ” world”; 这两个字符串之间的区别是什么? 编辑: 在这种情况下,差异将始终存在 s1 = “abc” s2 = “abcd ads as “

AuthenticationResult.IsSuccessful开始为谷歌返回false

今天,在我的实际网站上没有任何更改,使用Google外部登录提供程序登录停止了工作。 这只发生在有谷歌登录的用户,其他提供商都没问题。 这也只发生在实时网站上,我的dev机器运行相同代码的调试版本就可以了。 我的代码类似于示例MVC应用程序: public ActionResult ExternalLoginCallback( string returnUrl ) { … AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication( Url.Action( “ExternalLoginCallback”, new { ReturnUrl = returnUrl } ) ); if( !result.IsSuccessful ) { return RedirectToAction( “ExternalLoginFailure” ); } } 我看了一下空的result.error。 有什么变化我需要注意吗? 我可以在1月4日看到类似的问题。 我想这与我的实现有关,而不是谷歌范围的问题,因为我仍然可以登录使用我的谷歌开放ID的SO。 我正在使用Log4Net并接收DotNetOpenAuth日志,但是没有错误,所以它与此答案不同。 我尝试从4.3.0.13117升级到最新的Nuget(4.3.4.13329),但这没有效果。 我似乎也无法在存储库中找到4.3.4.13329源代码的标记。 我将尝试下载并构建4.3.0.13117以查看是否可以找到原因。 唯一的问题是,这可以在我的本地计算机上进行良好的测试,我不确定我是否想在现场网站上安装调试DLL。