Visual Studio 2015 introduces the new Android emulator. What is great is that it is based on Hyper-V technology, so hardware virtualization, as described more extensively in Introducing Visual Studio’s Emulator for Android.
Using it to develop Xamarin application, I've run into some issues, and I think that it would be good to collect them here:
- first of all, during my first attempt to run it to debug a simple application, I got in the Output windows of Visual Studio this cryptic error:
In mgmain JNI_OnLoad
Couldn't connect to logcat, GetProcessId returned: 0
As described in Can't run app on Visual Studio 2015 emulator (DWP Handshake failed), the solution is to go to the Android project settings and in the Android Options tab, disable Fast Deployment
- the second problem was that because of my naming convention for demo projects, I had a too long project name.
Doing some attempts, I've verified that the longest project name you can give is 37 characters (more create problems with the deployment);
- when I've been finally able to run my application, I've noticed that I had multiple graphic issues (even if the application is really basic).
As described in Visual studio android emulator will not start fully, you have to go to the folder C:\Program Files (x86)\Microsoft XDE\10.0.10240.0\SKUs\Android, edit the file xdesku.xml and delete/comment the line:
In C# there is a feature of the language that allows a method to receive as input parameters the member name, file path and line number of the calling method/property.
It is enough to add attributes to the method parameters receiving these values, as in the following example:
public void DoProcessing()
public void TraceMessage(string message,
[System.Runtime.CompilerServices.CallerMemberName] string memberName = "",
[System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "",
[System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
System.Diagnostics.Trace.WriteLine("message: " + message);
System.Diagnostics.Trace.WriteLine("member name: " + memberName);
System.Diagnostics.Trace.WriteLine("source file path: " + sourceFilePath);
System.Diagnostics.Trace.WriteLine("source line number: " + sourceLineNumber);
You can see that this feature can be particular useful during tracing.
The example above has been taken from Caller Information (C# and Visual Basic).
When you develop with Entity Framework, you may need the SQL instruction passed to the SQL engine when your LINQ query is evaluated.
As you can see from the post ToTraceString Method in Entity Framework, both the System.Data.Objects.ObjectQuery and the System.Data.EntityClient.EntityCommand classed implement the ToTraceString() method, whose evaluation returs just the info you need.
An update in EF 6.1 allows to output the generated SQL doing:
context.Database.Log = Console.Write;
after having created the context, as explained in Logging and Intercepting Database Operations.
In Visual Studio it's possible to edit and debug PowerShell scripts, using the PowerShell Tools for Visual Studio 2015 extension.
But even after installing the extension, debugging doesn't immediately work, as trying to do this, the output window simply shows an unauthorized access error message.
I've found the blog post PowerShell Tools for Visual Studio 2013 – unable to run and/or debug PowerShell script – execution policies problem that has helped me in finding the solution:
- from a PowerShell window with elevated privileges,
- run the command "Set-ExecutionPolicy" RemoteSigned