草庐IT

c# - 我的 Asp.Net C# 类如何返回 json 格式

如何想要一个返回json格式的类。这个方法在Controller中很有效但是当我想放入一个类时,Json对象似乎不存在。publicJsonResultTest(){//Error1Thename'Json'doesnotexistinthecurrentcontextC:\inetpub\wwwroot\mvcinfosite\mvcinfosite\Validation\ValidationClass\BaseValidator.cs6620mvcinfositereturnJson(new{errMsg="test"});}我想将该代码放在一个简单的类中。我希望能够在许多Cont

c# - 找不到类型或命名空间(是否缺少 using 指令或程序集引用?)

当我尝试编译我的C#程序时出现以下错误:找不到类型或命名空间名称“Login”(是否缺少using指令或程序集引用?)usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceFootballLeague{publicpartialclassMainMenu:Form{FootballLeagu

c# - 是否可以使用 .net 类型声明别名?

是否可以声明一个.net类型的别名?在C#中,如果是的话如何? 最佳答案 正如其他人所说,使用“usingalias=type;”using指令的形式。一些事情:1)它必须是文件或命名空间中的第一件事。(当然,除非您有externalias指令;它们位于using指令之前。)2)别名不是真正的类型。很多人希望看到:usingPopsicleCount=System.Int32;usingGiraffeCount=System.Int32;...PopsicleCountp=123;GiraffeCountg=p;//ERROR,ca

c# - 使用时出错

这个问题在这里已经有了答案:EntityFramework5modelfirst-WhereisIDisposablegone?(4个答案)关闭1年前。我有一个错误Typeusedinausingstatementmustbeimplicitlyconvertibleto'System.IDisposable'在线using(varcontext=newEntityContainer())这是我的代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Thr

c# - 内部使用 yield

如果我没记错的话,当我在usingSqlConnectionblock中使用yield时,我遇到了运行时异常。using(varconnection=newSqlConnection(connectionString)){varcommand=newSqlCommand(queryString,connection);connection.Open();SqlDataReaderreader=command.ExecuteReader();//CallReadbeforeaccessingdata.while(reader.Read()){yieldreader[0];}//CallC

c# - ASP.net 核心网络 API : Using Facebook/Google OAuth access token for authentication

这几天我一直在尝试使用Google和Facebook进行OAuth身份验证,以便在我的ASP.net核心WebAPI项目中工作。我目前的状态是:我有一个ASP.net核心WebApi项目,其中的用户需要进行身份验证我有一个Angular2网络应用程序,它应该使用我的网络API(需要身份验证)我有一个android应用程序,它应该使用我的webapi(需要身份验证)我的目标是:使用Google/Facebook作为OAuth提供商进行登录稍后:添加自己的用户帐户(可能使用IdentityServer4)无需重定向到特殊的登录网站(如IdentityServer4解决方案)。只需点击应用程

c# - 无法从 Win7 x64 上的 32 位进程启动屏幕键盘 (osk.exe)

90%的时间我无法从Win7x64上的32位进程启动osk.exe。最初代码只是使用:Process.Launch("osk.exe");由于目录虚拟化,这在x64上不起作用。我认为这不是问题,我将禁用虚拟化,启动应用程序,然后再次启用它,我认为是正确的做事方式。我还添加了一些代码以在键盘最小化时恢复键盘(工作正常)-代码(在示例WPF应用程序中)现在如下所示:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Windows;usingSystem.Wind

c# - 如何在powershell中实现using语句?

如何在powershell中编写using?这是C#中的工作示例using(varconn=newSqlConnection(connString)){Console.WriteLine("InUsing");}我在Powershell中需要同样的东西(不工作):Using-Object($conn=New-ObjectSystem.Data.SqlClient.SqlConnection($connString)){Write-Warning-Message'InUsing';}它在不使用的情况下工作:$conn=New-ObjectSystem.Data.SqlClient.Sql

c# - 如何使用 CSharpCodeProvider 定位 .net 4.5?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:UsingCSharpCodeProviderwith.net4.5beta对于.net3.5,我将v3.5传递给CSharpCodeProvider,当我在v4.5应用程序中将v4.5传递给CSharpCodeProvider时,我得到InvalidOperationException“找不到编译器可执行文件csc.exe。"任何人都知道这里发生了什么,我做错了什么?重现代码。..usingMicrosoft.CSharp;usingSystem;usingSystem.CodeDom.Compiler;u

C# - 为什么我不能将在 using 语句中声明的类作为引用类型传递?

假设我有以下一次性类和示例代码来运行它:publicclassDisposableInt:IDisposable{privateint?_Value;publicint?MyInt{get{return_Value;}set{_Value=value;}}publicDisposableInt(intInitialValue){_Value=InitialValue;}publicvoidDispose(){_Value=null;}}publicclassTestAnInt{privatevoidAddOne(refDisposableIntIntVal){IntVal.MyInt+