AutoMapper and Windows Phone 7 - automapper

Basics:
Visual Studio 2010
WP7 SDK 7.1 RC
AutoMapper added to project via NuGet
Ask for more!
Problem:
I'm getting the following error at runtime:
Could not load type 'AutoMapper.Mapper' from assembly 'AutoMapper, Version=1.1.0.188, Culture=neutral, PublicKeyToken=BE96CD2C38EF1005'.
There seems to be an open issue about this # CodePlex, but i thought that i'd ask if anyone has found any solutions to this?
As always, i'm more than happy to provide any additional info required!

AutoMapper uses Castle Dynamic Proxy which requires Reflection.Emit which is not supported on the phone.
If you want this you're going to need to look at building it all yourself. In terms of getting round the lack of reflection.Emit (if you really do need it) then you should look at using Mono.Cecil to provide this missing functionality.

Seems that automapper is working on silverlight edition so possible WP7/WP8 compatibility coming soon.
In the mean time there is a simple mapper library that you can use. It is very basic but probably meets most of your requirements for WP7 applications.
// Configure LazyMapper
Mapper.Create<SampleClass, SampleClassDto>();
// Perform mapping
var dto = Mapper.Map<SampleClass, SampleClassDto>(new SampleClass {
StringVal = "String1"});
Assert.AreEqual("String1",dto.StringVal);
Download at http://lazycowprojects.tumblr.com/LazyMapper

Related

Win8 app CLI library integration issue

I have a Win8 app that is purely native (c++) and I've already used a library that is written using managed code AFAIK. No issues there, I created objects and addressed them using C++/CX with ref counted pointers etc.
I need to add a new library, I referenced it as I did previously, but when I declare and object and try to address it I get:
error C3624: 'System::Object': use of this type requires a reference to assembly 'mscorlib'
Using #using <mscorlib.dll> is not a solution obviously, because WinRT does not support #using of a managed assembly.
When I look up the definition of the class I'm using in Object Browser I see that it's inherited from System::Object. The previous library had a class that was inherited from Platform::Object which is valid for C++/CX.
I already contacted the developers of current library I'm trying to use, but it takes a lot of time for them to respond.
Can I work around this issue? What are the possible courses of action?
UPD: Can I ask the developers to rebuild a library for C++/CX?
I do not believe this is going to work in the general case, unless the C# library is a PCL (portable class library). If it leverages anything that is not in the WinRT .NET client profile, it simply will not work.
If it is a PCL, what you can do is write a C# Windows Runtime Component that itself has a reference to this third-party library and wraps the necessary functionality. Then you reference that C# Windows Runtime Component from your C++/Cx application.

Using Protobuf-Net In Xamarin.iOS without full AOT

Is there any alternative to achieving serialising and deserialising of objects in Xamarin.iOS (Monotouch) using protobuf-net other than this method:
http://www.frictionpointstudios.com/blog/2011/3/31/using-protobuf-net-serialization-in-unity-iphone.html
Reading around some people claim they have managed it (without giving evidence), but my understanding is that [iOS JIT==NO] so does not quite make sense.
If the only possible solution is to fully AOT all relevant classes what might a suitable pre/post-build event command line be to perform this AOT for any relevant assemblies automatically?
I've heard a good number of people have success via that route, but I too can't give documented evidence.
That method is a bit out of date - I've simplified a few steps; there is a standalone pre-compile tool that should work:
create a project/assembly for the DTOs that you want to serialize that references the appropriate version of protobuf-net; presumably CoreOnly/ios, ideally with that dll set to copy into the output directory (it just makes life easier)
run
precompile "SomePath/YourDto.dll" -t:MySerializer -o:MySerializer.dll
(maybe with a mono before that to get mono to host the exe)
this should resolve the framework and compile a MySerializer.dll that you can reference, which involves zero JIT (MySerializer.dll will reference your dto dll and the version of protobuf-net that your dto dll referenced)
now reference your dto dll, the serializer dll, and the protobuf-net dll, and it should all work just by using new MySerializer().Serialize(...)
when you compile your solution, the projects should all AOT nicely
I'll be happy to offer guidance, but currently I am mac-less, so I can't check right now. If you get any problems let me know. If it can't resolve the framework, you can add -f:{path to the framework assemblies} to give it a clue.
I got protobuf-net 2 working on Xamarin-iOS by using the netstandard1.0 dll. You can get this dll by extracting the nuget package. No changes were needed.

