debug ASP.NET MVC system code in Azure Compute Emulator - asp.net-mvc

I'm developing an ASP.NET MVC (still v2) Azure web application. I've run into a problem that seems to require me to step through the MVC code itself. I can do this but also need to be able to inspect the code as I step, so I need to be an unoptimized version (so as to not get the "Cannot obtain value of local or argument ...") message in the debugger.
The standard way of circumventing the optimizations (http://blogs.msdn.com/b/sburke/archive/2008/01/29/how-to-disable-optimizations-when-debugging-reference-source.aspx) doesn't seem applicable to running in the Compute Emulator.
I also tried this by creating a local debug build of the System.Web.Mvc project but my web role hangs when I try to start it in the Compute Emulator.
So ... Any help with either of the following would be much appreciated:
Running an Azure web app in Visual Studio (2010) so that it will ignore code optimizations in system dlls.
OR
Creating a local system debug build so that it can be referenced by an Azure web app being debugged in the Compute Emulator.

If the Azure Compute Emulator is giving you issues you could run your MVC project using IIS Express. Just right click and and Select Debug/Start New Instance.

I was finally able to get unoptimized ASP.NET code while debugging in the compute emulator. The basic approach described on MSDN (http://msdn.microsoft.com/en-us/library/9dd8z24x%28v=vs.100%29.aspx) and elsewhere (http://martin.bz/blog/asp-net-mvc-source-debugging-the-easy-way among others) is to put an .ini file that tells the JIT compiler not to optimize in the same directory as the DLL.
The first challenge was to determine just where that was; it finally dawned on me to watch the logs in the Compute Emulator UI and see where they loaded the DLL (in this case System.Web.Mvc) from.
The second challenge was getting the .ini file there. Windows Explorer didn't work because it uses a different way of viewing assembly caches that doesn't give you direct access to the files. One of the posts I read reminded me that using the Command Prompt might give me that access and it did. The last step was realizing, when the Command Prompt wouldn't permit me to move the .ini file into the assembly directory, that I needed to run Command Prompt as admin.
Once I could view variables while debugging, I pretty quickly realized where my bug was.

Related

AspNetZero V8.0 - Debugger ends immediately

I just started coding with AspNetZero V8.0 solution. I purchased this version a couple of years ago. I had kept the raw downloaded solution in a GIT Repo without any changes.
Recently I downloaded the code for use in my project. All I have done so far is setup connection string, setup a tenant and logged into a tenant. After I got all that working I started development for my first domain class "Country". I have setup the domain classes, interfaces, application service and EF migration. All of this worked without any issues.
Now I have setup app service for Country domain and I am trying to test it from chrome console, as per the AspNetZero docs here. When I test the service I'm getting an error in the console and an error is getting logged in the AuditLogs table too. So in order to identify my issue with app service, I decided to debug the code. This is where my problem exists.
I am able to start the debugger. I see the chrome browser window open up, I see VS2019 (v16.8.4) switch to debug layout. After about 30+ seconds the browser closes and VS2019 returns to normal mode, not in debug, layout. I do not get any errors logged in chrome console, windows event log or in VS2019 output.
I have read many threads on SO about similar issues and tried many different VS2019 option changes, nothing seems to make a difference.
I tried a couple of other solutions, AspNetZero and other .NET Core, in VS2019 and I am able to debug them normally.
Has anyone else run into similar issue with AspNetZero solution or any other type of solution?
This is because they run the YOURCOMPANY.Web.Host as .exe OutputType.
To run and debug the project, open CMD on the YOURCOMPANY.Web.Host location then execute dotnet run
After that:
Attach to a running process on your local machine
In Visual Studio, select Debug > Attach to Process (or press
Ctrl+Alt+P) to open the Attach to Process dialog box.
Check the Connection type.
In most scenarios, you can use Default. Some scenarios may require a different connection type. For more info, see other sections in this article or Common debugging scenarios.
Set the Connection target your local machine name.
Finally, attach.
For more information:
Attach to running processes with the Visual Studio debugger

Why is my app not using scaffolded Identity pages?

I have an app where I wish to focus on some Identity function enhancements, e.g. password generation etc. I have used "Add scaffolded item->Identity", and each Identity page seems complete and fine.
Yet when I put breakpoints e.g. in the ctor of Login.cshtml.cs, they are not hit, as if the compiled Identity pages are still running the show.
What have I missed in scaffolding out the pages?
Please consider the followings:
Make sure that VS not switched to Release mode (instead of Debug
mode)
If possible, run your VS as the admin, check it. Maybe you could try
to change the platform target(Any CPU, X86, X64).
To make sure that the symbols are loaded for your app, I think you
would get more information from the Output window, see Specify symbol (.pdb) and source files in the Visual Studio debugger (C#, C++, Visual Basic, F#) and PDB Files: What Every Developer Must Know .
Make sure that it has the same framework version when you use the
attach process, see this.

What is the purpose of "building" a .NET MVC application if it runs fine without it?

I have a simple MVC Web application in the .NET Framework. To run it, I can click the green arrow ("play" button) in Visual Studio, which does a "build" and starts a Web browser pointing to the application.
Or, I can just start up IIS Express with the proper command line options, and navigate to localhost:8080 in a browser and run the application without a "build".
What is the purpose of "building" the application in Visual Studio if it runs fine without it?
The simple answer is that it doesn't run without the build step; your assumptions are wrong.
However, Visual Studio continuously monitors your source files and compiles them, e.g. to be able to show intellisense suggestions and compiler errors while you type. This means that there are in fact compiled binaries based on your source somewhere, maybe just not in the bin folder under your project root (that somewhere might be in memory, or in some cache location on disk, depending on circumstances out of scope for this question).
It's also very likely that you've previously built your application, resulting in binaries in your bin folder, even if you didn't do it with the purpose of running the application right after. In either case, if you get it working with IIS Express it's because it can find compiled binaries somewhere, and run those.
The main reason to have Visual Studio explicitly rebuild your app when you hit play, is to make sure that you're running the latest version of your code. Sure, it takes a few extra seconds every time you start the debugger, but it's nothing compared to the time you'd lose trying to track down a bug that you've already fixed in your code, but which still manifests in the running application, because the running application is an outdated version. (It also makes things like stepping through the code much less confusing, since, again, the source code on file will always be in sync with the running application.)

How can I activate Xamarin.Android for use on a CI server?

My company owns several business licenses for Xamarin.Android, and we'd like to use this on our CI server. However, it seems that I'd need to install the full Xamarin suite on my CI server including Visual Studio Pro to make this work. My question is, using the vanilla Xamarin.Android package, how can I activate it?
It seems that installing this on its own adds the Xamarin.Android tools and libraries to build with but there is no way to activate it that I can find, so when I attempt to build using MSBuild, the build fails with this error:
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(299,2): error XA9008: Building from the command-line requires aÿBusinessÿLicense.
Now, after some googling, I have found that the activation tool is called "mandroid.exe", which can be found in C:\Program Files (x86)\MSBuild\Xamarin\Android - although I have found references to this being in the 64-bit program files too.
Unfortunately, I can't find any suitable documentation on this tool. Every time I find a thread where someone discusses this, someone from Xamarin jumps in and says "contact support#xamarin.com". After a while I did that but two business days later there still is no response and I've got deadlines to meet so I thought it might be helpful for everyone involved for us to publicly document this process.
The best thing I've found comes from a thread on the Xamarin mailing list which references this invocation:
mandroid.exe --activate --name "NAME" --company "COMPANY" --email "EMAIL" --phone "PHONE" --code "ACTIVATION CODE"
I have also discovered another variant of this invocation that looks like this:
.\mandroid.exe –activate –activation-name="NAME" –activation-phone="PHONE" –activation-company="COMPANY" –activation-code="CODE" –activation-email="EMAIL"
I've tried many permutations of my account data here using both invocations - using the activation code from the products page on the Xamarin store. No matter what though, this error occurs:
\mandroid.exe : monodroid: error XA9997: Incomplete data provided to complete activation
In the "problems activating?" section of the products page, it says this:
In Mono for Android 1.0.21316 and later, if activation within Visual Studio fails then a MfaActivation.dat file will be created within the Documents folder. Select this file below.
Perhaps there's some way to force this file to be created by mandroid.exe? That would be very helpful. While I imagine that offline activation is the only way to make this work, I would accept any answer that involves uploading MfaActivation.dat or otherwise invoking the online activation machinery as well.
Update - I'm afraid that the below steps no longer work. Xamarin has updated their activation system to activate by a different method for newer versions.
In the end I had to install Xamarin Studio as part of the Chef configuration and just instruct administrators to manually activate the software as part of creating a new build node. I had no luck trying to reverse engineer a fix, and if I did, it would probably just break again.
It turns out that I almost had it correct. The second invocation I specified is actually the correct way to call this command but the -- part was apparently converted to a – token by some blog software somehow.
The --activate verb will perform an online activation with Xamarin's servers, so I'm still not sure how you'd do it without an internet connection.
For reference, here is how I did it:
mandroid.exe -v --activate --activation-name "(NAME)" --activation-phone "(PHONE_" --activation-email "(EMAIL)" --activation-company "(COMPANY)" --activation-code "(CODE)"
I'm not sure about the significance of the -v switch, but perhaps that would make it output debugging info if there was a problem.
You must enter all the information exactly as specified on your products page - select one of your licenses and select "problems activating?". However, you will need to enter the licensee name - i.e. the user who owns the license in the --activation-name parameter which must correspond to the --activation-code parameter.
After doing this you can call mandroid with the --activated switch which returns an exit code:
PS> & .\mandroid.exe --activated
PS> $LastExitCode
0
You will also be able to reload the products page and you should see that your license for the chosen user has a new computer registered to it.
This does use up another activation but if you e-mail the support team you can sign the build server agreement and then I assume they can set you up with additional activations for your build nodes.
It's a shame that this wasn't documented better because this has wasted my time for several days. Hopefully this will be helpful to someone else with the same situation.
From Xamarin documentation, we can see
http://docs.xamarin.com/guides/cross-platform/ci/configuring_tfs/
"Visual Studio Professional (or greater) must be installed on the Team
Foundation Server along with licensed copies of Xamarin.Android and
Xamarin.iOS to support development of Android and iOS mobile
applications via the Team Foundation Server."
So I assume that in all cases you need to have VS + Xamarin products installed and activated.
I might be wrong, so the best way is to contact Xamarin support, http://xamarin.com/support

Why does my MVC4 project not have debug and release folders under the bin folder?

When I build my app, I just get a single bin folder, with all files in it, versus the usual bin\debug and bin\release folders. Why is this?
Because the website can be run by IIS ( and the various flavours of... ) in the location you built.
IIS expects the assemblies in the bin folder ( it's hard wired in the AppDomain setup ) so the web project type compile to this location.
For an interview, i was put across with this question. One of the link could be this which answers in brief .
The above link will give you the statement as below:-
Release Mode
When an assembly is built in release mode, the compiler performs all
available optimisations to ensure that the outputted executables and
libraries execute as efficiently as possible. This mode should be used
for completed and tested software that is to be released to end-users.
The drawback of release mode is that whilst the generated code is
usually faster and smaller, it is not accessible to debugging tools.
Debug Mode
Debug mode is used whilst developing software. When an assembly is
compiled in debug mode, additional symbolic information is embedded
and the code is not optimised. This means that the output of the
compiler is generally larger, slower and less efficient. However, a
debugger can be attached to the running program to allow the code to
be stepped through whilst monitoring the values of internal variables.
[Update] After little google i came across similar question- "Confused about Release/Debug folders in Visual Studio 2010" with same answer which i have quoted above.
Also, please look into why-have-separate-debug-and-release-folders-in-visual-studio. #riko and other members of Stackoverflow have answered quiet well..
This behavior is not specific to MVC4. In fact it is consistent with so-called "classic" ASP.Net, both Web Site projects and Web Applications.
The distinction between release and debug modes in ASP.Net is that Release builds need to be Published.

Resources