Bug 48505 - The type initializer for 'XamarinProfiler.Windows.Core.XMASession' threw an exception
Summary: The type initializer for 'XamarinProfiler.Windows.Core.XMASession' threw an e...
Status: VERIFIED FIXED
Alias: None
Product: Profiler
Classification: Xamarin
Component: Windows ()
Version: 1.0.x
Hardware: PC Windows
: High critical
Target Milestone: 15.1
Assignee: Jose Miguel Torres
URL:
Depends on:
Blocks:
 
Reported: 2016-12-01 00:55 UTC by Kent
Modified: 2017-03-20 13:31 UTC (History)
7 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Log from timeout (2.35 KB, text/plain)
2017-01-03 06:02 UTC, Kent
Details
Another log (3.82 KB, text/plain)
2017-01-03 08:50 UTC, Kent
Details
Version Info (4.54 KB, text/plain)
2017-01-03 08:51 UTC, Kent
Details
Updated version information (4.54 KB, text/plain)
2017-01-05 04:18 UTC, Kent
Details
Updated profiler log (6.48 KB, text/plain)
2017-01-05 04:19 UTC, Kent
Details
Profiler log against Android (3.01 KB, text/plain)
2017-01-05 04:25 UTC, Kent
Details
Log for 1.1.6.39 (2.64 KB, text/plain)
2017-01-29 05:54 UTC, Kent
Details
Trying to set Enable profiling (169.44 KB, image/gif)
2017-02-06 23:24 UTC, Kent
Details
Latest Profiler logs (57.15 KB, text/plain)
2017-03-20 13:31 UTC, Alok Kulkarni
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Kent 2016-12-01 00:55:12 UTC
I'm trying to use the profiler (V1.0.0.24) with VS2015 on Windows. When I attempt to start a profiling session this message appears in the status bar of the profiler window:

Sorry, something went wrong trying to run MY.app: The type initializer for 'XamarinProfiler.Windows.Core.XMASession' threw an exception

The log file for the profiler ends with this:

System.TypeInitializationException: The type initializer for 'XamarinProfiler.Windows.Core.XMASession' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Xamarin.Messaging.VisualStudio, Version=4.2.1.60, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies. The system cannot find the file specified.
   at XamarinProfiler.Windows.Core.XMASession..cctor()
   --- End of inner exception stack trace ---
   at XamarinProfiler.Windows.Core.XMASession.Disconnect()
   at XamarinProfiler.Windows.MainWindow.<OnClosing>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
XamarinProfiler.Core.Profiler Error: 0 : [2016-12-01 10:57:58.0653] Domain UnhandledException 
XamarinProfiler.Core.Profiler Error: 0 : [2016-12-01 10:57:58.0653] Domain UnhandledException
Comment 1 Rodrigo Moya 2016-12-01 15:50:26 UTC
What version of XVS do you have installed on your windows machine? It needs to be the same than the one used by the profiler, which in the case of the stable Xamarin channel, is 4.2.1.64, so please make sure you have the latest stable Profiler (1.0.2) and the latest XVS from the stable channel. Both should be available from the Xamarin updater inside VS.

Does that fix it?
Comment 2 Kent 2016-12-01 23:58:09 UTC
Such a terrible experience...

I upgraded my VS from 4.2.1.62 to 4.2.1.64. But I got exactly the same problem (and confirmed the log output is the same).

So I figure maybe my profiler is out of date (despite downloading it just a few days ago). I check and can see it's 1.0.0.24. But there's no check-for-updates anywhere I can see. So I seem to have little choice but to go off to the website and check there. No version listed. Literally have to start the download and check the file name to see if it looks different. It did.

I install the profiler update and it starts up the app on the simulator, but does nothing in the profiler apart from say "Please wait". I have no choice but to quit the simulator and profiler and try again. Now I get "The app cannot be profiled" in VS. I try again. Now it starts again, but the profiler just displays "Please wait" again.

I throw my arms in the air.
Comment 3 Kent 2016-12-01 23:59:50 UTC
If the profiler version is so inextricably tied to the XVS version, why on Earth isn't it bundled with the XVS installer? Hell, just a check box that's disabled by default. You check it, and it downloads the appropriate profiler version for you.
Comment 4 Rodrigo Moya 2016-12-02 12:11:51 UTC
Hi Kent

The profiler is now integrated with the Xamarin VS updater, so when you update the other products, the profiler should also be updated, with the correct version to match the XVS one. Doesn't it show up for you in the XVS updater (Tools->Options->Xamarin)?

