问题:

我试图以.NET 4.6为目标,并通过将C#语言版本更改为6来利用最新的C#版本。

但是在编译期间我遇到了这个错误:

错误无效选项’6’表示/ langversion; 必须是ISO-1,ISO-2,3,4,5或默认值

如果我将Web.Config设置中的/langversion:6更新为5,它可以工作,

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701">

但是如何在不使用低语言版本的情况下解决这个问题呢?

我正在使用Visual Studio 2015社区版,我还手动安装了.NET Framework 4.6,以防Visual Studio 2015默认安装它。

该项目是Visual Studio 2015创建的标准ASP.NET MVC模板项目。

I am trying to target .NET 4.6 and also take advantage of the latest C# version by changing the C# language version to 6.However during compilation I got this error:Error Invalid option ‘6’ for /langversion;must be ISO-1, ISO-2, 3, 4, 5 or DefaultIf I update the /langversion:6 in Web.Config setting to 5 it works,But how do I resolve this without resorting to lower language version?I am using Visual Studio 2015 Community Edition, and I have also installed .NET Framework 4.6 manually just in case it was not installed by default by Visual Studio 2015.The project is a standard ASP.NET MVC template project created by Visual Studio 2015.

问题:

我正在初始化HttpWebRequest,然后检索它的响应。 有时,我得到500(或至少5 ##)错误,但没有描述。 我对两个端点都有控制权,希望接收端能获得更多信息。 例如,我想将异常消息从服务器传递到客户端。 使用HttpWebRequest和HttpWebResponse是否可能?

码:

try
{
    HttpWebRequest webRequest = HttpWebRequest.Create(URL) as HttpWebRequest;
    webRequest.Method = WebRequestMethods.Http.Get;
    webRequest.Credentials = new NetworkCredential(Username, Password);
    webRequest.ContentType = "application/x-www-form-urlencoded";
    using(HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse)
    {
        if(response.StatusCode == HttpStatusCode.OK)
        {
            // Do stuff with response.GetResponseStream();
        }
    }
}
catch(Exception ex)
{
    ShowError(ex);
    // if the server returns a 500 error than the webRequest.GetResponse() method
    // throws an exception and all I get is "The remote server returned an error: (500)."
}

任何帮助,将不胜感激。

I am initiating an HttpWebRequest and then retrieving it’s response.Occasionally, I get a 500 (or at least 5##) error, but no description.I have control over both endpoints and would like the receiving end to get a little bit more information.For example, I would like to pass the exception message from server to client.Is this possible using HttpWebRequest and HttpWebResponse?Code:Any help with this would be much appreciated.

问题:

我在using语句中有一个IDbTransaction,但我不确定如果在using语句中抛出异常,它是否会被回滚。 我知道using语句会强制调用Dispose()……但是有人知道Rollback()是否也是如此?

更新:此外,我是否需要显式调用Commit(),如下所示,还是由using语句处理吗?

我的代码看起来像这样:

using Microsoft.Practices.EnterpriseLibrary.Data;

...

using(IDbConnection connection = DatabaseInstance.CreateConnection())
{
    connection.Open();

    using(IDbTransaction transaction = connection.BeginTransaction())
    {
       //Attempt to do stuff in the database
       //potentially throw an exception
       transaction.Commit();
    }
}

I’ve got an IDbTransaction in a using statement but I’m unsure if it will be rolled back if an exception is thrown in a using statement.I know that a using statement will enforce the calling of Dispose()…but does anyone know if the same is true for Rollback()?Update: Also, do I need to call Commit() explicitly as I have below or will that also be taken care of by the using statement?My code looks sort of like this:

问题:

我有一个C# webforms应用程序,直到今天一直在webforms地工作。

今天,突然之间,每当我尝试运行该应用程序时,我都会收到文件锁定错误:

无法将文件“ obj \\ Debug \\ MyProject.exe”复制到“ bin \\ Debug \\ MyProject.exe”。 该进程无法访问文件“ bin \\ Debug \\ MyProject.exe”,因为它正在被另一个进程使用。

谷歌搜索错误不会带来明显的错误,即VS认为文件已锁定。 它是绝对的Visual Studio本身锁定文件,因为当我关闭VS并重新打开它,项目执行罚款-第一次。 当我尝试第二次运行它时,出现文件锁定错误。

每次我要运行该应用程序时,关闭VS并重新打开它都不可行! 如何找出锁定文件的内容,并阻止它被锁定?

编辑:另一个有趣的发现:我什至不必运行该应用程序。 编译一次会导致文件锁定。 我不能连续编译两次!

此问题特定于我的解决方案中的一个项目。 所有其他项目都可以正常工作,并且可以执行多次。 只是这个项目被锁定了。

I’ve got a C# webforms app, that until today had been working just swimmingly.Now today, all of a sudden, every time I try run the app, I get a file locking error:Unable to copy file “obj\\Debug\\MyProject.exe” to “bin\\Debug\\MyProject.exe”.The process cannot access the file “bin\\Debug\\MyProject.exe” because it is being used by another process.Googling the error doesn’t come up with anything beyond the obvious, ie VS thinks the file is locked.And it is definitely Visual Studio itself that locks the file, because when I close VS and reopen it, the project executes fine – the first time.When I try to run it a second time, I get the file locking error.Closing VS and reopening every time I want to run the app is not a viable workaround!How do I find out what’s locking the file, and stop it from getting locked?EDIT: Another interesting discovery: I don’t even have to run the app.Just compiling it once causes the file locking;I cannot compile twice in a row!This problem is specific to one project in my solution.All other projects work fine and can be executed as many times as I like.It’s only this one project that gets itself locked up.

问题:

我正在使用Web API创建一个Web服务。 我实现了一个简单的类

public class ActivityResult
{
    public String code;
    public int indexValue;
    public int primaryCodeReference;
}

然后我在我的控制器内实现了

[HttpPost]
public HttpResponseMessage Post(ActivityResult ar)
{
    return new HttpResponseMessage(HttpStatusCode.OK);
}

但是当我调用API传递POST文件时json:

{"code":"XXX-542","indexValue":"3","primaryCodeReference":"7"}

我收到以下错误消息:

{
    "Message": "The request entity's media type 'text/plain' is not supported for this resource.",
    "ExceptionMessage": "No MediaTypeFormatter is available to read an object of type 'ActivityResult' from content with media type 'text/plain'.",
    "ExceptionType": "System.Net.Http.UnsupportedMediaTypeException",
    "StackTrace": "   in System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n   in System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n   in System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)"
}

我究竟做错了什么?

I’m creating a web service using Web API.I implemented a simple classAnd then I have implemented inside my controllerBut when I call the API passing in POST the file json:I obtain the following error message:What am I doing wrong?