w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Webgrid: Cannot convert lambda expression to type 'object' because it is not a delegate type
You can't use embedded razor strings within the lambda expression, as @Alessandro D'Andra suggests you have to use x => "<img src='" + someString + "'></img>"; instead. You might also have to wrap it all in an MvcHtmlString to prevent Razor from escaping the string once it is used by the formatter, but I don't know exactly how the formatter works - you have to try it. I made a small test file to find out exactly what the Razor compiler would do with your code. This is the razor file: @{ string someString = "somestring"; Func<object, object> a = x => "<text><img src='" + someString + "'></img></text>"; Func<object, object> b = x => @<text><img src="@someString"></img></text>); } The ASP.NET

Categories : C#

WPF: Cannot convert lambda expression to type 'string' because it is not a delegate type
Your NotifyPropertyChanged expects a string, and you're passing it a delegate. Try: public string SelectedTransactionName { set { if (_selectedTransactionWsName == value) return; this._selectedTransactionWsName = value; // InitializaMessageElement(value.WsMethodName, transactionTypes); InitializaMessageElement(); this.NotifyPropertyChanged("SelectedTransactionName"); this.NotifyPropertyChanged("IsTransactionNameSelected"); } get { return this._selectedTransactionWsName; } }

Categories : Wpf

MVC Cannot convert lambda expression to type because it is not a delegate
Found what happens. The asp.net tags are not allowed in the SetContent() that way. The correct way to do it is: CBsettings.SetContent(() => { ViewContext.Writer.Write("<h1>Hello World</h1>"); ... }); So sad the intellisense doesn't give a clue about what is wrong.

Categories : C#

Cannot convert lambda expression to delegate type
I think you just have your syntax off a bit. Try: public user GetUser(int intUserID) { using (var context = new iomniEntities()) { user u = context.users.Where(u => u.userID == intUserID).FirstOrDefault(); return u; } } Or to hold onto your version, it just needs touched up: public user GetUser(int intUserID) { using (var context = new iomniEntities()) { user u = context.users.FirstOrDefault(user => user.userID == intUserID); return u; } }

Categories : SQL

Convert async lambda expression to delegate type System.Func?
No can do. When someone expects a Func<T> f you can assume it will be invoked with something like result = f() - i.e., it does not know about async behavior. If you cheat it by using .Result like you have - it will deadlock on UI thread because it wants to schedule the code after await (in _Fetch) on the UI thread, but you have already blocked it with .Result. Async lambda can be passed to Action since it has no return value - or to Func<Task> or Func<Task<T>>. Looking at your case, the GetOrCreateObject appears to be calling GetOrFetchObject. One of the GetOrFetchObject overloads accepts a Func<Task<T>>. You can try calling that method with your async lambda and see if it helps.

Categories : C#

LinqPad Error: Lambda expression cannot be converted to 'String' because 'String' is not a delegate type
The problem appears to be that one or more of the properties of object "p" is not a string. However, you most likely are misunderstanding what .Include does. It eager-loads whichever related tables you specify. So if you had: Dim projects = From p In db.Projects.Include("Managers") it would eager-load all of the related records from your "Managers" table for each row in your "Projects" table when the query is executed. Somehow, I don't think this is what you are trying to accomplish with the code you posted.

Categories : Vb.Net

Argument type 'lambda expression' is not assignable to parameter type 'System.Action'
I doubt this has anything to do with mvvmcross or mvvm A quick search for this error message suggests this is more likely to be down to tooling - especially r# - eg see hits like: http://devnet.jetbrains.com/thread/292248 http://caliburn.codeplex.com/discussions/212685 http://youtrack.jetbrains.com/issue/RSRP-178647?projectKey=RSRP If you are running any extensions like r# and you remove or disable them, then this may remove the warning. If disabling them helps, then I would recommend asking the extension vendor(s) for support. If disabling them does not help, then I would recommend investigating the differences between the two projects where the problem does/doesn't occur - that will hopefully yield the answer.

Categories : C#

Cannot convert expression type error in generic method
If you really need to have the same MouseDown handler for both UserControls, you may write it like this: private void OnRightMouseDown(object sender, MouseButtonEventArgs e) { var uc01 = sender as UserControl01; if (uc01 != null) { uc01.ViewModel.IsSelected = true; return; } var uc02 = sender as UserControl02; if (uc02 != null) { uc02.ViewModel.IsSelected = true; } } Anyway, the better solution would be to have two handlers: private void UserControl01_RightMouseDown(object sender, MouseButtonEventArgs e) { ((UserControl01)sender).ViewModel.IsSelected = true; } private void UserControl02_RightMouseDown(object sender, MouseButtonEventArgs e) { ((UserControl02)sender).ViewModel.IsSelected = true; }

