w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Umbraco Rest Extension Not working after moving code from 4.7.1 into 4.11.10
Most probably your code is throwing an exception and this gets converted to a 500 error that masks it. So the problem could be anything. I had the same issue and the best thing I did was wrap all my code inside a try/catch and return the exception as a string. Remember that in order to get all the info from the exception you need to compile in Debug mode and copy the .pdb file along with your .dll. ... [RestExtensionMethodAttribute] public static string GetCountries() { try { return Core.RazorRenderer.RenderScriptFile("LandingPage/GetCountries", 0, GetLandingParameters(false)); } catch (Exception e) { return e.ToString(); } } ... Hope this helps you find the problem ! It worked for me.

Categories : C#

why java 8 use default methods instead of extension methods
Because it's purpose is the exact opposite of the use-case you describe. Default methods allow library code to change its API without requiring calling code to be changed & recompiled. It's only a tool to help with API & ABI compatibility, it's not a tool to override implementation details of 3rd party code.

Categories : Java

In Umbraco 6.1.1 MVC 4, how can I do a form post back to a surface controller using a model that inherits from Umbraco's RenderModel?
Ok, I've had no responses to this question but am now in a position to answer it myself. Maybe it was a fundamental oversight, but not that obvious imho, and information on the Umbraco forum etc about inheriting from RenderModel is fairly limited. Essentially the answer, as was my first instinct, is to solve the original exception "No parameterless constructor defined for this object" by providing a paramaterless constructor. The difficulty is working out what to put inside the parameterless constructor for my model, since it inherits from the Umbraco RenderModel which requires an IPublishedContent instance passed to it's constructor. Luckily while browsing around I happened across this post on the Umbraco forum: http://our.umbraco.org/forum/developers/api-questions/40754-Getting-Curre

Categories : Asp Net Mvc

Umbraco MVC Implementation - View does not depend on Umbraco implementations
No you can't. Simply because all requests pass through a single action. In order to retrieve a path to a CMS-managed page, you need to use the node/content traversal the @Model provides. See here for more details on this. Edit To clarify, the author of the article is suggesting that the Umbraco implementation should be more in line with a traditional MVC implementation with little or no logic in the views. Therefore, any querying of node data should happen prior to the view (e.g. in the Mappers). So this is where you would have to retrieve the links. Umbraco's default MVC implementation forces all requests to go via a single action on a single controller. The author's implementation allows the requests to be shared across one controller per document type - which is better IMO. But it st

Categories : Asp Net Mvc

Umbraco MediaService / Umbraco MediaItem not saving
To Save media, I found this method with MediaService. However, I think it's possible another method more refined [HttpPost] public JsonResult Upload(HttpPostedFileBase file) { IMedia mimage; // Create the media item mimage = _mediaService.CreateMedia(file.FileName, <parentId>, Constants.Conventions.MediaTypes.Image); mimage.SetValue(Constants.Conventions.Media.File, file); _mediaService.Save(mimage); return Json(new { success = true}); }

Categories : C#

Umbraco - error when using umbraco.library:NiceUrl(...)
Ok I found a solution: I added an extra check to this part: <!-- Return the url --> <xsl:if test="$i = $max"> <xsl:if test="$id != '' "> <xsl:value-of select="umbraco.library:NiceUrl($id)" /> </xsl:if> </xsl:if> this fixed my problem.

Categories : Xslt

Could not locate Razor Host Factory type: umbraco.MacroEngines.RazorUmbracoFactory, umbraco.MacroEngines
If you are trying to host the blogengine site within a virtual directory of the Umbraco site, then you will have to amend the blogengine web.config to "remove" all the Umbraco-specific handlers and modules, as these will be inherited by the blogengine application, causing this exception because the application can't find the relevant DLLs in its bin folder. I recently had a similar problem and I have posted the web.config I used in the virtual directory below. Mine was a very simple web application, so obviously this will not work by itself in your blogengine app. You will need to add the relevant parts into your web.config file. Also, this was for a v6 Umbraco install in IIS7.5, so you may have to experiment a little. <?xml version="1.0"?> <configuration> <configSecti

Categories : Iis

When to declare Class Extension Methods
Declare them if they help you. From a documentation point of view they are very useful. The compiler will also tell you if you have specified that a method will exist and then not implemented it. There is no rule, but its a good idea to add them. Consider how you'll feel if you have to come back in 6 months and edit the class - will having the methods listed there help you?

Categories : IOS

