w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
No matching constructor found on type. You can use the Arguments or FactoryMethod directives to construct the type
Turns out after much pain re-installing .NET Framework 4, applying various KB patches up to and including the runtime 4.0.3. the problem was caused by an ILMerge msbuild step. The build process included a msbuild task after build to merge the main executable with some dll's. I removed this ILMerge step and the error disappeared. Not sure why this occured on this environment and not on any of our test machines but its working now.

Categories : C#

In go, how to create a constructor for a type without any arguments
Although it is definitely not idiomatic Go, you could do something like this: type Response map[string]interface{} func (r *Response) New() { *r = make(map[string]interface{}) (*r)["hello"] = "World" (*r)["high"] = 5 } func main() { var r Response r.New() for k, v := range r { fmt.Printf("%s = %v ", k, v) } } But really, there's nothing wrong with func NewResponse() Response.

Categories : Go

What is the purpose of type arguments in constructor call following new?
Constructors can declare type parameters too public class Main { public static class Foo<T> { public <E> Foo(T object, E object2) { } } public static void main(String[] args) throws Exception { Foo<Integer> foo = new <String> Foo<Integer>(1, "hello"); } } That's what the <String> preceding the constructor call is for. It is the type argument for the constructor. The following Foo<Integer> foo = new <String> Foo<Integer>(1, new Object()); fails with The parameterized constructor Foo(Integer, String) of type Main.Foo is not applicable for the arguments (Integer, Object) In your last Foo<Integer> t5 = new <NotDefined> Foo<Integer>(); // fails

Categories : Java

