Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

JSON file create issue on IIS production server

$
0
0

I have an ASP.NET MVC web app running on .NET 4.6.1. I am creating a JSON file. The file is getting created locally, however when I deploy code on IIS on the server, I get an error

Invalid Signature

Even moving the existing JSON file results in the same error. I'm unable to debug as the functionality works locally.

Problem occurs only when array or list type is added to JSON file. For example - JSON file content

{"TypeOfTheTest": "Custom", "ExportData": true} 

this works but the content shown here results in the error of "invalid signature":

{"TypeOfTheTest": "Custom", "ExportData": true, "DataFiles": [ "C:\\Temp\\1.mme" ]}

I tried creating file with content

{"TypeOfTheTest": "Custom", "ExportData": true } 

and it works but when I add list or array type to file invalid signature occurs.

Here is detailed error from server:

System.IO.IOException
Invalid Signature.

System.IO.IOException: Invalid Signature.

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileSystemEnumerableIterator1.CommonInit() at System.IO.FileSystemEnumerableIterator1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler1 resultHandler, Boolean checkHost) at System.IO.Directory.GetFiles(String path, String searchPattern, SearchOption searchOption) at WebUI.Controllers.TestRequestController.CreateXCrashJasonFile(Int32 testRequestId) in C:\Users\repos\DEVELOPMENT\WebUI\Controllers\TestController.cs:line 0 at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters)at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult)at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3d()at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.b__3f()at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.b__1c()at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.b__1e(IAsyncResult asyncResult)

Here is controller method

public JsonResult CreateXCrashJasonFile(int testRequestId){var response = new JsonResponse(message: "JSON file created successfully", success: true);

        var testRequestMacros = TestRequestMacroes.ToList();        var macros = testRequestMacros.Select(z => z.Macro.MacroName.Trim()).ToList();        var testPath = PictureVideoPaths;        if (testPath != null && !string.IsNullOrEmpty(testPath.DatFolder))        {            var basePath = testPath.BasePath;            var mmeFiles = Directory.GetFiles(basePath, "*.mme", SearchOption.AllDirectories);            List<string> mmePaths = new List<string>();            mmePaths.AddRange(mmeFiles);            var ttiBasepath = UtilDefine.GetAppValueToString("dataImportFileObserverDirectory");//            var fileName = testRequestId +"-TTI" + DateTime.Now.ToString("-yyyy-MM-dd_hh-mm-ss") +".json";            var filePath = Path.Combine(ttiBasepath, fileName);            var defaultPath = Path.GetDirectoryName(mmeFiles[0]);            var defaultName = Path.GetFileNameWithoutExtension(mmeFiles[0]);            var outputFileName = defaultName +"-" + DateTime.Now.ToString("-yyyy-MM-dd_hh-mm-ss");            var diademFilePath = Path.Combine(defaultPath, "Result");            var excelFilePath = Path.Combine(defaultPath, "Report");            //MacroTTIServerViewModel _data = new MacroTTIServerViewModel()            //{            //    DataFiles = mmePaths,            //    TypeOfTheTest = "Custom",            //    Macros = macros,            //    ExportData = true,            //    OutputPaths = new TTIServerOutputPathsViewModel()            //    {            //        DIAdemFilesName = outputFileName,            //        DIAdemFilesPath = diademFilePath,            //        ExcelFilesName = outputFileName,            //        ExcelFilesPath = excelFilePath,            //        PDFReportFilesName = outputFileName,            //        PDFReportFilesPath = excelFilePath            //    }            //};            //Tried with class , did not work so moved to string approach            StringBuilder sb = new StringBuilder();            sb.Append("{\"DataFiles\":[");            foreach (var path in mmePaths)                sb.Append("\"" + path.Replace("\\","\\\\") +"\",");            sb.Length--; // Remove the last comma            sb.Append("],\"TypeOfTheTest\":\"Custom\",\"Macros\":[");            foreach(var macro in macros)                sb.Append("\"" + macro +"\",");            sb.Length--; // Remove the last comma            sb.Append("],\"ExportData\":true,\"OutputPaths\":{");            sb.Append("\"DIAdemFilesPath\":\"" + diademFilePath.Replace("\\","\\\\") +"\",");            sb.Append("\"DIAdemFilesName\":\"" + outputFileName +"\",");            sb.Append("\"ExcelFilesPath\":\"" + excelFilePath.Replace("\\","\\\\") +"\",");            sb.Append("\"ExcelFilesName\":\"" + outputFileName +"\",");            sb.Append("\"PDFReportFilesPath\":\"" + excelFilePath.Replace("\\","\\\\") +"\",");            sb.Append("\"PDFReportFilesName\":\"" + outputFileName +"\"");            sb.Append("}}");            string json1 = sb.ToString();            //string json = JsonConvert.SerializeObject(_data);            using (Impersonation.LogonUser(UtilDefine.GetAppValueToString("NetworkDomain"), UtilDefine.GetAppValueToString("NetworkUser"), UtilDefine.GetAppValueToString("NetworkPassword"), LogonType.NewCredentials))            {                using (FileStream fs = System.IO.File.Create(filePath))                {                    var content = new UTF8Encoding(true).GetBytes(json1);                    fs.Write(content, 0, content.Length);                }            }        }        else        {            response = new JsonResponse(message: "Test path empty", success: false);        }        return Json(response, JsonRequestBehavior.AllowGet);    }I tried JsonConvert.SerializeObject but did not work so moved to string approach

Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>