Attempt by security transparent method X to access security critical method Y failed

I have a fairly stable server application version that's been deployed for nearly a year at dozens of customers.
One new customer recently setup the application and is getting the following error:
System.MethodAccessException: Attempt by security transparent method
[SomeMethod] to access security critical method [SomeOtherMethod]
failed.
Both SomeMethod and SomeOtherMethod are methods in assemblies that I wrote, that are built against .NET 4, and that are running inside a Windows Service. If it makes a difference, SomeOtherMethod does reference a type from a 3rd party assembly (EntLib 4.1) built against .NET 2.0. Looking at the code for EntLib 4.1, I do see that they use both SecurityTransparent and APTC attributes, but this has never caused issues at other clients.
These assemblies were upgraded from the .NET 2.0 CLR, but a long time ago. This exact code is running on other customers just fine, and I'm not explicitly using the APTC attribute nor am I using the SecurityCritical attribute anywhere.
This leads me to the conclusion that it's a configuration issue or perhaps .NET Framework patch issue. Has there been a patch released for .NET that would cause this breaking change? Is there a configuration setting some where that enforces this type of check which is off by default but that my customer may have enabled?
One last point. My service utilizes SSRS RDLCs to generate PDFs. Due to some changes in .NET 4, I must force the service to use the legacy security policy via the following config:
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true" />
</runtime>
For more details on why I need to do this, see this stackoverflow post: Very High Memory Usage in .NET 4.0
The important point is that I do this at all my other customers as well. Only this one customer is having issues.
Sigh, the patterns and practices employed by the Microsoft Patterns And Practices team that's responsible for the Enterprise libraries are pretty deplorable. Well, the exception is accurate, you cannot call a method that's decorated as "I'll definitely check security" from code that's decorated with "Meh, I won't check security so don't bother burning the cpu cycles to check it". Which scales about as well as exception specifications as used in Java. CAS is incredibly useful, but diagnosing the exceptions is a major headache and often involves code that you don't own and can't fix. Big reason it got deprecated in .NET 4.
Editorial done. Taking a pot-shot at the problem, you need to find out why CAS is being enforced here. The simplest explanation for that is that the service doesn't run in full trust. The simplest explanation for that is that the client didn't install the service on the local hard drive. Or is generally running code in don't-trust-it mode even on local assemblies, a very paranoid admin could well prefer that. That needs to be configured with Caspol.exe, a tool whose command line options are as mysterious as CAS. Pot-shooting at the non-trusted location explanation, your client needs to run Caspol as shown in this blog post. Or just simply deploy the service locally so the default "I trust thee" applies.
Editing in the real reason as discovered by the OP: beware of the alternate data stream that gets added to a file when it is downloaded from an untrusted Internet or network location. The file will get a stream named "Zone.Identifier" that keeps track of where it came from with the "ZoneId" value. It is that value that overrides the trust derived from the storage location. Usually putting it in the Internet zone. Use Explorer, right-click the file and click "Unblock" to remove that stream. After you're sure you can trust the file :)
I was facing the similar issue while running the downloaded WCF sample from http://www.idesign.net/ while using their ServiceModelEx library.
I commented out the below line in AssemblyInfo.cs in ServiceModelEx project
//[assembly: AllowPartiallyTrustedCallers]
and it worked for me.
In case it helps others i post my solution for this issue:
1) On the AssemblyInfo.cs, removed/commented the [assembly: SecurityTransparent] line.
2) The Class and the Method that does the actual Job was marked as [SecuritySafeCritical], in my case establishing a Network Connection:
[SecuritySafeCritical]
public class NetworkConnection : IDisposable
{
[SecuritySafeCritical]
public NetworkConnection(string networkName, NetworkCredential credentials)
{
.............
}
}
3) The Caller Class and Method was market as [SecurityCritical]:
[SecurityCritical]
public class DBF_DAO : AbstractDAO
{
[SecurityCritical]
public bool DBF_EsAccesoExclusivo(string pTabla, ref ArrayList exepciones)
{
....
using (new NetworkConnection(DBF_PATH, readCredentials))
{
....
}
}
}
In my case it was an issue when I managed a NuGet packages in the solution some package overrides System.Web.Mvc assembly version binding in main web site project. Set back to 4.0.0.0 (I had 5.0 installed). I didn't change notice the change because Mvc v4.0 was installed and accessible via GAC. Set back