You need Xamarin.Profiler 1.0.2 and XVS 4.2.1.64, which both should be in the stable channel of the XVS updater, so please check that, if not, it's probably a bug in the installer/updater.
Comment 5 Kent 2016-12-04 23:12:27 UTC
Hi Rodrigo,

I'm not sure I follow exactly, but I have _never_ seen anything other than the XVS extension turn up in Tool/Options/Xamarin/Check Now. Are you saying I should see other tooling turn up there?

That said, I can confirm my profiler is now at 1.0.2.2 (updated manually).

I just tried a complete clean and rebuild of my project, and for now it is working.
Comment 6 Rodrigo Moya 2016-12-14 09:20:20 UTC
With the release of the profiler 1.0, it is part of the Xamarin installer/updater, so it should show up with the rest of the Xamarin packages. Is it not doing that for you?
Comment 7 Kent 2016-12-14 10:05:34 UTC
Please clarify what you mean. Show up where? Do you mean in VS when I do Tools/Options/Xamarin/Other/Check? Or do you mean inside the installer UI?

Either way, I repeat: I have never seen the profiler listed in either of these locations. However, when I install updates I just quickly click through the defaults. Is it smart enough to detect I have the profiler installed and auto-select it if I do?
Comment 8 John Miller [MSFT] 2016-12-15 14:17:38 UTC
Filed a new issue for the profiler not appearing in the VS updater: https://bugzilla.xamarin.com/show_bug.cgi?id=50102

@Kent, please update this bug with your version information and logs now that you profiler is up-to-date.
Comment 9 Kent 2017-01-03 06:02:41 UTC
Created attachment 19056 [details]
Log from timeout

Seems I get a different error every time I try and profile. This time around: a time out.
Comment 10 Kent 2017-01-03 08:50:03 UTC
Created attachment 19059 [details]
Another log

Here's another log, this time with a disconnect.
Comment 11 Kent 2017-01-03 08:51:19 UTC
Created attachment 19060 [details]
Version Info

And here is my version info. Since the Profiler isn't listed, it reports 1.0.2.2 from Help/About.
Comment 12 Kent 2017-01-05 04:18:18 UTC
Created attachment 19086 [details]
Updated version information

I've just updated to latest stable, and here is the new version info. Also, I updated the profiler to 1.1.2.31.
Comment 13 Kent 2017-01-05 04:19:12 UTC
Created attachment 19087 [details]
Updated profiler log

Here is the log from attempting to profile the app again after the above updates.
Comment 14 Kent 2017-01-05 04:25:40 UTC
Created attachment 19088 [details]
Profiler log against Android

And here's another profiler log, running the same app but this time on Android (Nexus 5, all instruments enabled). It worked for about 5-10 seconds and then the profiler crashed. Log looks unhelpful.
Comment 15 Kent 2017-01-29 05:54:02 UTC
Created attachment 19619 [details]
Log for 1.1.6.39

And here's another, running on Android with latest profiler (1.1.6.39). I just get a crash a few seconds after starting the profile session.
Comment 16 Kent 2017-01-29 06:36:51 UTC
Since the profiler log is useless with respect to these crashes, I just attached a debug session to the profiler to catch it in the act of crashing.

Here's the stack trace:

