I've been in the process of attempting to deploy an ASP.NET 4.0 (webform) project on a server that is running an ASP.NET MVC 1.0 application in it's web-root. I was slowly making progress, but hit a wall, so I decided to recompile the MVC app against version 2.0 of the MVC framework and 4.0 of the .NET framework. I used a few tools to do so.
The project appeared to successfully convert, but now it fails to compile. Specifically, it appears that there is a problem with System.Web.HttpContextBase.
For example, if I have the following code:
context.HttpContext.Response.Clear();
I get the following error:
'System.Web.HttpContextBase' does not contain a definition for 'Response' and no extension method 'Response' accepting a first argument of type 'System.Web.HttpContextBase' could be found (are you missing a using directive or an assembly reference?)
I've checked the object explorer just to make sure: HttpContextBase does have a property called Response. This thing is driving me crazy.
I have another big problem, which I believe to be related. Anytime the Request object is queried:
Request["old"];
It says:
Cannot apply indexing with [] to an expression of type 'System.Web.HttpRequestBase'
As far as I can tell, there isn't any reason for this either.
I'm at my wits end. I've checked the breaking changes document for MVC 2.0 but didn't see anything related to this. The references all look good to me; the version numbers all check out.
Further note on the server issue: I do not have any access to the deployment web server except ftp. I cannot go in and mess around with the server configuration. That's why this may sound a little odd to you.
I'm glad that worked for you, here it is again as an answer for everyone else
It's possible your IDE and Runtime are disagreeing over which library
version to use. Try creating a new project and moving your source over
to it and compiling again.
Related
I am learning how to use WebSharper. Actually, I am failing to learn how to use WebSharper.
I wanted to learn how to build a simple SPA so I followed this tutorial from the WebSharper page. I am able to create the SPA with Visual Studio and Zafir (the codename for WebSharper 4.0 that is in beta). I followed every step in the tutorial. I have created a repo on github that is everything in the SPA.
The project won't build. More specifically, in the Client.fs file, I get compiler error
The value or constructor P is not found
in line 10 with the P, in line 11 the same error with the Div, and in line 18 I get the error
Namesapces cannot contain values. Consider using a module to hold your value declrations.
with Run(), yet when I try to move the [<SPAEntryPoint>] information into the module HelloWorld, I get the error
Lookup on object of indeterminate type based on information prior to this program point. A type annotation...
As a result, when I try to build this project, the build fails.
Why am I getting these errors? Is the tutorial out of date with the rest of WebSharper? What can I do to get a simple tutorial to work correctly?
EDIT: I get the same errors when I use WebSharper v3.x, too.
Although not mentioned in the tutorial, adding
open WebSharper.Html.Server
eliminated the compiler errors with P and Div, adding
open WebSharper.Html.Client
eliminated a new compiler error of OnClick, and moving the [<SPAEntryPoint>] into the module eliminated that compiler error and allowed me to build the project.
Thanks for the report! I have updated documentation, indeed that page was not updated since a while. I will review it more thoroughly.
The source of the documentations are found at https://github.com/intellifactory/websharper.docs, feel free to add issue there about further questions/problems or also you can submit a PR.
I started messing with the new Visual Studio Code today and I am running into a small "problem"...of sorts.
I have added reference to Npgsql in the project.json of a Web API project and run 'dnu restore' which also updated the project.lock.json to include the proper references. However the code editor highlights an error for every reference to an Npgsql object, giving me the "are you missing a using directive or reference" message for each one, including the 'using Npgsql;'
The really odd part is that the same tooltip that tells me it doesn't recognize the type..also tells me exactly what it is and does. Intellisense still works and if I execute 'dnx: web'...the whole thing runs just fine with no errors.
I am assuming its just a bug in the new editor but who knows, maybe I've not configured something correctly? Anybody else see this?
You might see this when having two frameworks configured in project.json. By default you will have dnx451 and dnxcore50. It might be that the dependency is only available for one of the frameworks but not for the other. Check the error message VSCode gives you - it will include in []-brackets the framework for which the error is valid.
In my project I've added some custom code to the CategoryNavigation, just a call to a stored database procedure via IDbContext.
My NopCommerce site now crashes after between 10 to 30 minutes of runtime with a "Could not load type" error, which occurs from a Razor Layout file.
Clearly my class (which is compiled into Nop.Web assembly) cannot have disappeared during runtime. On altering the Razor script during the fault, I have found that other Actions and Views work, as do other classes.
The fault does not go away until an edit to Global.asax, an App Pool recycle, or recompile - the former two methods of regaining a proper state would tend to suggest that no files went walkabout.
Is there any generally known mechanism in DotNet where a fault in a program can cause it's class type to become unavailable to the rest of the program? Is anyone aware of a mechanism in NopCommerce that would do this?
I have found out what the problem is with our NopCommerce 2.65
In short, our plugins were outputting all of their references into their Plugin folder, and the Plugin Manager was loading them all.
In effect, because we had registered Nop.Web, and then continued to customise the real Nop.Web, the version in our plugin folder ran out of kilter and lacked any of our customisations.
It appears that Razor prefers to use the version loaded by the plugin manager, and this explains all of the problems that we had. Our solution is now stable and quick.
Hope this helps someone with a similar problem.
Kind Regards,
Mark Rabjohn
Integrated Arts Ltd
I'll just preface this question by saying I began working with SignalR around 30 hrs ago, so please forgive any amateur questions and feel free to point me to the documentation that I've missed if you know of some. Also, I'm not trying to write a blog post - just explaining the steps I went through to get where I am.
TLDR? skip to the questions at the end...
I need to use the Sql Server Backplane (would love to use Redis but we don't currently deal with Redis and aren't comfortable introducing too many new technologies in one dev cycle). Currently, there isn't a NuGet package available for Microsoft.AspNet.SignalR.SqlServer so I have to work with the Github source.
So I went and pulled down the source, compiled and added the reference to Microsoft.AspNet.SignalR.SqlServer.dll but now compilation fails (specifically when referencing GlobalHost.DependencyResolver.UseSqlServer( ... ) in my code - it's a dependency conflict where the *.SqlServer code is expecting a more recent version of *.SignalR.Core - not really surprising as Github's version has (no doubt) more than a few changes since the NuGet package was released). :(
So the next step is to use the *.Core which I compiled with *.SqlServer. Next problem - the new SignalR version no longer works with *.Hosting.Common or *.Hosting.AspNet which have been replaced with the *.Owin library.
So, I added *.Owin (and Owin - from NuGet) but now I run into yet another problem: the MapHubs( ... ) extension method no longer works - there are extension methods called MapHubs( IAppBuilder builder, ... ) in Owin but they don't work off the RouteTable anymore - they work of Owin.IAppBuilder (hence the need to reference Owin, I suppose).
So this is where I'm at. I did a quick read-up about Owin (seems like a cool concept) but I don't particularly care to spend some hours getting my head around that just to be able to setup SignalR on the server-side. So, now for the questions:
Should I just try to make *.SqlServer play nice with the older NuGet packages of SignalR (in other words, is it likely that changing the dependencies of *.SqlServer will introduce unreliable behaviour)? Or, is there a version of *.SqlServer which works with the current NuGet release version of SignalR available online already?
What specific steps are needed to run SignalR via the Owin host approach (I can't find any examples for this without, say, Nancy integration thrown in - or is that the correct approach)?
What is the replacement approach for the MapHubs method? Where do I get an IAppBuilder from? Am I even supposed to do so?
In a Google Groups post, David Fowler indicates that, with Owin support, the AspNet dependency is no longer required. That's fine - but is there any reason to use SignalR in an ASP.Net MVC app now?
If no part of SignalR is hosted via IIS on the server, does client-side fallback (i.e. SSE or long-polling) go through IIS or does it use the Owin host independently?
Finally, I was planning to run SignalR off an ASP.Net MVC 4 project being hosted as a virtual directory off another existing site - I want to work within a single domain. With the Owin approach is it still feasible to do this when my site is hosted in IIS 7.5?
UPDATE: As per 1. above, I managed to get the code compiling by making *.SqlServer depend upon the current NuGet *.Core implementation. So now I can continue development. I don't think I want to use this in production though - I only had to make a small change relating to disposing an object - but I just don't think it's a good approach. So my questions around the Owin approach still stand - unless someone can convince me that the approach I've taken is fine.
Thanks,
Zac
Short Answer:
Hopefully this will help others out who have this problem (I'm sure there's at least one of you!): it seems that the question I asked was really badly timed as, a couple of hours after posting, SignalR was updated in NuGet to version 1.0.0-rc1. So, to anyone with the same problem I had - just upgrade the package.
Details:
After installing when you look at the references, you'll notice that there's now a Microsoft.AspNet.SignalR.SystemWeb reference. Without having delved into it yet, I'm thinking this is a replacement for *.Hosting.Common and *.Hosting.AspNet because after updating the MapHubs( ... ) extension method works fine.
I also noted that the *.SystemWeb reference depends on *.Owin - so I guess the Owin reference is used as an abstraction layer which allows the SystemWeb hosting to be independent of underlying IIS/other server implementations.
As for the .SqlServer reference, well, that still requires me to compile a version against the NuGet version of *.Core in order to compile locally. I'm going to just work with that for now and hope that the project team release a working version on NuGet sometime in the near-future.
A realistic alternative would be to convince my team that we should throw Redis into the mix - having worked with Redis on other projects, I consider this to be a good option due to performance considerations however it does require Linux which might be a problem for a .Net team...
Setup:
An MVC 3 app I am working on suddenly won't compile. I get the following error:
The type 'System.Web.UI.Control' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
This is clearly absurd: I have System.Web version 4.0.0.0 on my machine.
If I remove the code at the relevant line, the error simply moves to the next line.
Visual Studio had been complaining about an add in, eg, if I was trying to Go To Definition, VS would complain and ask if I wanted to remove the add in.
Questions:
Is VS mangled?
Do I need to reinstall the whole bally thing (VS 2010, power tools, MVC 3 and heck knows what else)?
EDIT:
Since finding the cause and therefore solving the issue, I have renamed the question to a name that is more likely to be found by others with the same or similar problem.
To the best of my abilities, my answer tells how to troubleshoot this issue. But if anyone can come up with a full explanation for this issue, then I will gladly mark that as the answer.
OK, I have got to the bottom of this.
The problem was that I was using some string extensions. These were packed in a library, written ages ago.
The issue is caused by the namespace. Lets call it WS.Extensions
In WS.Extensions I also had some extension methods for plain vanilla asp.net server controls, and the classes these extensions are in have using statements for System.Web.UI.
Although the relevant dlls are referenced in the library project, it seems that this causes issues with MVC 3 and, to my mind, an obscure error. Obvious once you know where the issue lies, but not otherwise.
I have moved all the extensions to a new library with no cross using statements that reference server control namespaces such as System.Web.UI.
I have not deleted my post as I think that the problem could happen to others moving from the horrors of server controls to MVC.
Addendum:
The nasty thing of this error is that it shows as a compiler error, with a specific line where the "problem" is. Commenting out this line just moves the line that the compiler complains about down one line. Also, the line had absolutely NOTHING to do with the lines where the extensions were used. So there were no clues.
As a result, I would consider this to be a compiler bug, that has nothing to do with ASP.NET MVC, 3 or otherwise.
It is caused by referencing (using) a namespace from and ASP.NET MVC 3 app, when that namespace includes code that is written for ASP.NET server controls.
I lost half a day on the problem, so hope that this helps someone else. As a result, have renamed the question.
I had the same problem. I had several projects which used different versions of MVC, so I received this kind of error.
Also sometimes it is good to clear ASP.NET cache after converting project to MVC 3. This is also useful.