Error serializing with ServiceStack JSON on MonoTouch

I am experimenting with ServiceStack's JSON engine. I grabbed the MonoTouch binary build, v2.20. Works fine from simulator, but from the iOS device (iPad2, iOS5) I get an exception thrown by the type initializer for JsonWriter (and not much other than that). I am using MonoTouch 5, MonoDevelop 2.8.1, and targeting iOS 5. I have disabled library linking because I am getting an error when enabled.
I created a sample and uploaded to https://github.com/t9mike/ServiceStack-JSON1.
I'm trying to determine whether the issue is my compilation options, Service Stack, or MonoTouch. Thanks in advance.
A quick partial answer that might help:
I have disabled library linking because I am getting an error when enabled.
The current (5.0) managed linker can eliminate some unused (from a static analysis point of view) code from your application. This generally occurs when using Link all option, i.e. where user code gets processed by the linker.
One alternative is using the Link SDK assemblies only that won't touch the user code (only the code shipped with MonoTouch itself will be processed by the linker).
Another alternative is adding [Preserve] attributes on your code to ensure the serializer requirements are still met after the linker has processed your code. More information about the linker and [Preserve] attributes can be found here.
The next (5.2) release of MonoTouch will include a bit more sophisticated step in the linker to ensure the basic XML serialization and DataContract requirements are not broken. Not sure if this will solve this specific case (ServiceStack JSON) but I'll have a look into it.
As for the rest of your question I'll try to build this myself and duplicate your issue.
I ended up grabbing the ServiceStack.Text sources from GitHub, version 3.0.3. I created a new MonoTouch library project. I had to tweak ServiceStack.Text/JsConfig.cs slightly to conditionalize away the System.Drawing.Color bits. I'll send a patch and MT csproj to the authors.
After using this new assembly, my sample MT app ran fine on the device. I have updated my sample at https://github.com/t9mike/ServiceStack-JSON1 with the new ServiceStack.Text dll.

Error preverifying class NetBeans 6.8 using lwuit api

I'm trying to develop a portable J2ME appli, but Netbeans do a class preverification of LWUIT library that uses optional APIs that some configurations don't have, so I get this error when I try to compile on a configuration without JSR-184 (M3G Optional API):
Error preverifying class com.sun.lwuit.animations.Transition3D
VERIFIER ERROR com/sun/lwuit/animations/Transition3D.initTransition()V:
Cannot find class javax/microedition/m3g/Node
I don't want to remove the classes from the LWUIT API because that classes works on other configurations compatibles with JSR-184
What I want is that NetBeans do not preverify the library, It is posible?
Here are some code:
//#ifdef JSR184
//# import com.sun.lwuit.animations.Transition3D;
//#else
import com.sun.lwuit.animations.CommonTransitions;
//#endif
Transition out;
//#ifdef JSR184
//# out = Transition3D.createRotation(500, true);
//#else
out = CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, true, 500);
//#endif
setTransitionOutAnimator(out);
Thanks
We had the similar problems, as I remember BlackBerry handsets are problematic (?) for this JSR-184. What I did to solve this problem, I created different configurations for different targets and removed this problematic classes from LWUIT library, rebuild library for that target, and also modified project settings of related configuration accordingly. Hope it helps.
There is a native blackberry port of LWUIT as well as quite a few tutorials and instructions on how to use it. The native port uses native RIM API's which work far better on the blackberry devices than MIDP API's.
LWUIT's use of 184/226 doesn't bother devices that don't support these profiles other than blackberry which has a broken classloader implementation.
It may be possible, though I havent tried it. Netbeans has two xml files, build.xml and build-impl.xml. Look at these files and look for preverify task, then you can do a bit of testing and ensure that it doesnt preverify the library.
Netbeans ant plugin is a pretty simple setup and you can change it which ever way you want to.

Resources