I just published an application that is working fine in development, but when I upload it to the server it fails when I try to pre-render a specific view.
Simple mvc function returning a view:
public ActionResult StandaloneReport(ReportPageData pageData)
{
return View(pageData);
}
Simple server side render:
#Html.React("Components.ReportDisplayContainer", new {.pageData = Model})
#Html.ReactInitJavaScript()
React.net is set to used a pre-packed js bundle:
ReactSiteConfiguration.Configuration.SetLoadBabel(false)
.AddScriptWithoutTransform("~/Scripts/webpack/build/server.bundle.js");
ReactSiteConfiguration.Configuration.SetReuseJavaScriptEngines(false);
This all works fine in development, and I have republished and deleted all files from the server before publishing so I don't get why it's not working on the server..
The error I am getting is:
Error while rendering "Components.ReportDisplayContainer" to
"react_phCzHNkR5Uq7r5UEzzqYrQ": Script threw an exception: Object
doesn't support property or method 'from' Line: 0 Column:0
Line 61: #Html.React("Components.ReportDisplayContainer", New With {.pageData = Model})
Which I can only see relates to this line of code generated by webpack:
return Array.from(arr);
So why is the react helper happy to do it locally but not on the server?
Not sure if this is exactly what you're experiencing, but I happened upon the solution for my issue after many hours of fruitless experimentation, so hopefully it can help you or someone on the web.
My project has 10 jsx files:
bundles.Add(new System.Web.Optimization.React.BabelBundle("~/bundles/CustomJsxFiles").Include(
"~/Content/ReactJSXFiles/ReactApp.jsx",
"~/Content/ReactJSXFiles/CalendarControl.jsx",
"~/Content/ReactJSXFiles/BootstrapNavbar.jsx",
"~/Content/ReactJSXFiles/SectionList.jsx",
"~/Content/ReactJSXFiles/FutureDPsList.jsx",
"~/Content/ReactJSXFiles/PastDPsList.jsx",
"~/Content/ReactJSXFiles/TimeRecs.jsx",
"~/Content/ReactJSXFiles/ClickableHeader.jsx",
"~/Content/ReactJSXFiles/CodeEntryModal.jsx",
"~/Content/ReactJSXFiles/Dp28DayRow.jsx"
));
and it works fine when debugging locally, but when I published to IIS, I only see 3 files:
ClickableHeader.jsx
ReactApp.jsx
TimeRecs.jsx
FYI, I am using
BundleTable.EnableOptimizations = false;
for debugging purposes. When it's set to true, it creates just one file, but even in that case you can still see that the file is much smaller than the one created locally.
Anyway, at the bottom of the discussion at
http://reactjs.net/guides/weboptimizer.html
I noticed this line:
We just had the same issue, I followed the above instructions. Make
sure the JSX is marked as "content" in the properties.
I look in Visual Studio and the jsx files that were missing were marked none like this:
Whereas the ones that were there were marked like this:
After marking them all as Content, I could successfully push to the server.
Related
I promise I searched for the answer...
My application consist of both a Mobile backend in azure and a Web-client application that makes calls upon this back-end.
I have run across a bizarre bug that creates 404 not found errors when calling a Http Get function on my backend.
The bizarre part of this issue is that the error is random. It is probably a %50 chance that I might get a 404 or a 200 ok response from the server. This only happens on one specific method that was recently added.
I am wondering if breaking the back-end into instances might have created a non-identical copy of my app.
I removed the instance, and the specific api I have been calling is not longer available on the published version it is visible while running on debug.. I get 100% error on the published version now.
What is wrong with azure? cleaning and rebuilding the back-end does nothing.
[Route("api/UserProject/{projectId}")]
[HttpGet]
public HttpResponseMessage GetUserProjectByProjectId(int projectId)
{
//Get all UserProject
List<DTO.User> userList = new List<DTO.User>();
DataTable UserdataTable = SqlHelper.ExecuteDataset("dbo.UserGetByProjectId", projectId).Tables[0];
if (UserdataTable.Rows.Count > 0)
{
foreach (DataRow dataRow in UserdataTable.Rows)
{
DTO.User u = new DTO.User();
Map.DataToObject(dataRow, u);
userList.Add(u);
}
}
return this.Request.CreateResponse(HttpStatusCode.OK, userList);
}
going to the api/help page on Debug the UserProject route works and is shown in DEBUG mode, but as soon as I publish the app the UserProject function is not longer anywhere to be found.
Wow I finally fixed it. I did the one thing I though would be useless and it worked.
I restarted the service from the azure portal....
My opinion: I guess the created intances where the ones working of the latest version while the original was unable to be updated and the only way to make the original update was to restart the whole thing.
I really don't know why this happened, if you guys want to comment on this please do so.
Iam using Nancy Framework with C# and my views are rendered from HTML files. If i need to udate the code in my HTML,CSS or JS (which is part of the content), I have to go through the long annoying process of
Stopping the running C# project
Editing my HTML,CSS or JS File
Saving the changes
Running the C# project
Refreshing the browser
Waiting for the connection to localhost:8080 to be established (This usually takes a bit longer on the first run and that is even more annoying)
7.Finally i get to see if that CSS styling has been applied...if it has not be applied, i have to start the whole process from 1.
Please help me if u have a better way of doing this if not maybe just explain to me why i always have to wait a few more seconds for the first run of the C# project to start allowing connections on the browser.
Nancy does not cache CSS or JS files, they are pass-through files when they exist under Content folder, or if you explicitly set them up in the static conventions.
To disable View Caching, simply disable caches in your bootstrapper:
StaticConfiguration.DisableCaches = true
Edit:
Based on your comment:
https://github.com/richorama/Jukebox/blob/master/Jukebox/Controllers/Home.cs#L11
namespace Jukebox.Controllers
{
public class Home : NancyModule
{
public Home()
{
Get["/"] = x =>
{
return Response.AsFile("default.htm");
};
}
}
}
This will load the htm file off the disk every request. So I'm not entirely sure what issues you're running into. None-the-less try disabling the caches.
Also caching is only enabled when you're running the code in Release mode...
Edit 2:
Since you're using a console app and files are copied to the bin.
https://github.com/NancyFx/Nancy/wiki/The-root-path#changing-the-root-path
Create a implementation of the rootpath provider pointing to your dev directory. Configure it to only run during development.
Do you get 304 - Not Modified HTTP status code for the HTML, JS and CSS files? If so, then the files are cached by browser. Disable the caching either on the server side as Phill suggested or disable the browser caching (which might be counter-productive).
I was debugging a localhost asp.net and I have made some very minor code changes and ran it again and now I get an error I have never gotten before. In nice big blue letters it tells me "This page can't be displayed".
Apart from taking everything to forumula, what do you think would cause this error and how would I go about fixing it? It offers a button that says "Fix connection problems", but this is a localhost browser, so there are no connection, really. I clicked the button anyway and it did not offer any solution. I also refreshed the page, as suggested and it did nothing.
I test my localhost in the browser and it is working.
What do you think?
If it is functioning properly for you when debugging on local host, then I would assume it is a path/file resole issue. Trying doing what was mentioned earlier, and debugging it. That is why your localhost test works, but when placed on the server for the live version, it fumbles. I do not see any other reason that may cause this. Yes, it could be a browser issue, but is not really anything specific to conclude that. What were the changes you made? Is there a way you can post the code, or some of it?
I found the offensive part of code.
The code does a check on the URL and modifies it to make sure it is correct. This messes up the localhost url. The same if statement that checks for characters in the URL now also checks that string to see if there is a "localhost" and then side-steps the code.
I had the same problem. I fixed it by next steps:
stop debug
delete solution (I think this point is optional)
get version from TFS (this point is optional with previous ;-) )
close VS
delete custom IISExpress config files in c:\Users\\Documents\IISExpress (delete whole folder)
restart computer
start VS
start Debug
Application is running.
I am using Visual Studio 2017 and I had a similar problem. I tried #Vojta Novák's instructions to no avail.
However, I did find a solution that works for me.
Right-click on the web project, select "Properties" and select the "Web" tab on the properties. Change the port number in the Project Url and click [Create Virtual Directory]. Save and run the project.
I tried deleting the IIS Express configuration folder, but it seems like no matter what I do, if I try to run the web app under the port number it was on originally, I get an error.
What is even more baffling is the fact that I only could reproduce the error when browsing the web app with IE. With Chrome, it works fine.
I get this error sometimes after I publish. I just add an empty line to my web.config. Then run the app. It now works. Then stop and undo my change to my web.config.
I have a simple web service that looks something like this:
[WebMethod]
public OrderForecastItem GetOrderForecast(int shipTo, string catalogName, bool showPricing)
{
return OrderForecastManager.GetOrderForecast(shipTo, catalogName, showPricing);
}
I'm calling it from another place in a fairly simple way:
using (OrderForecastWS.OrderForecastWS service = new OurSite.Web.Reporting.OrderForecastWS.OrderForecastWS())
{
OrderForecastItem orderForecastItems = service.GetOrderForecast(2585432, "DENTAL", false);
}
After some gymnastics to get the systems to understand that I'm talking about the same type of objects on the client and server sides (I had to open the Reference.cs file inside my Web References, delete the generated OrderForecastItem and add a link to our real OrderForecastItem), the system runs and attempts to get the item.
Unfortunately, it now bombs during the service call, claiming:
Exception There is an error in XML document (1, 1113).(InvalidOperationException)
I can go to the web service in a browser, put in the same values, and I get a seemingly valid XML response. (It looks okay to me, and I ran it through the XML parser at W3Schools, and it cleared it.)
I think the numbers in the error are supposed to be the line and character number...but the browser seems to reformat the xml document, so I can't easily see what the original (1, 1113) location is.
I don't see an easy way to intercept the response and examine it, since it seems to be blowing up as soon as it gets it.
How can I debug this?
If you control the service, you can step into it. If it is a part of your solution and hosted in VS WebDev on your local box, just F11 from Visual Studio, if service is hosted remotely (eg by IIS on other computer) run remote debugging tool on service host msdn, and then you will be able to step in to the service remotely.
By the way, you can tell Visual Studio to re-use objects from referenced libraries for types from the service: just pick configure Service Reference from service context menu and tell which libraries to re-use.
On second thought this error may happen if returned XML could not be deserialized into your business object. May happen when class is changed on either side, or you are trying to use different version of business library than service is using.
If you use Firefox, I'd recommend Firebug. You'll be able to easily view the response from the website in its original format, which might get you closer to the line and position you're looking for.
I'm creating an Updater program in C# for my PC game that basically sends an Http message to the server to find out what the latest version of the game is. If there is a newer version, it downloads the necessary files. To download the files I used the WebClient.DownloadFile() method. There are a few posts on the forums detailing problems with this method but none of them are quite like mine.
I use the method like this:
WebClient webClient = new WebClient();<br/>
webClient.DownloadFile(sOriginFile, sDestinationFile);
I immediately ran into a problem downloading any files with the following extensions:
.xnb
.xgs
.xsb
.xwb
I would get an exception stating "The remote server returned an error: (404) Not Found."
So as an experiment I added 3, more common, files to the same directory.
.txt
.doc
.jpg
and the DownloadFile() method worked perfectly for those files. Does anybody know why this method isn't working for the first 4 files types but works fine with the last 3?
Also I tried WebClient.DownloadData() and HttpWebRequest.GetResponse() (after setting up the request), I even tried reversing the extension name on the server (.bnx), but no matter what, I would get the same exact exception.
If anybody really wants to tackle this, here are links to 2 sample files (I tried to post all 7 sample files but Stack Overflow only allows me to post 2 links):
http://www.facepuncher.com/Versions/CastleAbra/1.1/Sample.txt
http://www.facepuncher.com/Versions/CastleAbra/1.1/UiCursor.xnb
Most likely the MIME-Settings for the file types you mention are set up incorrectly in IIS. Go to IIS Server Mananger -> MIME-Settings and add the file-types accordingly.
Probably a better idea to transfer any filetype would be to download only files like
file.xnb.dat
file.xgs.dat
and rename them locally.
-Matthias