Cant Create Automapper custom value resolver - automapper

I have been trying to create a automapper Custom value resolvers, but I seem to have missed some set up step as it can never seem to find
public abstract class ValueResolver<TSource, TDestination> : IValueResolver
So in the following snippet will not compile.
using DITest.Models; // This is where the SalesOrder class is
using AutoMapper;
namespace DITest.AutoMapper.SaleOrder
{
public class FullAddress : ValueResolver<SalesOrder, string>
{
protected override string ResolveCore(SalesOrder source)
{
return "foo bar";
}
}
}
I get the error message
The type or namespace name 'ValueResolver<,>' could not be found (are you missing a using directive or an assembly reference?)
Its say the using AutoMapper is not used.
In the past I have been naughty and hacked in a reference for lib\net45\AutoMapper.dll

Please try IMemberValueResolver type instead of IValueResolver. The AutoMapper had some upgraded things.
https://github.com/AutoMapper/AutoMapper/wiki/5.0-Upgrade-Guide

ValueResolver is gone. IValueResolver is the replacement. And there is also IMemberValueResolver, as the docs say.

Related

graph extension is marked as [PXOverride], but the original method with such name has not been found in PXGraph

I'm needing to adjust some of the field attributes for the Location.VCashAccountID field on the Vendors screen - AP303000. When I put the code below into a customization DLL, it compiles fine and there are not apparent issues on the screen. However, when I try to publish the customization project with the DLL included, I get an error.
Code:
public class VendorMaintDefLocationExtExt : PXGraphExtension<VendorMaint.DefLocationExt,
VendorMaint>
{
public void _(Events.CacheAttached<PX.Objects.CR.Standalone.Location.vCashAccountID> e) { }
}
Error:
"Method Boolean DoValidateAddresses(PX.Objects.CR.Extensions.ValidateAddressesDelegate) in graph extension is marked as [PXOverride], but the original method with such name has not been found in PXGraph"
What am I missing?
TIA!
The following implementation will override the vCashAccount attribute on AP303000
public class AAVendorMaintDefLocationExtExtension : PXGraphExtension<DefLocationExt, DefContactAddressExt, VendorMaint>
{
[PXMergeAttributes(Method = MergeMethod.Merge)]
[PXUIField(DisplayName = "I am override")]
public void _(Events.CacheAttached<PX.Objects.CR.Standalone.Location.vCashAccountID> e) { }
}
You will also require the following references
using PX.Data;
using PX.Objects.AP;
using static PX.Objects.AP.VendorMaint;
The result can be seen in the snip below
The main difficulty in this task was the multitude of graph extensions utilized by the page. Though it's a beneficial design to encapsulate functionality it can be finnicky to determine which order they should be declared in a new extension.
You're graph extension extends VendorMaint.DefLocationExt which contains DoValidateAddresses. Try just extending VendorMaint.

The name 'PropertySupport' does not exist in the current context

I would like to create a base class for observableObject generic enough for an observable object to derive from, but I hit some technical issue. This is an extract of the class. It is an abstract that implements interface INotifyPropertyChanged. But when I tried to use PropertySupport.ExtractPropertyName, I got compiler error saying 'PropertySupport' not exist in the current context. I am using VS2002. My intention was to create a library to host a small "framework" of my own and use it for different projects. Could anyone more well versed in the reflection point out what was wrong in my code to cause the compiler error?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace MyFramework
{
[Serializable]
public abstract class ObservableObject: INotifyPropertyChanged
{
[field: NonSerialized]
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
var handler = this.PropertyChanged;
if (handler!=null)
{
handler(this, e);
}
}
protected void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression)
{
var propertyName = PropertySupport.ExtractPropertyName(propertyExpression);
this.RaisePropertyChanged(propertyName);
}
protected void RaisePropertyChanged(String propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
}
}
The error you are getting usually refers to a missing using directive or missing reference.
Looking at MSDN for the function you are trying to use it looks like you are missing the using directive Prism.ViewModel
using Microsoft.Practices.Prism.ViewModel;
If this doesn't fix your problem then you need to add a reference to the correct dll
Microsoft.Practices.Prism.Composition.dll
I've never used Prism but after copying your class, adding the correct reference & using directive it built ok.

