草庐IT

content_type_task

全部标签

c# - 可访问性不一致 : return type is less accessible than method C#

好吧,这真的很奇怪。我有一个私有(private)成员,我想将它用于Form2。我创建了一个公共(public)静态方法,以便我可以将该成员放入Form2。这是我的代码:privatestaticAppControllerappController;privateBreadRepositorybreadRep;privateCakeRepositorycakeRep;privateSandwichRepositorysandwichRep;publicForm1(){InitializeComponent();breadRep=newBreadRepository();cakeRep=

c# - 构建 : error MSB4062 Microsoft. Build.Tasks.ResolveComReference 时出现 .NET Core 错误

我正在开发.net核心网络应用程序(针对net461)。该应用需要引用COMdll。我添加了COM引用,应用程序仍然在我的开发机器上构建。但是,在构建服务器上它无法构建并出现此错误:C:\ProgramFiles(x86)\dotnet\sdk\2.0.0\Microsoft.Common.CurrentVersion.targets(2604,5):错误MSB4062:“Microsoft.Build.Tasks.ResolveComReference”任务无法从程序集Microsoft.Build.Tasks.Core加载经过一番搜索,这似乎是一个非常不常见的错误。任何人都知道错误

c# - 在 C# 中,Type.FullName 何时返回 null?

MSDNforType.FullName说这个属性返回nullifthecurrentinstancerepresentsagenerictypeparameter,anarraytype,pointertype,orbyreftypebasedonatypeparameter,oragenerictypethatisnotagenerictypedefinitionbutcontainsunresolvedtypeparameters.我数了五种情况,发现一个比一个更不清楚。这是我尝试构建每个案例的示例。usingSystem;usingSystem.Collections.Gene

c# - "new"inside concrete type projection 只被调用一次

我有简单的Linq2Sql查询:varresult=fromtinMyContext.MyItemsselectnewMyViewModelClass(){FirstProperty=t,SecondProperty=newSomeLinq2SqlEntity()}问题是newSomeLinq2SqlEntity()似乎只对该序列执行一次,因此查询结果中MyViewModelClass的所有实例共享链接到一个对象。更新:这是我快速检查它的方法:result[0].SecondProperty.MyField=10;使用调试器,我可以检查MyField在所有情况下都设置为10。当我用fo

c# - Task.ContinueWith 是否捕获调用线程上下文以继续?

下面的Test_Click是在UI线程上运行的代码的简化版本(带有WindowsFormsSynchronizationContext):voidTest_Click(objectsender,EventArgse){vartask=DoNavigationAsync();task.ContinueWith((t)=>{MessageBox.Show("Navigationdone!");},TaskScheduler.FromCurrentSynchronizationContext());}我是否应该显式指定TaskScheduler.FromCurrentSynchronizat

c# - Content-Type 字符集是否未从 HttpResponseMessage 公开?

我正在将一些代码从使用HttpWebRequest转换为HttpClient。我遇到的一个问题是从内容类型响应header获取字符集。使用HttpWebRequest时,字符集在HttpWebResponse.CharacterSet属性中公开,如下所示using(WebResponseresponse=awaitthis.webRequest.GetResponseAsync()){stringcharacterSet=((HttpWebResponse)response).CharacterSet;您还可以从WebResponse.ContentType属性或从HttpWebRes

c# - "Unable to cast object of type ' System.Net.Http.Formatting.JsonContractResolver ' to type ' Newtonsoft.Json.Serialization.DefaultContractResolver '."

我们有一个最近被转移到新服务器的WEBAPI项目。在对项目的有效负载进行一些添加后,我正在运行我的项目,但它突然抛出以下错误:Unabletocastobjectoftype'System.Net.Http.Formatting.JsonContractResolver'totype'Newtonsoft.Json.Serialization.DefaultContractResolver'.有问题的代码行在global.asax中:protectedvoidApplication_Start(){GlobalConfiguration.Configure(WebApiConfig.R

c# - 我可以在 ASP.NET Core 中使用 Content Negotiation 向浏览器返回 View 并向 API 调用返回 JSON 吗?

我有一个返回客户列表的非常基本的Controller方法。我希望它在用户浏览时返回ListView,并将JSON返回给在Acceptheader中具有application/json的请求。在ASP.NETCoreMVC1.0中这可能吗?我已经试过了:[HttpGet("")]publicasyncTaskList(intpage=1,intcount=20){varcustomers=await_customerService.GetCustomers(page,count);returnOk(customers.Select(c=>new{c.Id,c.Name}));}但默认情况

c# - 带有未捕获异常的 Task.Factory.StartNew 会杀死 w3wp?

我刚刚将我网站的一些代码从使用QueueUserWorkItem转换为Task.Factory.StartNew我有一些错误的代码引发了异常并最终关闭了w3wp。在WindowsServer2008R2、x64上运行IIS7.5Task.Factory.StartNew(()=>{MethodThatThrowsException();}Application:w3wp.exeFrameworkVersion:v4.0.30319Description:Theprocesswasterminatedduetoanunhandledexception.ExceptionInfo:Syst

c# - 使用 Task.Run() 写入控制台失败

我的一位同事发现我们的代码存在问题,花了一段时间才查明到底发生了什么,但这个简单的例子可以最好地证明这一点://FailsclassProgram{staticvoidMain(string[]args){Task.Run(()=>Console.WriteLine("HelloWorld"));Console.ReadKey();}}//WorksfineclassProgram{staticvoidMain(string[]args){Console.Write(String.Empty);Task.Run(()=>Console.WriteLine("HelloWorld"));