Unless constructor argument passed is a hash type, croak on invalid arguments?
We can look at the various ways your dump method can be called. If we pass a "hash list", the number of elements is even (@_ % 2 == 0). Also, if at least one key-value pair is present, the first argument (a key) is a string, so not defined reftype $_[0] holds. If we pass a hash reference, then the argument list should only hold this reference, and no other values: @_ == 1. The first argument will be a hash: reftype($_[0]) eq 'HASH'. So to put the arguments in a hash reference, one could do something like: sub dump { my $invocant = shift; my $hashref; if (@_ == 1 and reftype $_[0] eq 'HASH') { $hashref = $_[0]; } elsif (@_ % 2 == 0 and (@_ == 0 or not defined reftype $_[0])) { $hashref = +{ @_ }; } else { croak "Unknown argument format: either pass a hashref, or an

Categories : Perl

Mongo/DataNucleus/JPA with embedded type query gives: Cannot find type of (part of) ... since symbol has no type; implicit variable?
FINE: Compilation of filter to be evaluated completely in-datastore was impossible : Invoke expression is not supported by this mapper so it is not currently implemented to convert JPQL "collField.contains(val)" (the equivalent of what you typed in for your query) into a MongoDB query, hence cant evaluate it in the datastore. Since you know what it needs converting into, you can easily enough get the code for the DataNucleus MongoDB plugin and find class QueryToMongoDBMapper and contribute support for that particular query.

Categories : Mongodb

.net dictionary object type
"1.5" is not a valid type name in any common .NET language, they insist you start a type name with a letter. Important to make the job of a lexer simple, the part of the compiler that preprocesses the source code into tokens before the program is parsed. A lexer will identify "1.5" as a number, not an identifier. The CLR has much more lax rules about that however, just about anything goes for a type name. This is taken advantage of by obfuscators. A program that you run after building an assembly that makes it difficult to reverse-engineer the source code from the assembly. There are several very good decompilers available for .NET, like Reflector and ILSpy. An obfuscator is designed to defeat them. High odds that the assembly you are using was obfuscated.

Categories : Dotnet

C++11 variable number of arguments, same specific type
A possible solution is to make the parameter type a container that can be initialized by a brace initializer list, such as std::initializer_list<int> or std::vector<int>. For example: #include <iostream> #include <initializer_list> void func(std::initializer_list<int> a_args) { for (auto i: a_args) std::cout << i << ' '; } int main() { func({4, 7}); func({4, 7, 12, 14}); }

Categories : C++

Type error with dictionary object
Since the ASPXHiddenField does not support an integer in a dictionary object, I made it into a . During the JS function, I was missing one thing to do. I changed the value from: dict[key] = parseInt(qty, 10); to dict[key] = qty.toString(); and that solved the issue...

Categories : C#

getting the type of parameters passed in a variable arguments list
I'd rather consider passing tuple or array or a vector. As std::array is template with N, it is possible to make your function a template with N too, and implement in a generic way. Variadic template is also viable if your complier is good for it. The ... is something we try to get rid of. It's undefined behavior to pass anything non-POD, and no type check is possible. What makes it way too prone to errors. For your case it is not very helpful either.

Categories : C++

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[X]', but this dictionary requires a model item of type 'X'
Take this at face value - yours is not unique. Your problem is you are passing an array of user to a controller action that expects a user. You need to post your HTML but it is probably something like @model List user or something instead of a single user. If your model represents a single user then pass that to the controller. If opposite, do opposite, If you want to pass a list to the controller use list users edit make your razor syntax @model Mike.Models.User

Categories : Asp Net Mvc

C# declaring array in class with not constant type variable through constructor
private readonly short DeckSize; private readonly char[,] Deck; public HandDeck(short Size) { DeckSize = Size; Deck = new char[DeckSize, 2]; }

Categories : C#

Exception "No suitable constructor found for type [simple type..." while parsing XML file to POJO by fasterxml
R and AttSearch should be static: public static class R { // other stuff public static class AttSearch { // other stuff Otherwise compiler create default constructor with outer class reference as parameter, so fasterxml can't find constructor without parameters and create pojo.

Categories : Java

Query on Junit @parameters method's return type and the test class constructor argument type
As you suggested the values are being casted. The casting is actually done by the Java reflection API, specifically: Constructor.newInstance(Object...). If you're curious, the above method is invoked by JUnit on line 186, here (JUnit v4.11 source).

Categories : Java

Can Java infer type arguments from type parameter bounds?
Two things I've noticed: CAP#1 is not a wildcard, it is a type variable because of capture conversion. On the first step, the JLS mentions that U is the type expression while Tj is the type parameter. The JLS does not explicitly define what a type expression is, but my gut feeling is that it includes the bounds of the type parameter. If that is the case, U would be C extends Foo<A,B> and V would be CAP#1 extends Foo<CAP#2, CAP#3>. Following the type inference algorithm: V = U -> C = CAP#1 AND Foo<CAP#2, CAP#3> = Foo<A, B> You can continue to apply the type inference algorithm to the above, and you will end up with A= CAP#2 and B=CAP#3. I believe you have spotted a bug with Oracle's compiler

Categories : Java

A subclass type as parameter type in superclass constructor java
Use Inheritance public interface Node{ //... } public class SimpleNode implements Node{ //... } public class ComplexNode implements Node{ //... } Then, you can add a Constructor like that: public class SimpleNode implements Node{ public SimpleNode(int numberOfNode){ //... } }

Categories : Java

The type JComboBox is not generic; it cannot be parameterized with arguments
Change the below lines public JComboBox<Object> leftAICombo; public JComboBox<Object> rightAICombo; to public JComboBox leftAICombo; public JComboBox rightAICombo; Here JComboBox<Object> type parameter introduced in java7 only.if you are using jdk below 7 it gives error

Categories : Java

Cannot get moq to create a instance from a type - "No parameterless constructor defined for this object."
You are creating an instance of record.GetType() and since record = recordStub.Object which is an object dynamically generated by Moq at run-time that implements IRecord in your situation then what you are essentially doing is creating an instance of a dynamically generated object and it seems that Activator.CreateInstance() can't find a public constructor that takes no arguments on that type. Now i don't know why are you doing what you are doing but i have never seen anyone using a Mock like that so i think you should reconsider your test.

Categories : Dotnet

Setting default value in Oracle Object Type Constructor Function
In your second code block, you aren't calling the constructor that only has two arguments. Passing a null argument doesn't mean you use the other constructor, you're calling the (default) constructor with four arguments, two of which just happen to be intentionally null. You're effectively doing: TYPE_MAIN(col1 => '1', col2 => NULL, col3 => NULL, col4 => NULL) not TYPE_MAIN(col3 => '1', col4 => NULL) So this works: INSERT INTO TAB_MAIN(PKEY,COLTEST,COLNEW) VALUES(1,'TESTCOL2',TYPE_MAIN('3','4')) / ... PKEY COLTEST COLNEW ---------- --------------- -------------------------------------------------- 1 1 TESTCOL TYPE_

Categories : Oracle

Issue with Dictionary type, If gived a specific text then get the equivalent dictionary key or dictionary value?
If this were my application, I would change the UI element to a datagridview so that I could bind a collection containing a custom class and just hide or show the appropriate columns as needed. This approach will allow you to easily add additional property columns in the future without worrying about the problems you are currently facing. It would also allow you to extend the UI to other platforms (mobile, web) without a lot of hard-coded information in the UI. For example, I would create the following class and collection to hold info about the files: Public Class FileDetails Public Property Index As Integer Public Property Description As String = String.Empty Public Property FullFileName As String = String.Empty Public ReadOnly Property FileName As String Get

Categories : Dotnet

How to make Generic Type as out type if it is reference Type?
If you have an error with the return type of IEnumerable<IGrouping<string, MyClass>> in a generic class that has been declared using <T>, then I'm guessing that your return type should actually be IEnumerable<IGrouping<string, T>>... of course, without seeing your code, this can only be a guess.

Categories : C#

Abstract type in constructor instead of Concrete type
You want an abstract base class: public abstract class BaseClass { // Use protected fields to store data that only this class and derived // classes can access. protected List<Something> storedSomethings; //Define an abstract method signature for methods that the concrete classes // have very different implementations for: public abstract List<Something>GetSomethings(); //Use a virtual method for methods that are identical or similar on //the concrete classes: public virtual void AddSomethings(List<Something> addList) { storedSomethings.Add(addList); } } Then your concrete classes are implemented like so: public class Concrete1 : BaseClass { public override List<Something> GetSomethings() { //ac

Categories : C#

C Casting a variable of type double to a variable of type char when freeing memory
I have to agree with you - that code is a bit weird. There's no reason the author couldn't have used void ** just as easily. In addition, the if (*ptr != NULL) check is unnecessary, since free(NULL) is perfectly legal. The ; characters after the braces aren't necessary either. A simpler version might look like this: static void free_and_null(void **ptr) { free(*ptr); *ptr = NULL; } The reason this function exists at all is to make sure that freed pointers are set to NULL, which is helpful for detecting use-after-free bugs and avoiding double-free bugs entirely. Edit: As StarPilot suggests below, it's probably a good idea to check that ptr itself isn't NULL: static void free_and_null(void **ptr) { if (ptr) { free(*ptr); *ptr = NULL; } }

Categories : C

Dictionary of >
You could use the following static class public static class GenericLists { private static Dictionary<Type, object> MyDict = new Dictionary<Type, object>(); public static void NewEntry<T>() { MyDict.Add(typeof(T), new List<T>()); } public static List<T> GetEntry<T>() { return (List<T>)MyDict[typeof(T)]; } public static void RemoveEntry<T>() { MyDict.Remove(typeof(T)); } } Or you could use public class GenericLists<T> { private Dictionary<Type, List<T>> MyDict = new Dictionary<Type, List<T>>(); public void NewEntry() { MyDict.Add(typeof(T), new List<T>()); } public List<T> GetEntry() { retur

Categories : C#

Assign custom object into Object type variable in SSIS
I don't have enough reputation to comment so I'm adding an answer instead. I did the below steps to try and replicate your problem: Created a new script task Created a new class in the namespace of that script Created a variable of type Object and added to script task as Read/Write variable Initialised the new class and assigned that value to the Object variable. Below is my code which ran successfully. Can you please explain if there is any thing I am missing/understanding wrong? using System; using System.Data; using Microsoft.SqlServer.Dts.Runtime; using System.Windows.Forms; namespace ST_8eab6a8fbc79431c8c9eb80339c09d1d.csproj { public class myclass { int a, b; public myclass() { a = 0; b = 0; } } [System.AddIn.AddIn("ScriptMain", Version = "1.0"

Categories : C#

Typescript Error Message error TS2173: Generic type references must include all type arguments
That line should have been: promise(type?: any, target?: any): JQueryPromise<any>; I'll send them a pull request. Thanks. JQueryPromise is a generic interface. i.e. it takes type parameters. Starting with TS 0.9.1.1 they are more strict about generic parameters. They must be specified from now on. This was allowed in previous versions (where the type was assumed to any implicitly) but the compiler analysis is stricter now (and the type must be specified explicitly).

Categories : Typescript

How to make variable type polymorphism work?
As pointed out in the comments, templates can indeed have virtual functions. However this is not going to solve your problem. In fact, you would need those functions to have different return types. This is a possible template-based solution to your problem, it might not be the most elegant but you (we) can work on this basis #include <iostream> using namespace std; template <typename T, template<typename> class Accessor, template<typename> class Traits> class Node{ public: Node() : data(5.){} typedef typename Traits<T>::type getType; getType get(){ return static_cast<Accessor<T>*>(this)->implementation(); } virtual ~Node(){} protected: T data; }; template <typename T>

Categories : C++

Avoid repeating the variable type: Return Type Resolver, C++11 auto, ...anything else?
Here is a way to package the boilerplate up in one spot for every return type deduction function: // usual sequence boilerplate: template<unsigned... s> struct seq { typedef seq<s...> type; }; template<unsigned max, unsigned... s > struct make_seq:make_seq<max-1, max-1, s...> {}; template<unsigned... s> struct make_seq<0, s...>:seq<s...> {}; // RTR object, which wraps a functor F to do return type deduction: template<template<typename>class F> struct RTR { // Stores a `tuple` of arguments, which it forwards to F when cast to anything: template<typename... Args> struct worker { std::tuple<Args...> args; worker ( Args&&... a ):args(std::forward<Args>(a)...) {} template<typename T, unsigned.

Categories : C++

How to make this template which using typedefed type in template constructor copmiles?
Not sure how it got compiled in VC++ But following compiles with MinGW g++ 4.7.2 #include <iostream> template <typename T> struct W { typedef T TT; W(const TT & m) // remove typename W<int> or use W(const W::TT & m) { std::cout << "here" << std::endl; } }; int main() { int f; W<int> k( f ); return 0; }

Categories : C++

How to prevent type from being used as a member variable type in a struct/class?
If you can use an object outside of a class, it can be a member of a class. I'm 99.9% sure that you can't stop that in any way (that doesn't restrict how/where you can use T in other ways - clearly having a private constructor would prevent it from being a direct member of a class, but it would also restrict it from being used in the other three scenarios you are showing).

Categories : C++

Does a variable of an interface type act as value type if the underlying implementation is a struct?
No, interface is a contract, to make it work properly you need to use ref keyword. public void SetInterfaceProp(ref IMyInterface thingy) { thingy.desc = "the implementing type is a struct"; } What matters here is a real type that stays inside that interface wrap. To be more clear: even if code with method SetInterfaceProp defined like public void SetInterfaceProp(IMyInterface thingy) { thingy.desc = "the implementing type is a struct"; } will work: IMyInterface inter= default(MyStruct); SetInterfaceProp(inter); this one will not : MyStruct inter = default(MyStruct); SetInterfaceProp(inter); You can not gurantee that the caller of your method will always use IMyInterface, so to guarantee expected behavior, in this case, you can define ref keyword, that will guaran

Categories : C#

Variable store function as primitive type or reference type?
The value of f2 is, like f1, a reference to the same function. You can use the fact that functions are objects to prove it : var f1 = function(){} var f2 = f1; f1.a = 3; console.log(f2.a); // logs 3 But as you can't change a function core, there is little practical use in knowing this, apart the fact you don't use much memory if you duplicate a function reference.

Categories : Javascript

Add variable number of items of one type when creating item of another type
Let's assume your Item A is a Person and Item B is a Project. So, for what you said, a Person has_many Projects. (I decided to use "real world" resources, instead of Item A and Item B for the clarify of the example). Here is how you would define your models associations: class Person < ActiveRecord::Base has_many :projects accepts_nested_attributes_for :projects end class Project < ActiveRecord::Base belongs_to :person end Then, the form of your Person would look like this: <%= form_for @person do |person_form| %> ... <%= person_form.fields_for :projects do |project_builder| %> # Here goes the fields of the projects <%= project_builder.text_field :name %> <% end %> ... <% end %> The key here is fields_for method, which will

Categories : Ruby On Rails

How to reference an already existing type variable in a haskell type spec?
Check http://www.haskell.org/haskellwiki/Scoped_type_variables From the link: Scoped Type Variables are an extension to Haskell's type system that allow free type variables to be re-used in the scope of a function.

Categories : Haskell

How to create an object by pulling the type from a variable?
I would suggest using a factory interface for GameObject creation, with an implementation for each type (like arynaq mentioned in the comments): interface GameObjectFactory { GameObject create(); // this could also take arguments like x, y, and parent } private static final Map<Integer, GameObjectFactory> FACTORIES_BY_ID; static { final Map<Integer, GameObjectFactory> factoriesById = new HashMap<>(); // ID 42 is for walls factoriesById.put(42, new GameObjectFactory() { @Override public GameObject create() { return new Wall(); } }); //etc. FACTORIES_BY_ID = factoriesById; } You could also use an array if the IDs are sequential: private static final GameObjectFactory[] FACTORIES = { // ID 0 is for w

Categories : Java

How to fix Sys.ArgumentTypeException: Object of type 'Object' cannot be converted to type 'Function'
The remove_endRequest accepts function that you want to remove from the list of handlers for endRequest Event. So the code you provided has invalid parameter because call of $(document).ready() returns the jQuery "wrapper" object instead of handler function. If you want to call code after the end of async postback you should use add_endRequest and remove $(document).ready since it is not tied to the async postback events. <script type="text/javascript"> function Navigate() { $('#dialogDiv').dialog('open'); } function myEndRequestHandler() { var list = ""; $('#dialogDiv').dialog({ autoOpen: false, resizable: true, width: 300, height: 'auto', buttons: { "Save": function (

Categories : C#

Check if a type implements a generic interface without considering the generic type arguments
As far as I know, the only way to do this is to get all interfaces and see if the generic definition matches the required interface type. bool result1 = type.GetInterfaces() .Where(i => i.IsGenericType) .Select(i => i.GetGenericTypeDefinition()) .Contains(typeof(MyInterface<,>)); EDIT: As Jon points out in the comments, you could also do: bool result1 = type.GetInterfaces() .Where(i => i.IsGenericType) .Any(i => i.GetGenericTypeDefinition() == typeof(MyInterface<,>));

Categories : C#

How to pass a Range type value to a String Type variable
You don't need to conver the Range to a string, you need to use its address property, which is already a string Sub SelectRange() Dim Rng1 As Range Set Rng1 = Application.InputBox("select cell", Type:=8) MsgBox ("You selected " & Rng1.Address & "as the range") End Sub

Categories : String

C#, instantiating a generic type - with variable type argument?
You can do it with reflection var entryType = typeof(Entry<>); Type[] typeArgs = { o.GetType() }; var genericType = entryType.MakeGenericType(typeArgs); IEntry entry = (IEntry)Activator.CreateInstance(genericType);

Categories : C#

How can I cast a subset of a dictionary to a type derived from Dictionary<>
You get an invalid cast exception because the result of ToDictionary is not MyDict. In order to fix this problem, add a constructor to MyDict that takes an IDictionary<string,A>, and return the result of calling that constructor from your GetSubSet method: public class MyDict : Dictionary<string, A> { public MyDict() { // Perform the default initialization here ... } public MyDict(IDictionary<string,A> dict) { // Initialize with data from the dict ... } } ... public MyDict GetSubSet(int testVal) { var ret = dict.Where(e => e.Value.aValue == testVal). ToDictionary(k => k.Key, k => k.Value); return new MyDict(ret); }

Categories : C#

Java Pass instance type of Object to generic class type parameter
No.. generic type should be known at compile time. Generics are there to catch possible runtime exceptions at compile time itself. List<Integer> list = new ArrayList<Integer>(); //..some code String s = list.get(0); // this generates compilation error because compiler knows that list is meant to store only Integer objects and assigning the value got from list to String is definitely an error. If the generic type was determined at run-time this would have been difficult.

Categories : Java



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