Issue while Automapper Upgrade to 5.1.1 - automapper

We were using the automapper v5.0 in our code. In our create map statement, we had a statement ->
m.ResolveUsing((src, o, context) => (CodeObject)context.Options.Items["test"]))
When we upgraded the Automapper version to 5.1.1, we are getting build error in the above statement.
Can you please suggest how to correct this with latest version.

Finally i have got the answer after going through the automapper source code. We can do it this way:
m => m.ResolveUsing((src, o, destMemb, context) => (CodeObject)context.Items["test"]))

Related

Automapper 8.1.1 using reflection not working after update to Abp 4.8.1

I upgraded Abp to 4.8.1. After this update my AutoMapper throws this error:
- Missing type map configuration or unsupported mapping.
The issue arises when i try to map a DTO to an Entity
Im how im configuring AbpAutomapper
var thisAssembly = typeof(dsimApplicationModule).GetAssembly();
IocManager.RegisterAssemblyByConvention(thisAssembly);
Configuration.Modules.AbpAutoMapper().Configurators.Add(
// Scan the assembly for classes which inherit from AutoMapper.Profile
cfg => cfg.AddMaps(thisAssembly)
);
My DTO:
[AutoMapTo(typeof(ServiceTemplate))]
public class UpdateServiceTemplateDto : EntityDto, IShouldNormalize, ICustomValidate
{
//properties
}
In AppService, Update Method:
var serviceTemplate = ObjectMapper.Map<ServiceTemplate>(input);
Worked fine before update. I Read that dynamic mapping is depricated in Automapper 8.1.1. Not sure this is considered dynamic though since i use reflection.

AutoMapper 8 Upgrade ConstructUsing

I have just upgraded to v8 of AutoMapper and the expression below fails but I really cannot see why.
cfg.CreateMap<string, Nmtoken>()
.ConstructUsing(i => new Nmtoken(i))
.ForMember(m => m.Token, o => o.MapFrom(s => s));
I believe that the passed expressions are valid. I get no build errors and intellisense is happy. But I get runtime error:
System.MissingMethodException: 'Method not found:
'AutoMapper.IMappingExpression`2<!0,!1>
AutoMapper.IMappingExpression`2.ConstructUsing(System.Func`2<!0,!1>)'.'
I'm happy to admit that I don't understand the error message.
Apologies. I have two projects linked with a dependency and one of them was still using AutoMapper 7.
I had the samme issue, but i was using AutoMapper v8.0.0.
Upgrading to version v8.1.0 solved the issue.

AutoMapper version 5.0.0-beta-1 - Created Mapper shows exceptions

I updated automapper package today and it got updated to 5.0.0-beta and i immediately got few build errors. Going through the latest changes in their wiki page i found that CreateMap is deprecated. So i followed their instruction and here is my code below.
The created mapper shows these exception about which i have no clue. I am not able to continue further. Should i do something extra with this new version of AutoMapper? Any help would be greatly appreciated. My POCO classes are just regular ones with int and strings.
You can just create a new Mapper instance now:
var mapper = new Mapper(config);
builder.RegisterInstance(mapper).As<IMapper>();
Or, if you prefer the old static way, just use Mapper.Initialize().

How can I figure out which version of apache POI is needed for jXLS 2.3.0?

This is my Gradle file:
compile 'org.apache.poi:poi:3.13'
compile 'org.jxls:jxls-jexcel:1.0.6'
compile 'org.jxls:jxls-poi:1.0.9'
compile 'org.jxls:jxls:2.3.0'
It looks like I'm using the wrong version of apache POI:
java.lang.NoSuchMethodError: org.apache.poi.ss.usermodel.Workbook.getCellStyleAt(S)Lorg/apache/poi/ss/usermodel/CellStyle;
at org.jxls.transform.poi.PoiTransformer.clearCell(PoiTransformer.java:224)
at org.jxls.area.XlsArea.clearCells(XlsArea.java:437)
at org.jxls.builder.xls.XlsCommentAreaBuilder.build(XlsCommentAreaBuilder.java:181)
at org.jxls.template.SimpleExporter.gridExport(SimpleExporter.java:54)
Isn't it a bit strange that I have to explicitly include a dependency that another dependency depends upon? Moreover, how can I figure out which version of the dependency (the POI) I actually need?
I am just trying to get the simple exporter sample to work:
try (InputStream is = CalXlsExporter.class.getResourceAsStream(template)) {
try (OutputStream os2 = new FileOutputStream("ExportOutput.xlsx")) {
headers = Arrays.asList(HEADERS);
Context context = new Context();
context.putVar("headers", HEADERS);
context.putVar("cell", cal);
JxlsHelper.getInstance().processTemplate(is, os2, context); //Exception inside this
}
} catch (Exception e) {
e.printStackTrace();
}
You can always look at the Maven pom file of jxls-poi module for example you can see that jxls-poi-1.0.9 contains a dependency to POI 3.12 as defined in pom properties section
<properties>
...
<poi.version>3.12</poi.version>
...
</properties>
It may happen that later POI versions can also work but it is not always the case because it depends on Apache POI backwards compatibility.
I would try to simply remove the dependency on POI in your file as jxls will drag in the correct version of POI as transitive dependency anyway, so you just need to depend on jxls in your application always and future updates will not cause similar strange errors.

Xamarin Linker : Default constructor not found for type Cirrious.CrossCore.IoC.MvxPropertyInjector

With a skeleton project with FirstView from HotTuna package, and with Build linker behavior set to "Link all assemblies", I get the following error:
System.MissingMethodException: Default constructor not found for type Cirrious.CrossCore.IoC.MvxPropertyInjector
Using NuGet package v3.1.1 for all MvvmCross (4 packages)
LinkerPleaseInclude file does have the line
[MonoTouch.Foundation.Preserve(AllMembers = true)]
Using the latest stable build:
On PC:
Xamarin for VS 1.12.278
Xamarin.iOS 1.12.278
Mac:
Xamarin.iOS 7.2.2.2
Of course with Linker behavior of SDK only, it runs fine. Any suggestions anyone?
Solved; So, with the basic project, there were three consecutive errors in the following order:
System.MissingMethodException: Default constructor not found for type Cirrious.CrossCore.IoC.MvxPropertyInjector
can be resolved either by --linkskip=Cirrious.Core (ugly), or by including the following in LinkerPleaseInclude.cs
public void Include(MvxPropertyInjector injector){
injector = new MvxPropertyInjector ();
}
Next error is:
Cirrious.CrossCore.Exceptions.MvxException: Failed to construct and initialize ViewModel for type {0} from locator MvxDefaultViewModelLocator - check MvxTrace for more information
This one is difficult; Simple fix is to ofcourse to do a --linkskip=portableLibrary, or to crate an instance of the ViewModel somewhere (perhaps in LinkerPleaseInclude.cs); problem with the second approach at-least in my case is, most of my VM doesn't have a parameter less constructor, and obviously using IOC in this case wouldn't help.
Final Error:
System.ArgumentNullException: missing source event info in MvxWeakEventSubscription
Parameter name: sourceEventInfo
Either use --linkskip=System (ugly), or add the following to LinkerPleaseInclude.cs
public void Include(INotifyPropertyChanged changed)
{
changed.PropertyChanged += (sender, e) => {
var test = e.PropertyName;
};
}
This was enough for my basic project to run with LinkAllAssemblies, Using LLVM optimizer, and Use SGen collector.
Hope this will help anyone looking for a solution.
I hit this when my XCode was out of sync with the latest Xamarin on my Mac. Upgrading XCode to the latest resolved the problem.

Resources