我有一個Asp.Net MVC應用程序與框架版本.NET 4.5運行,我正在使用VS2017專業版。用戶可以上傳附件,包括但不限於:C#7本地功能沒有按預期工作,也沒有顯示錯誤
- Excel中
- 字
- 的PowerPoint
- JPEG
- PNG
所以我有一個private
功能,如下:
private string ImageExtension(string path)
{
string noImagePath = HttpContext.Current.Server.MapPath("~/Content/images/Template/No-Image-Available-100x100.jpg");
string fileExtension = System.IO.Path.GetExtension(path);
switch (fileExtension)
{
case ".jpg":
case ".jpeg":
case ".gif":
case ".png":
return path;
default:
return noImagePath;
}
}
正如您所看到的,它非常簡單,並且不會做任何奇特的事情。由於我只在一個地方使用了這個功能,因此我考慮使用本地函數的新C#7功能。所以我已經提前創建了我的主要功能,並在其中添加了ImageExtension(string path)
。
public void BugInfo(HttpPostedFileBase file)
{
if(file != null && file.ContentLength > 0)
{
string fileName = file.FileName;
string directoryPath = "directory path";
//save path of
string savePath = System.IO.Path.Combine(directoryPath, fileName);
string testString = ImageExtension(savePath);
string ImageExtension(string path)
{
string noImagePath = HttpContext.Current.Server.MapPath("~/Content/images/Template/No-Image-Available-100x100.jpg");
string fileExtension = System.IO.Path.GetExtension(path);
switch (fileExtension)
{
case ".jpg":
case ".jpeg":
case ".gif":
case ".png":
return path;
default:
return noImagePath;
}
}
}
//save values to db here
}
通過上面的代碼我的項目生成沒有任何錯誤。只要我打F5
或Ctrl + F5
我收到以下錯誤屏幕
如果我在ErrorList
檢查,看看是否有我得到根本就沒有,你可以看到下面的任何錯誤。
誰能告訴我,我要去哪裏錯了,請。我是否必須更改任何設置或需要包含任何其他DLL以利用C#7功能。
看着this答案似乎像所有的C#7特點應該在.NET 4.5
嘗試查看輸出窗格/窗口,在組合框中選擇編譯。也許錯誤信息已經記錄在那裏。 – xanatos
以及@xanatos所說的,在錯誤列表窗格的頂部有一個下拉列表,讓您可以選擇不同的顯示源(build/intellisense)。 –
@xanatos謝謝,我會看看,看看是否有幫助。 – Izzy