Categories : C#

Cannot implicitly convert type 'string' to 'bool' CheckBox
chkNewEmployee.Checked = Convert.ToBoolean(dr["chkNewEmployee"]); ToBoolean: true or false, which reflects the value returned by invoking the IConvertible.ToBoolean method for the underlying type of value. If value is null, the method returns false. Depending on your needs you may want to try bool.Parse or bool.TryParse UPDATE bool.Parse, bool.TryParse and Convert.ToBoolean: are case insensitive ignore leading and trailing white space bool.Parse: correct value is either true or false throws FormatException in case of failed conversion bool.TryParse: correct value is either true or false doesn't throw exception in case of failed conversion return true if conversion succeeded, otherwise false conversion result is saved via second parameter (out bool result) Convert.

Categories : C#

Synat error - The type of the expression must be an array type but it resolved to String
Well yes - data is a String, and you can't use an indexing expression like data[i] on a string. Perhaps you want: if (b.toString().equals(data.substring(i, i + 1)) Although it's far from clear that that's a good idea. Byte.toString probably doesn't do what you expect it to. Perhaps you actually want: if ((char) b == data.charAt(i)) ?

Categories : Java

Cannot convert type 'DelegateType' to 'System.Delegate'
Indeed, you cannot specify a : Delegate constraint - it simply cannot be done (the compiler stops you). You might find it useful to add a where DelegateType : class, just to stop usage with int etc, but you can't do this all through generics. You will need to cast via object instead: (Delegate)(object)d However, personally I think you should be storing DelegateType, not Delegate, i.e. protected class PrioritizedDelegate : IComparable { public DelegateType d; public int priority; public PrioritizedDelegate(DelegateType d, int priority) { this.d = d; this.priority = priority; } } Note I removed the <DelegateType> from the above: because it is nested inside a generic type (PrioritizedEvent<DelegateType>) it already inherits this from the

Categories : C#

Cannot implicitly convert type 'System.Linq.IQueryable' to 'bool'
context.SomeTables.Where(p => p.FileName == System.IO.Path.GetFileName(file)) returns an IQueryable, not a bool. You need something that returns a bool, like context.SomeTables.Any(p => p.FileName == System.IO.Path.GetFileName(file)) as your condition for the if statement. See Also Enumerable.Any Method (IEnumerable)

Categories : C#