System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.ValueCollection.Enumerator.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem..ctor(CallTreeNodeItem parent, CallTreeNode calltreenode, ProfileRun run, Boolean isInverted)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem.<CallTreeChildren>b__76_0(CallTreeNode node)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem..ctor(CallTreeNodeItem parent, CallTreeNode calltreenode, ProfileRun run, Boolean isInverted)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem.<CallTreeChildren>b__76_0(CallTreeNode node)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem..ctor(CallTreeNodeItem parent, CallTreeNode calltreenode, ProfileRun run, Boolean isInverted)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem.<CallTreeChildren>b__76_0(CallTreeNode node)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem..ctor(CallTreeNodeItem parent, CallTreeNode calltreenode, ProfileRun run, Boolean isInverted)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem.<CallTreeChildren>b__76_0(CallTreeNode node)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem..ctor(CallTreeNodeItem parent, CallTreeNode calltreenode, ProfileRun run, Boolean isInverted)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem.<CallTreeChildren>b__76_0(CallTreeNode node)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem..ctor(CallTreeNodeItem parent, CallTreeNode calltreenode, ProfileRun run, Boolean isInverted)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem.<CallTreeChildren>b__76_0(CallTreeNode node)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem..ctor(CallTreeNodeItem parent, CallTreeNode calltreenode, ProfileRun run, Boolean isInverted)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem.<CallTreeChildren>b__76_0(CallTreeNode node)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem..ctor(CallTreeNodeItem parent, CallTreeNode calltreenode, ProfileRun run, Boolean isInverted)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem.<CallTreeChildren>b__76_0(CallTreeNode node)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem..ctor(CallTreeNodeItem parent, CallTreeNode calltreenode, ProfileRun run, Boolean isInverted)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem.<CallTreeChildren>b__76_0(CallTreeNode node)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at XamarinProfiler.Windows.ViewModels.CallTreeNodeItem..ctor(CallTreeNodeItem parent, CallTreeNode calltreenode, ProfileRun run, Boolean isInverted)
   at XamarinProfiler.Windows.ViewModels.AllocationsViewModel.<ConvertNodeItems>b__105_0(CallTreeNode item)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at XamarinProfiler.Windows.ViewModels.AllocationsViewModel.CallTreeServiceDataChanged(BaseService`1 baseService, ICallTree data)
   at XamarinProfiler.Instruments.BaseService`1.<>c__DisplayClass23_0.<<UpdateData>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_1(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
Comment 17 John Miller [MSFT] 2017-01-29 14:06:43 UTC
Updating this to NEW per all the information Kent has provided. 

@Rodrigo, if there is something specific you need from Kent, please comment.
Comment 18 Rodrigo Moya 2017-01-30 22:37:17 UTC
The last couple of logs for Android runs seem to be a different bug. The previous ones were all, it seems, related to the version mismatch with XamarinVS. Profiler latest in stable is 1.0.5, so make sure you have that installed with the latest XamarinVS from the stable channel. That combination should work for the iOS case. If the versions don't match, they won't work.

As for the 2 last logs, which are on Android runs, @josemiguel please have a look.
Comment 19 Kent 2017-01-30 22:54:59 UTC
Thanks Rodrigo.

But I think we're back at square one. As per comment 2, my update experience has *never* shown me the profiler, nor has it ever installed it for me. I've always had to go and get it manually from https://www.xamarin.com/profiler, which gives me no option to choose between stable/beta/alpha. That explains why I have a mismatch between XVS and the profiler version, because I am having to do this manually.

So, the question is, how do I get my update experience to work so that it detects and installs the correct profiler for my selected channel (stable)?

I will gladly screen share to resolve this issue.
Comment 20 Rodrigo Moya 2017-02-01 16:38:35 UTC
Hi Kent

Profiler 1.0.5 can be downloaded from https://developer.xamarin.com/releases/profiler/profiler-1.0/profiler-1.0.5/ but make sure you have the latest XamarinVS from the stable channel. That should be enough for the original bug, which was the version mismatch.

Now, there's also a SSH timeout in one of your logs, and then the "Collection was modified" crash, which we have already fixed (profiler 1.1.7 -> https://developer.xamarin.com/releases/profiler/profiler-1.1/profiler-1.1.7/), but for using this profiler version you would need to switch XamarinVS to the beta or alpha channel, because of the version mismatch problem in 1.0.x.
Comment 21 Kent 2017-02-01 21:20:20 UTC
Thanks Rodrigo.

I will install 1.0.5 manually for now and continue this thread if I still get problems.

I've opened #52227 to try to get a resolution to the updater problem.
Comment 22 Kent 2017-02-06 01:25:44 UTC
@Rodrigo

Well, 1.0.5 seems to work OK with Android (although snapshots still don't work, but I'm not sure they're supposed to yet).

On iOS, however, things still aren't working. I just get an infinite "Please wait" message and the logs eventually show a time out:

XamarinProfiler.Core.Profiler Information: 0 : [2017-02-06 11:46:23.7924] initializing android platform
XamarinProfiler.Core.Profiler Information: 0 : [2017-02-06 11:46:23.7954] initializing ios platform
XamarinProfiler.Core.Profiler Information: 0 : [2017-02-06 11:46:23.7954] initializing mlpd platform
XamarinProfiler.Core.Profiler Information: 0 : [2017-02-06 11:46:23.7984] ##########################################
XamarinProfiler.Core.Profiler Information: 0 : [2017-02-06 11:46:23.7994] # Xamarin Profiler version -  1.0.5.1
XamarinProfiler.Core.Profiler Information: 0 : [2017-02-06 11:46:23.7994] #  * Arch x86_64
XamarinProfiler.Core.Profiler Information: 0 : [2017-02-06 11:46:23.8320] ##########################################
XamarinProfiler.Core.Profiler Information: 0 : [2017-02-06 11:46:31.9764] Initializing profiling...
XamarinProfiler.Core.Profiler Information: 0 : [2017-02-06 11:46:32.8528] Connecting to 192.168.10.7 as kent
XamarinProfiler.Core.Profiler Information: 0 : [2017-02-06 11:46:32.8808] StartRecording for au.com.codeheroes.qut
XamarinProfiler.Core.Profiler Information: 0 : [2017-02-06 11:46:38.6541] Deploying profiler agent to 192.168.10.7
XamarinProfiler.Core.Profiler Information: 0 : [2017-02-06 11:46:38.7373] Starting listener on port 58277
XamarinProfiler.Core.Profiler Information: 0 : [2017-02-06 11:46:38.7378] Starting au.com.codeheroes.qut on iPad
XamarinProfiler.Core.Profiler Error: 0 : [2017-02-06 11:47:38.4687] error occured on run au.com.codeheroes.qut didn't get a connection from the Mac agent after 30 seconds, terminating
XamarinProfiler.Core.Profiler Error: 0 : [2017-02-06 11:47:38.4687] error occured on run au.com.codeheroes.qut didn't get a connection from the Mac agent after 30 seconds, terminating
XamarinProfiler.Core.Profiler Information: 0 : [2017-02-06 11:47:38.4687] Sorry, something went wrong trying to run au.com.codeheroes.qut: didn't get a connection from the Mac agent after 30 seconds, terminating
XamarinProfiler.Core.Profiler Information: 0 : [2017-02-06 11:47:38.4757] Stopping remote application
XamarinProfiler.Core.Profiler Error: 0 : [2017-02-06 11:47:38.4982] Error occured on run au.com.codeheroes.qut: didn't get a connection from the Mac agent after 30 seconds, terminating
XamarinProfiler.Core.Profiler Error: 0 : [2017-02-06 11:47:38.4982] Error occured on run au.com.codeheroes.qut: didn't get a connection from the Mac agent after 30 seconds, terminating
Xamarin.Messaging.Client.MessagingClient Error: 0 : An error occured on client profiler12872Kent while executing a post for topic xp/1.0.5.1/stop-profiling
System.TimeoutException: The operation has timed out.
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Xamarin.Messaging.Client.MessagingClient.<PostAsync>d__23`2.MoveNext()
XamarinProfiler.Core.Profiler Error: 0 : [2017-02-06 11:47:48.5237] error occured on run au.com.codeheroes.qut An error occured on client profiler12872Kent while executing a post for topic xp/1.0.5.1/stop-profiling
XamarinProfiler.Core.Profiler Error: 0 : [2017-02-06 11:47:48.5237] error occured on run au.com.codeheroes.qut An error occured on client profiler12872Kent while executing a post for topic xp/1.0.5.1/stop-profiling
XamarinProfiler.Core.Profiler Information: 0 : [2017-02-06 11:47:48.5237] Sorry, something went wrong trying to run au.com.codeheroes.qut: An error occured on client profiler12872Kent while executing a post for topic xp/1.0.5.1/stop-profiling

This was true when trying to analyze on the simulator or on device.
Comment 23 Rodrigo Moya 2017-02-06 16:27:12 UTC
hmm, this last log looks a bit "better", at least it is connecting and deploying the ProfilerAgent to the Mac side, so I'd say this is either:

* ProfilerAgent crashing, in which case, please attach its logs, which are in ~/Library/Logs/Xamarin-4.2/ on the Mac side.
* The app not being rebuilt with profiling support: this would be bug #44253
Comment 24 Kent 2017-02-06 23:24:18 UTC
Created attachment 19742 [details]
Trying to set Enable profiling

Aha! You're right about the profiling setting. But I know I've checked this option before and saved the project afterwards. I've just take a look into this and found a rather large problem...

No matter how many times I check the Enable profiling checkbox, it reverts back again. Don't believe me? I don't blame you. I've attached a screen recording.

Where to from here?
Comment 25 Kent 2017-02-06 23:24:58 UTC
Also, why does XVS even *allow* you to start profiling without the Enable profiling option selected? Surely it could detect that and saving you a lot of trouble with a simple message box?
Comment 26 Rodrigo Moya 2017-02-07 15:50:38 UTC
hmm, this was a bug that was fixed in XVS some time ago, so @mag maybe it's not in the C8 builds?
Comment 27 Kent 2017-02-09 22:45:01 UTC
Updating this to NEW again, since I cannot provide any more info at this stage.
Comment 29 Luis Aguilera 2017-02-18 00:21:36 UTC
C9 is now closed. We'll move this bug to the next scheduled milestone, "15.1". We'll continue working on these issues, and will attempt to resolve them ASAP.
Comment 30 Jose Miguel Torres 2017-02-21 07:20:48 UTC
This bug is already fixed on Cycle9.
Comment 31 Alok Kulkarni 2017-03-20 13:31:32 UTC
Created attachment 20463 [details]
Latest Profiler logs

Verified on Profiler build version 1.4.0.0