Custom objectset extension methods
public static class YourExtensions { public static void MyMethod<T>(this DbSet<T> table) where T: class // this constraint is required because DbSet<T> have it { // code here } } Here is MSDN article on Extension Methods

Categories : C#

Naming convention for Rx extension methods?
I don't know of any official guidance, but the main metric I would use is to look at the amount of work you are doing. For most cases, there is a non-trivial amount of work being done (which is subjective in itself), such as turning an IEnumerable into an IObservable, and I would use ToObservable. When the method does fairly trivial work, as with the Observable.AsObservable extension method, AsObservable seems the better choice. Another notable difference between these two methods is that AsObservable is not much more than a type cast and doesn't make any real changes to behavior of the argument, but Observable.ToObservable(IEnumerable<T>) returns an object with significantly different semantics.

Categories : Misc

Static Constructor and Extension methods
Wondering if my static constructor fails and throws exception if the extension methods would still work? No. If a type initializer of any kind (whether using a static constructor or not) fails, the type is basically unusable thereafter. It's very easy to demonstrate this... using System; static class Extensions { static Extensions() { Console.WriteLine("Throwing exception"); throw new Exception("Bang"); } public static void Woot(this int x) { Console.WriteLine("Woot!"); } } class Test { static void Main() { for (int i = 0; i < 5; i++) { try { i.Woot(); } catch (Exception e) { Console.WriteLine("Caught exception: {

Categories : C#

What is the practical use of extension methods in Java?
The reason these were added were part of the adding of closures to Java so that there was a easy upgrade path to things like collection classes. The challenge with the addition of closures is there now are a whole lot of functions you want to add to standard collections. However, if you add those to the existing interfaces you break any implementations of those interfaces. A way around this is to add an additional interface with the new methods. This is possible without the virtual extension methods, however, it has its own drawback. Namely, that the implementation of that new interface needs to be added before it can be used. Since there are probably a lot of implementations out there today it may take a long time to get all those implementations upgraded. However, at the same time the

Categories : C#

Extension methods for both IDictionary and IReadOnlyDictionary
You only need one extension method. Redefine it as follows: public static TValue? GetNullableKey<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> dictionary, TKey, key) where TValue : struct { // Your code here. // Per @nmclean: to reap performance benefits of dictionary lookup, try to cast // dictionary to the expected dictionary type, e.g. IDictionary<K, V> or // IReadOnlyDictionary<K, V>. Thanks for that nmclean! } Both IDictionary<TKey, TValue> and IReadOnlyDictionary<TKey, TValue> inherit from IEnumerable<KeyValuePair<TKey, TValue>>. HTH. UPDATE: To answer your comment question If you don't need to call methods that only appear on one interface or the other (i.e. you're on

Categories : C#

Lambda Expressions and Extension methods
Extension methods don't add a method to the type's definition. They are merely syntactic sugar for a static method call. The Type that you are passing in for the containing type of FormatStrign is for string, but it should be for whatever type FormatString is defined in. If you defined it in a class called StringExtensions then that is the Type you need to pass in.

Categories : C#

Default Value for "this" parameter in C# Extension methods
Those are not comparable concepts. The first is compiler supported optional parameters, the second is meta-data default values for things like design tools (it has no direct compiler support for method calling in code). It is nonsensical to have a default value for the this parameter of an extension method because the value will be derived from the call target. My best guess as to why they don't support optional parameters for this in an extension method is limited returns (cost of implementation vs benefit to developer) and a confusion of coding style. Extension methods style themselves as fake extra methods on existing types, so this is pretty well fixed to the type you are extending. Wanting to change this is tantamount to wanting to change the style that extension methods are offerin

Categories : C#

Extension methods for both ICollection and IReadOnlyCollection
Given that they both inherit from IEnumerable<T> you could avoid the ambiguity issue by doing an extension on that instead: public static class IEnumerableExtensions { public static bool IsEmpty<T>(this IEnumerable<T> enumerable) { return enumerable == null || !enumerable.Any(); } }

Categories : C#

Do access modifiers affect extension methods?
private will hide the method from everybody, other than methods in the extension methods class (which is pointless). protected means nothing for static methods. You can make your class Internal so it will be hidden from other assemblies.

Categories : C#

Ninject: injecting inside extension methods
You can't do this with any DI container afaik because although you can define a constructor on a static class, that constructor must be parameterless. The only way I could see this working for you would be to either define CalculatePrice on instances of Product but the instance function simply passes through the call to the static method. Inject the dependencies into the instance via constructor and pass them via the static call within the instance call. Create a "helper" class that does the same thing (e.g ProductPriceHelper) and implement a Setup or Initialise method on it taking the dependencies, but you still will not* be able to have DI auto-inject for you - you'll have to do it manually somewhere in your composition rot (i.e wherever you currently do all your Ninject binding).

Categories : C#

Add C#-like extension methods for WebDriver using Java binding
Can't do much besides creating your own static methods (that will have to "wrap" instead of using the "after dot" extension method syntax), or create a wrapper class for the driver and add your methods there.

Categories : C#

Code Contracts vs if in Generic Extension methods
You can add Code Contracts to a class library without introducing a dependency on Code Contracts for any other assembly that uses that class library. The Code Contracts are implemented by a re-writer that changes the code that specifies the code contracts. The rest of the Code Contracts support is already baked in to .Net 4 or later, so other code can happily reference the library that uses Code Contracts without having to take any special steps. Therefore you can use Code Contracts in some assemblies without worrying about anything else that references those assemblies. Specifically, this statement is not true: The disadvantage is that this Tested Generic Class with Extension methods will not be reusable in another systems (which possibly will not use Code Contracts for validation)

Categories : C#

MVC4 DTO's and Many to Many Relationships with extension methods for WebAPI
I am going to assume that your Task has a IEnumerable called Groups. You need two extension methods in these kind of situations. One that will convert your child model and another that will convert the list of your child models. public static GroupDetail ToGroupDetail(this Group group) { return new GroupDetail { .. your mappings }; } public static IEnumerable<GroupDetail> ToGroupDetailList(this IEnumerable<Group> groups) { return groups.Select(g => g.ToGroupDetail()); } Then include following line in your ToTaskDetail after other properties. Groups = task.Groups.ToGroupDetailList() If the task.Groups is a IQueriable you need to change the ToGroupDetailList extension method to take a IQueriable instead of IEnumerable. Hope this helps

Categories : Asp Net Mvc

Is it good practice to use Extension methods just to set default properties?
Yes you definitely can do it that way. As extension methods are just syntactic sugar for static methods, and as you want to build some static helper method to configure a given instance of an object, it makes sense. Just for the sake of the completeness, control configuration are sometimes done using extension methods associated with a fluent interface: public static class DataGridExtensions { public static DataGrid AllowColumnConfiguration(this DataGrid grid) { // Add NRE check grid.CanUserResizeColumns = true; grid.CanUserSortColumns = true; grid.CanUserReorderColumns = true; return grid; } public static DataGrid AllowEdition(this DataGrid grid) { // Add NRE check grid.CanUserAddRows = true; grid.CanU

Categories : C#

Java 8: virtual extension methods vs abstract class
abstract classes cannot be root classes of lambda expressions, while interfaces with virtual extension methods can be. also abstract classes can have constructors and member variables, while interfaces cannot. i believe its the execution of a possible constructor, and the possible throwing of a checked exception that prohibits abstract classes from being the root of a lambda expression. so if you want to write an API that allows the user to use lambda expressions, you should use interfaces instead.

Categories : Java

.NET extension method conflict resolution of like named methods?
I'm going to guess that you "enabled" extension methods via the "ExtensionAttribute hack", which is how you have extension methods and not LINQ... As for why you're seeing this problem now, you've likely included this somewhere in the new code: using System.Linq; Since that brings System.Linq.Enumerable into scope, now you have ambiguity between your First and Linq's First - You can sorta control this with namespace aliasing...here's a throwaway example: using System; using System.Collections.Generic; // don't add this, lest you bring it in //using System.Linq; using Linq = System.Linq.Enumerable; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var values = new List<int>(Linq.Range(0, 10)); var us

Categories : C#

Can't compile LINQ extension methods on classes that derive from a class implementing IEnumerable
The problem is that MyList<T> implements IEnumerable<T> twice, so the compiler can't infer the type of the generic argument of Enumerable.Any<TSource>. You have to explicitly specify which T you want to use: var test2 = new MyList<int>().Any<Item>(); // or var test2 = new MyList<int>().Any<Item<int>>(); Unfortunately, the error message is not really good at transporting this information. If you call the extension method with the normal syntax, the message is very clear. Call: var test2 = Enumerable.Any(new MyList<int>()); Results in: The type arguments for method 'System.Linq.Enumerable.Any<TSource>(System.Collections.Generic.IEnumerable<TSource>)' cannot be inferred from the usage. Try specifying the type argume

Categories : C#

Creating class extension for a Class's private methods
Your createNewGameAgainst method is a class method (see the + in front of the method declaration). Your checkIfGameAlreadyExistsAgainst method is a instance method (see the - in front of the method declaration). To call checkIfGameAlreadyExistsAgainst from createNewGameAgainst you need to get an instance of MESGameModel. self inside of createNewGameAgainst references the class itself, not an instance of it.

Categories : IOS

ASP.NET MVC @helper syntax vs Html Helper Extension methods
They can be like user controls Vs Custom Controls Use @helper for razor style formatting in views. Use extension methods for generic solutions, for example overloading a label creation which takes additional parameters. You can find detailed explanation with examples here

Categories : C#

Why is IQueryable lacking all the extension methods that IQueryable has?
From the docs: The IQueryable interface is intended for implementation by query providers. It is only supposed to be implemented by providers that also implement IQueryable<T>. If the provider does not also implement IQueryable<T>, the standard query operators cannot be used on the provider's data source. IEnumerable is the artifact of the times when .NET did not have generics ( I don't mean to say it is deprecated, of course ). It has lived on for backward compatibility, after generics and hence IEnumerable<T> was introduced. IQueryable keeps up with that for consistency. Basically, given that there is generics now, and given the advantages, it makes it useful to implement these extensions only on the generic interfaces. The non-generic ones can always be converted

Categories : C#

Session has value but is not recognised
I added <?php $username = Session::get('username'); ?> and {{ Session::flash('username', $username) }} in uservalid.php so when page is refreshed it display the same page (which is correct) and also when page is open in new window, it doesn't log out or anything now unlike before it kinda seem iffy to me though .. any suggestion/s ?

Categories : PHP

Class not being recognised
LinkedListIter is a class template, not a class. So your operator needs to be a template also. template<typename a, typename b> std::ostream& operator<< (std::ostream& o, LinkedListIter<a,b> const & lli){ ...

Categories : C++

Guid format is not Recognised
I tried to use var id = Guid.Parse("7590aab2-29b9-4262-9982-4403ca7b52f2"); and it worked perfect.So the culprit is the ddlProjTemplates.SelectedValue and make sure it has value. Use the following Guid result; if(Guid.TryParse(ddlProjTemplates.SelectedValue ,out result) { ///do your stuff here }

Categories : C#

How do get this variable to be recognised later in the method?
You need to define response outside of the if statement: int response = -1; if (number2 > 0) { response = /* ... Something ... */ } else { response = /* ... Something else ... */ }

Categories : Java

gluUnProject() is not recognised during build
collect2: ld returned 1 exit status This is a cryptic but common error from the linker (named ld), you have likely included the header for openGL-ES, but neglected to actually link against the library.

Categories : Android

URL is not a recognised format, can I convert
Ok, based on your question and a comment in another answer, it sounds like you have the blob name but not the full URI. The full blob uri is going to be http(s)://<cloudstorageaccountname>.blob.core.windows.net/<containername>/<blobname> Since you're already working with a container object, you must have already acquired the storage account name (probably from one of your app settings), as well as your container name (since you already have a container object). At this point, you should easily be able to assemble the full name. Note that you can choose either http or https. If you're connecting from your web/app tier straight to storage, go with http as traffic stays within the data center. If, on the other hand, you're creating links to embed in a web page to the en

Categories : C#

fetchObjectsForEntityName: not recognised as valid method
Because the method doesn't exist. I guess you copied some code from a tutorial but you didn't copy all of it. There should be a category on NSManagedObjectContext which defines and implements the method.

Categories : Iphone

XMLType View column not recognised
Resolved. I changed the view to something like create or replace VIEW SS_CDRS_EXPORT_COMP_XML AS select XMLELEMENT("CM_DATA", XMLFOREST(TRIM(V.COMPNAME) AS COMPANYNAME, .... )) AS "RESULT" FROM v; and the line in the button press code to .. CURSOR C IS SELECT X.RESULT.GETSTRINGVAL() FROM SS_CDRS_EXPORT_COMP_XML X;

Categories : SQL

Element IDs are not being recognised and are not triggering function
The problem: ID's are meant to be unique identifiers. You should be using classes if you want to identify multiple elements. For this reason, when you select by ID with $("#font"), jQuery (which uses native javascript's getElementById) will only return the first element it comes across that has that ID. This is because if the DOM is valid, it shouldn't find anymore instances of that ID and it would be a waste of processing to continue looking. A solution: Remove the font ID's from your divs and replace them with a class instead, like class="font". Since you already have some classes identified, you can use multiple classes separated by spaces, like: class="font minecrafter". After doing this, you will be able to select your elements with the font class using this selector: $(".font")

Categories : Javascript

Importing CSV to Django and settings not recognised
Make sure Django, and your project are in PYTHONPATH then you can do: import urllib2 import csv import requests from django.core.management import setup_environ from django.db import models from yoursite import settings setup_environ(settings) from gmbl.models import Match master_data_file = urllib2.urlopen("http://www.football-data.co.uk/mmz4281/1213/E0.csv", "GET") data = list(tuple(rec) for rec in csv.reader(master_data_file, delimiter=',')) # ... your code ... Reference: http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/ Hope it helps!

Categories : Django

Why the XUnit attributs aren't recognised?
You are using C# attribute syntax in VB.NET. VB.NET syntax would be <Fact> Public Sub FactMethodName() Write(DateTime.Parse("1658").ToString()) End Sub and so on.

Categories : Vb.Net

Compilation error, list not recognised
The difference is that the * does not import sub-levels, but only everything in the current level. If you used import gnu.trove.list.array.*, it would work as you expect. The reason it works on java.util.* is because the ArrayList class is in the same folder as the wildcard.

Categories : Java



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.