The type or namespace name 'LinkedList' could not be found (are you missing a using directive or an assembly reference?

I have a fresh install of Visual Studio, the following code gives me the error in the title.
using System;
using System.Collections;
using System.Collections.Generic;
public class GenericCollection
{
public static void Main()
{
// Create and initialize a new LinkedList.
LinkedList<String> ll = new LinkedList<String>();
ll.AddLast("red");
ll.AddLast("orange");
ll.AddLast("yellow");
ll.AddLast("orange");
// Display the contents of the LinkedList.
if (ll.Count > 0)
{
Console.WriteLine("The item in the list is {0}.", ll.First.Value);
Console.WriteLine("The item in the list is {0}.", ll.Last.Value);
Console.WriteLine("The LinkedList contains:");
foreach (String s in ll)
Console.WriteLine(" {0}", s);
}
else
{
Console.WriteLine("The LinkedList is empty.");
}
}
}
I am not even using a custom class.
just from the System.Collections.Generic dll
I assume there is a problem with the references, since the code is correct.
Please help me , how can i fix this.
(PS: I am fairly new to coding)
System.Collections.Generic.LinkedList<T> exists in the System (System.dll) assembly.
Make sure you have a project reference to this assembly.
You can view your existing references by expanding the References section under the project in Solution Explorer.

Compile error using Azure Storage Client library 3.0 method executequery<T> where T is tableentity

I must be missing something obvious but the following fails with a compile error:
internal static IEnumerable<T> GetEntitiesWithCommaSeparatedRowKeys<T>(
string tableName, string partitionKey,
string commaDelimitedStringOfRowKeys) where T: TableEntity
{
....
TableQuery<T> entitiesQuery = new TableQuery<T>().Where(
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("PartitionKey",
QueryComparisons.Equal, partitionKey),
TableOperators.And,
AzureHelper.GetFilterConditionForCommaDelimitedStringOfRowKeys(commaDelimitedStringOfRowKeys)
));
// compile error on this line
IEnumerable<T> entities = table.ExecuteQuery<T>(entitiesQuery);
...
}
The error I get is:
'T' must be a non-abstract type with a public parameterless constructor
in order to use it as parameter 'TElement' in the generic type or
method 'Microsoft.WindowsAzure.Storage.Table.CloudTable.ExecuteQuery<TElement>
(Microsoft.WindowsAzure.Storage.Table.TableQuery<TElement>,
Microsoft.WindowsAzure.Storage.Table.TableRequestOptions,
Microsoft.WindowsAzure.Storage.OperationContext)'
TableEntity clearly has a public parameterless constructor and is non-abstract.
The following is the object from metadata info when I hit F12 on TableEntity (just to ensure its resolving the TableEntity type correctly).
namespace Microsoft.WindowsAzure.Storage.Table
{
public class TableEntity : ITableEntity
{
// Summary:
// Initializes a new instance of the Microsoft.WindowsAzure.Storage.Table.TableEntity
// class.
public TableEntity();
...
}
}
Any ideas anyone?
FYI I'm using Azure Client library 3.0.1.0.
UPDATE: Added linked issue which solved a similar problem
So turns out that if a method provides a constraint on type, that constraint must be also forwarded by any callers of that type.
I didn't know that.
In this case the definition for Table.ExecuteQuery looks like the following
public IEnumerable<TElement> ExecuteQuery<TElement>(TableQuery<TElement> query,
TableRequestOptions requestOptions = null,
OperationContext operationContext = null)
where TElement : ITableEntity, new();
Therefore adding new() to my constraints for T fixes the issue.
So the final method declaration looks like
internal static IEnumerable<T> GetEntitiesWithCommaSeparatedRowKeys<T>(string tableName,
string partitionKey,
string commaDelimitedStringOfRowKeys)
where T : TableEntity , new() //This is new (pun intended :))
Found a related issue in one of the related links that showed up for this question.
I'm guessing the compiler could always look up the type constraints from when I actually make the call, but since TableEntity is public (and not sealed) I guess it could end up being a runtime issue.
Also interesting to note that my method is marked internal which should really enable the compiler to check against callers within the library.
Anyways, learnt something new :).

ServiceStack and HttpError

In ServiceStack is there an implementation of HttpError?
I can find the interface definition:
namespace ServiceStack.ServiceHost
{
public interface IHttpError : IHttpResult, IHasOptions
{
string ErrorCode { get; }
string Message { get; }
}
}
But am I missing a using directive, because I get this compiler error:
The type or namespace name 'HttpError' could not be found (are you missing a using directive or an assembly reference?)
The HttpError class is in the ServiceStack.Common.Web namespace (ServiceStack.Common assembly/NuGet package) in the current (version 3) release of ServiceStack.
In under-development version 4, looks like it was moved to the root ServiceStack namespace.
I just found out how to search namespaces, in VS2012 anyway... Select the class and type Shift-Alt-F10... this causes a little dropdown box to appear... click on it and you will see the namespaces that have matching class names!

Resources