I am trying to migrate some existing code from MVC5 to MVC6 and I am having difficulty with this particular code:
Engine.Razor.RunCompile(File.ReadAllText(emailTemplatePath), "emailTemplateKey", typeof (EmailViewModel), emailViewModel);
I am receiving the following runtime error:
MissingMethodException: Method not found: "Void Microsoft.AspNet.Razor.CodeGenerators.GeneratedClassContext.set_ResolveUrlMethodName(System.String)". in RazorEngine.Compilation.CompilerServiceBase.CreateHost(Type templateType, Type modelType, String className)
The original code I was using in MVC5 was taken from here. If there is no way of converting the above code to work with MVC6 what is another elegant way of doing email templates?
Apparently there has been a change in GeneratedClassContext class - the property ResolveUrlMethodName does not exist anymore, hence the MissingMethodException. Looks like ParserContext class has changed too, since accessing OnError event handler throws the same exception.
In fact it is the setter of the missing property missing (pardon the expression!), which, being a method, causes the exception. Absolutely accurate but somewhat misleading, unless you recall this.
Quite a similar question (and a good answer with alternative solution!) here: RazorEngine and MVC 6 beta 7.
Related
I'm new to ASP.NET MVC. A project that I am attempting to upgrade from MVC 3 -> MVC 5 has most of its calls to RenderAction, ActionLink etc in a format that is different to what I've seen in tutorials for MVC.
Specifically an invocation of a method looks like this:
#{Html.RenderAction<MyControllerHere>(c => c.MyAwesomeMethod());}
Razor is reporting the error:
The non generic method ...RenderAction(System.Web.Mvc.HtmlHelperString) cannot be used with type arguments.
Is this syntax still supported in MVC?
If so, what is the type argument referred to in the error?
If not how does this translate to current syntax?
I'll address your questions individually:
Is the syntax still supported?
Not as far as I know. I couldn't find an official source to confirm this, but as far as I understand, it was temporarily available as part of MVC Futures.
What is the type argument referred to in the error?
The C# type argument passed to the call to RenderAction. In your example, it is MyControllerHere.
How does this translate to current syntax?
Assuming your controller follows the default convention of having the Controller name suffix, such as MyController:
#{Html.RenderAction("MyAwesomeMethod", "My");}
I haven't tested this, but I believe it's mostly right.
When using EntityFramework and returning an IQueryable from an MVC 4 Web API Get action, the following error occurs when the XML serializer is set to use the old XmlSerializer (rather than DataContractSerializer).
XmlMediaTypeFormatter cannot write an object of type ObjectQuery
Is this a known issue?
Too late for this question but for those who faced the same exception:
Your ObjectQuery class probably lacks a default constructor.
See my full answer here: Xml Serialization cannot write an object of type 'x'
No.
You need to define [Queryable] attribute on your action. This requirement was added on RC and probably will be removed at RTM
NOTE
OData support is very unclear at the moment. I have created PocoHttp for consuming ASP.NET Web API's OData but paused development because of lack of clarity at the moment.
I had this error because one of the members of the class I was serialising was an interface. I didn't need to serialise that member so annotating it with a [XmlIgnore] attribute fixed it.
My original project is in Asp.net MVC 2.
I convert my project to MVC 3 without problem.
In the same time, I install the EntityFramework 4.2. Again without problem.
Were it's begin to be complicated is when I add the T4 Generate DBContext.
Thats create me the T4 properly and generate all my entity into his own "POCO Class". Thats perfect!.
When I Build my project, I Got about 400 error. Here is some example.
'mvn.Models.DBEntities' does not contain a definition for
'AddToLeaseConditionInfos' and no extension method
'AddToLeaseConditionInfos' accepting a first argument of type
'mvn.Models.DBEntities' could be found (are you missing a using
directive or an assembly reference?)
As you can see here, the context.AddToLeaseConditionInfos(objCondition); doesn't work anymore.
Same for the DeleteObject context method.
context.ConvertionUnits.DeleteObject(MyObjConvertionUnit);
Someone has an Idea.
Thanks a lot.
You previously used ObjectContext API and default code generator (or EntityObject T4 template) but now you are trying to use DbContext API with POCO DbContext T4 Generator. Those two are completely incompatible because they represent different API. You must use the same code generation approach as you used in EFv4 (which means upgrade will not give you almost any additional value) or you must rewrite your current data access code to use new API.
I apologize for such a long message in advance, but I'm trying for detail here...
I'm working on using bTouch to create a compiled dll for referencing the ArcGIS iOS SDK.
When running bTouch using :
/Developer/MonoTouch/usr/bin/btouch libArcGIS.cs
it returns the following error
/tmp/fp2ivuh8.3gj/IncidentReportApp/AGSMutablePolygon.g.cs(39,31):
error CS0102: The type `IncidentReportApp.AGSMutablePolygon'
already contains a definition for `selAddPointToRing'
/tmp/fp2ivuh8.3gj/IncidentReportApp/AGSMutablePolygon.g.cs(38,31):
(Location of the symbol related to previous error)
/tmp/fp2ivuh8.3gj/IncidentReportApp/AGSMutablePolyline.g.cs(39,31): error CS0102:
The type `IncidentReportApp.AGSMutablePolyline'
already contains a definition for `selAddPointToPath'
/tmp/fp2ivuh8.3gj/IncidentReportApp/AGSMutablePolyline.g.cs(38,31):
(Location of the symbol related to previous error)
Compilation failed: 2 error(s), 0 warnings
I checked my cs class and neither type is referenced\invoked. I'd like to understand why this message is occuring.
I have tried to use the instructions (and downloaded) code by Al Pascual at How to use the ArcGIS iPhone SDK with MonoTouch to call the Map View, but when attempting to launch the view with the code causes a crash. When I try to debug, it locks up when adding a mapping layer. I tested this with the MKMapView, but didn't experience the same behavior.
The error means that you defined more than one method mapping the same objective-C method.
Without the source, it is hard to diagnose.
I'm doing the same thing actually, I heavily modified the old "parser" library and am working on doing it now, hopefully dropping it in the public domain.
I'm seeing a similar (and probably related) problem in the ApiDefinition, there is a class AGSGPResultLayer that derives from AGSDynamicLayer. The AGSGPResultLayer overrides a property called Credential among other and since both are defining the same property.
How should over-riden properties be handled in bTouch? I'm guessing I'm missing something in the syntax.
Use the solution I provide with the correct bindings
I am getting the following error in my mvc application when I am doing the paging functionality
CS1061: 'System.Collections.Generic.IEnumerable' does not contain a definition for 'HasPreviousPage' and no extension method 'HasPreviousPage' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?)
please tell me what to do and what is that Model.
This reminds me of the PaginatedList<T> class found in the Conery et al MVC 1.0 Wrox book... (And probably also found in the NerdDinner app.) I actually have this book right here next to me and have this section tabbed. And sure enough they have a property called HasPreviousPage, which leads me to guess this is what you are working with? It is in Chapter 1, which is a free download. (Google for it.) I highly recommend taking a look at this chapter, or at least this section, as there are many other helpful suggestions and tips to be found!
Best of luck!
I think that you may be missing a namespace import.
Is HasPreviousPage a method or a property? If it is a helpermethod on the type of list you are returning then you need to import that namespace in your aspx file (or in the web.config to reflect on all pages)
You need to change the controller to use Paging, check out http://blogs.embarcadero.com/johnk/2009/04/02/38871 for more info
EDIT: To clarify, so somewhere in the Controller, you're gonna see something to the effect of "return View(someModelObject)" - you need to use PaginationHelper.AsPagination here to turn someModelObject into a pageable object
There are a few possibilities here:
First off, Model is your object, or class. HasPreviousPage is a method or function in Model.
Here are some possibilities:
Model is not defined because the file is not included in the page
HasPreviousPage does not exist as a method
HasPreviousPage is actually a property and needs more information to extract data (as tster is saying)
The signature for HasPreviousPage is incorrect. You are sending too much, or not enough data.
My guess is it's either a boolean property, or a method that returns a boolean. Either way the compiler has no idea what to do with it, so you need to track it down. Try doing a find in your solution for "HasPreviousPage". See if it's been referenced anywhere, or where it is located.
Ctrl + F
Find What:
HasPreviousPage
Look In:
Entire Solution