[HASKELL]Couldn't match expected type `[a0]' with actual type `[a1] -> Bool'
null is a function [a] -> Bool and returns whether the input list is empty. Therefore sStringV has type [a] -> Bool. In the line if (null sStringV == True) the argument to null should be a list, not the null function itself. It seems you should change the declaration of sStringV to something like sStringV :: String sStringV = "" However, you should be aware that let sStringV = lines contents does not assign a new value to sStringV - it only declares a new variable sStringV which hides the old definition. You can't modify sStringV from within your readMyFile function. It looks like you're trying to use Haskell like an imperative language.

Categories : Haskell

the built-in type bool in C++ or the stdbool.h type in C defines TRUE and FALSE as not the size of the machine word?
On SOME machines, int may be easier to handle than a byte-sized object. But for many processors, an int is no easier to deal with than a byte-sized integer. Since a byte takes less space (at least if you don't stick it next to an int so that the compiler needs to pad it), then you benefit in doing so in some situations. I don't think the standard says anything about what size it actually MUST be. Edit: As the comment says, the C++ standard specifically says that the size is implementation defined, and is not required to be 1 (but it also doesn't say it CAN'T be 1). The standard also says that the value of a bool is true or false, but that if you "use" an uninitialized variable of type bool, it is undefined behaviour, and it can be something that is neither of those values. There are a

Categories : C++

c++ std::map asignation error : cannot convert ' type **' to 'type *' in assignment
void findMessageId(R * aPointerType,const int & aPKValue, int & aResult) { if (aPKValue < 0) { aResult=-1; return; } //buscar valor dentro de la lista mMessageListIterador=mListMessage->find(aPKValue); if (mMessageListIterador!=mListMessage->end()) { aResult=0; aPointerType=&mMessageListIterador->second; } else aResult=-1; return; } In this method i changed this line: aPointerType=&mMessageListIterador->second; for this: aPointerType=mMessageListIterador->second;

Categories : C++

Using a strong enum (C++11) of type bool fails for template bool argument, why?
Strongly typed enums mean that you can only, implicitly, compare and assign values in the same enum class. The solution is to use a non-strongly typed enum example: enum test : bool { yes, no }; bool x = test::yes; // ok Or as suggested by Tom Knapen: explicitly cast the enum enum class test : bool { yes, no }; bool x = static_cast<bool>(test::yes); // ok

Categories : C++

LINQ To XML error: type of the expression in the select clause is incorrect. Type inference failed in the call to 'Select'
The problem is with your closing parenthesis - you've got it at the end of the ToList() call, when you meant to put it at the end of the object initializer. Also, you're not actually calling the method - you're just specifying a method group. Finally, you can let type inference work out the type argument for you: List<Data> dogs = (from q in doc.Descendants("dog") where (string)q.Attribute("name") == dogName select new Data { name = q.Attribute("name").Value, breed = q.Element("breed").Value, sex = q.Element("sex").Value }).ToList();

Categories : C#

g++ gives error : invalid initialization of reference of type ‘char&’ from expression of type ‘unsigned char’
Why isn't it possible to initialize 'char &' with a variable of type 'unsigned char' while it is possible to initialize 'const char &' with it? Because the latter creates a temporary to bind to the const reference when the unsigned char is converted to a char, something you can't do with non-const references. char, signed char, and unsigned char are three distinct types, as explained in C++11 § 3.9.1: Plain char, signed char, and unsigned char are three distinct types

Categories : C++

Convert lambda to custom delegate
It's interesting that you say that you had no such issues in a different VS2010 project. It would be good to see what that code (which works) looks like. Are both the source project and the consuming project set to target the same .Net Framework version and possibly also using the same Tools version? Maybe the compiler is having trouble inferring the types - try making the lambda parameters explicitly typed, and/or explicitly casting the lambda to the delegate type: Instruction<string, bool> instruction = (CancellationToken cancellationToken, Action reportProgress, string argument) => SomeOperation(argument); Instruction<string, bool> instruction = (Instruction<string, bool>)((CancellationToken cancellationToken, Action reportProgress, string argument) => SomeOp

Categories : C#

Expression.Convert using type that isn't included
AS DAL.Foo is closer(in current assembly) than DTO.Foo (in an included assembly) hence the compiler picks it up first. It is expected and consistent behaviour, not a bug. You need to specify the name explicitly so, change this x => ((Foo)x).Bar, to x => ((DTO.Foo)x).Bar,

Categories : C#

Is there a use for a delegate type that returns a delegate of the same type as itself?
I have an example of some similar code that isn't exactly a recursive delegate, but it comes close. A "Y-Combinator" comes close - and quite frankly I have no idea how it works in practice, but it is used to define recursive functions. Here's the funky code you need to define: public delegate T S<T>(S<T> s); public static T U<T>(S<T> s) { return s(s); } public static Func<A, Z> Y<A, Z>(Func<Func<A, Z>, Func<A, Z>> f) { return U<Func<A, Z>>(r => a => f(U(r))(a)); } Now you can define recursive functions in one line. Factorial: var fact = Y<int, int>(_ => x => x == 0 ? 1 : x * _(x - 1)); var fact5 = fact(5); // == 120 var fact6 = fact(6); // == 720 var fact7 = fact(7); // == 5040 Fibonacci:

Categories : C#

Cannot convert HomeScreen expression to type MonoTouch.UIKit.UIViewController
I asked around on the Xamarin forums aswell and they suggested me to retry to delete the ViewController and remake it because likely the cause is that it didn't create a .h file. After doing that, I launched the debugger using the simulator and now it works. The cause was that it didn't create a .h file when I opened the .xib file in Xcode. The solution was given me here For anyone else that comes across this issue, I hope this helps for you aswell.

Categories : C#

Delegate types and covariance with a generic delegate type
The problem is the two delegate types simply aren't compatible. In order to make this work you are going to need to add an indirection layer which converts the arguments between ICommand and TCommand. public void RegisterHandler<TCommand>(CommandHandler<TCommand> handler) where TCommand : ICommand { mCommandHandlers.Add( typeof(TCommand), (command) => handler((TCommand)command); ); }

Categories : C#

Convert Expression> to Expression>
Why don't you just change your method to be: T GetSingle(IRepository<T> repository, Expression<Func<TSource, Boolean>> predicate) { return repository.GetAll().Single(predicate); } so instead of this: GetSingle(myRepository, (a,b) => a.Id == b.Id, myEntity); you should be able to do this: GetSingle(myRepository, a => a.Id == myEntity.Id);

Categories : C#

How to convert IQueryable to Expression>?
Any reason you don't just do the following: public IQueryable<Event> GetBySearch(EventFilter search) { IQueryable<Event> query = this.Context.Events.AsQueryable(); if (search.CategoryId != 0) { query = query.Where(x => x.CategoryId == search.CategoryId); } if (search.SubCategoryId != 0) { query = query.Where(x => x.SubCategoryId == search.SubCategoryId); } return query; } As Florian said in the comment, returning IQueryables is to be avoided (when possible). The easy solution is to return a list instead: public List<Event> GetBySearch(EventFilter search) { IQueryable<Event> query = this.Context.Events.AsQueryable(); if (search.CategoryId != 0) { query = query.Where(x => x.CategoryId

Categories : C#

LINQ throwing TypeAs expression with input of type 1 and check of type 2 is not supported
Unfortunately, you're going to have to do this dynamically. Generics (combined with Entity Framework's apparent fear of typecasting) won't allow you to write the code you want in a static manner. So try this instead: using System.Linq.Expressions; public static Expression<Func<TEntity, bool>> DefaultFilter<TEntity>() where TEntity : IEntity { if (typeof(SoftDeleteEntity).IsAssignableFrom(typeof(TEntity))) return DefaultFilterSoftDelete<TEntity>(); else return x => true; } public static Expression<Func<TEntity, bool>> DefaultFilterSoftDelete<TEntity>() where TEntity : IEntity { var parameterExpression = Expression.Parameter(typeof(TEntity)); var propertyExpression = Expression.Property(parameterExpression, "

Categories : C#

Using Many to many with ef linq expression gave me "Unable to create a constant value of type (type)"
The Entity Framework can't translate the Contains(product) to SQL code. Your problem lies here: discount.Products.Contains(product) You should search the product by it's ProductID, which should be a primitive type. This is a know issue which is documented here: Referencing Non-Scalar Variables Not Supported : Referencing a non-scalar variables, such as an entity, in a query is not supported. When such a query executes, a NotSupportedException exception is thrown with a message that states "Unable to create a constant value of type EntityType. Only primitive types ('such as Int32, String, and Guid') are supported in this context."

Categories : Entity Framework

The type of the expression must be an array type but it resolved to long
The problem is that you have two variables called id: private String id[]; and long id of onItemClick. Just change your onItemClickListener to the following: public void onItemClick(AdapterView parent, View v, int position, long anid) { Intent x = new Intent(Menu.this, Account_View.class); x.putExtra("Id", id[position]); startActivity(x); } Please note the name of your the last argument of onItemClick.

Categories : Java

Convert sql to Lambda expression
Here is how you can do it var galleryIds = (bidModelses.Where(b => b.UserId == [YOURPARAMETER]) .Select(b => b.GalleryId)); var query = (bidModelses.Where(bm => galleryIds.Contains(bm.GalleryId)) .GroupBy(bm => bm.GalleryId) .Select(gbm => new {gbm.Key, MaxBid = gbm.Max(p => p.BidId)}));

Categories : SQL

asp.net json web service sending array error Cannot convert object of type 'System.String' to type 'System.Collections.Generic.List`1[System.String]'
You need to make your data parameter of the $.ajax call like this: JSON.stringify({'a': variables}) The JSON variable is not available in < IE8 so you'll want to include a JSON implementation like the one mentioned in the answer here Also, you had an extra } in the success function. So, in the future, if you want to add extra parameters to your data object passed to the web service, you'd construct it like so: var someArr = ['el1', 'el2']; JSON.stringify({ 'param1': 1, 'param2': 'two' 'param3': someArr // etc }); JavaScript: var variables = Array(); var i = 0; $('#Div_AdSubmition').find('.selectBox').each(function () { variables[i] = $(this).find('.selected').find(".text").html(); i++; }); $.ajax({ type: 'post', data: JSON.stringify({'a': variables}),

Categories : C#

expression must have pointer type error
my_Session->my_ListIndex->push_back(i); ...tries to use my_ListIndex as a pointer, which it (according to the call to size() a few lines above) is not. my_Session->my_ListIndex.push_back(i); ...works better.

Categories : C

What does Failed to convert property value of type '$Proxy0 to required type means in this case?
Ok, first thing i see here: WriterSqlParameterSetter is a ItemPreparedStatementSetter! fine! But even if you declare: <beans:property name="amount" value="#{jobParameters[amount]}"/> <beans:property name="id" value="#{jobParameters[id]}"/> I don't see theses properties in : public class WriterSqlParameterSetter implements ItemPreparedStatementSetter<transactionas>{ public void setValues(transactionas ts, PreparedStatement ps) throws SQLException { ps.setDouble(1, ts.GetAmount()); ps.setInt(2, ts.GetID()); } } And even if the properties were declared, the ItemPreparedStatementSetter wont use them since, it takes value from the object received in the writer (eg. transactionas). I am trying to see why you need to pass an amount and

Categories : Spring

What does Failed to convert property value of type '$Proxy0 to required type means?
You don't use the right interface. Your ReaderSqlParameterSetter should implements PreparedStatementSetter not ItemPreparedStatementSetter If you look at the impl of JdbcCursorItemReader: public class JdbcCursorItemReader<T> extends AbstractCursorItemReader<T> { PreparedStatement preparedStatement; PreparedStatementSetter preparedStatementSetter; String sql; RowMapper rowMapper; The property is a PreparedStatementSetter . If you look at the interface you try to use : public interface ItemPreparedStatementSetter<T> { /** * Set parameter values on the given PreparedStatement as determined from * the provided item. * @param ps the PreparedStatement to invoke setter methods on * @throws SQLException if a SQLException is encountered (i.e. there is no * need to

Categories : Spring

Different type returned by getter than type of field in Jackson. How to convert map to set?
There is no direct way to convert a Set to a Map. Set is an extension of Collection, Map is an entirely different object. If ContactInfoInterface contains the information you need to manually build a Map you could do that. But trying to pass back a Set in the form of a Map will never work.

Categories : Java

Cannot convert object of type 'System.String' to type 'PropertySearch'
It looks like you are trying to deserialize with invalid json. A good place to check your json format is JsonLint.com. You will want your json object to look more like this: { "UserId": 1, "SessionId": 1, "PriceMin": 1, "PriceMax": 1, "BedsMin": 1 } The issue you are having is you are passing a comma delimited string. The deserializer does not know which values to map to which fields.

Categories : Dotnet

Do Entity Framework Provide Utility that convert DB Type To C# Type?
I dont know such a public method (I think there is none... it that may be accepted as answer) However, try to uncompile sqlmetal.exe, you can have a good idea of how default associations are implemented internally: In class LinqToSqlShared.Utility.DbTypeSystem (internal class) you can find the method: internal static Type GetClosestRuntimeType(SqlDbType sqlDbType) { switch (sqlDbType) { case SqlDbType.BigInt: return typeof(long); case SqlDbType.Binary: case SqlDbType.Image: case SqlDbType.Timestamp: case SqlDbType.VarBinary: return typeof(Binary); case SqlDbType.Bit: return typeof(bool); case SqlDbType.Char: case SqlDbType.NChar: case SqlDbType.NText: case SqlDbType.NVarChar: case SqlDbType.Text: case SqlDbType.

Categories : C#

typeof() when Cannot implicitly convert type 'System.Type' to 'string'
According to the documentation, the DataType property is used to specify an XSD data type, not a .NET type: An XML Schema data type, as defined by the World Wide Web Consortium (www.w3.org) document named "XML Schema Part 2: Datatypes". Try this instead: public class EPubBody { [XmlElement(ElementName = "Image")] public EPubImage[] BodyItems; }

Categories : C#

Error when using a Linq Expression variable instead of lambda expression directly
Compile your expression into executable code (delegate): var types = assembly.GetTypes().AsEnumerable().Where(_standardFilter.Compile()); As @Kirk stated, it's better not to use expression tree, if you are not going to analyze it. Simply use filter of type Func<Type, bool>.

Categories : C#

Convert "C# friendly type" name to actual type: "int" => typeof(int)
Alias names like 'int','bool' etc. are not part of .NET Framework. Internally they are converted into System.Int32, System.Boolean etc. Type.GetType("int") should return you null. Best way to appoach this is by having a dictionary to map alias with their type e.g. Dictionary<string, Type> PrimitiveTypes = new Dictionary<string, Type>(); PrimitiveTypes.Add("int", typeof(int)); PrimitiveTypes.Add("long", typeof(long)); etc.etc..

Categories : C#

Error on result of linq expression (and anounymous type)
Use a different variable (do not use res) var res = model.DbExame.Where(exame => exame.Descricao.Trim() == desc.Trim()).Select(exame => new { Id = exame.Id, Codigo = exame.Codigo }); //^ Now res is of a specific type (ie: IEnumerable<Anonymous1>) if (res == null) var res2 = model.DbExame.Where(exame => exame.Codigo.Trim() == desc.Trim()).Select(exame => new { Id = exame.Id, Descricao = exame.Descricao }); //^ you cant affect res2 to res because they are of different type if (res == null) res will never be null, may be you want if (!res.Any()) to see if res has items. This is what you should do: public static string VerificaExame(string desc) { var model = new ExameContext(); object res = (object)model.DbExame.Where(exame => exame.Descricao.Trim

Categories : C#



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