I'm running a custom plugin inside a design program called Autodesk Revit and I recently implemented async usage reporting but this change caused my calling assembly to change.
Prior to this change I was recording the usage synchronously but that was freezing the UI for a second. The change to async is working great but the calling assembly seems to have changed. The reason why I'm saying that is because I was recording the assembly version as part of the usage reports so I know which version of the plugin the user has installed but now the calling assembly changed to mscorlib and it's showing this Microsoft assembly's version.
I've tried the calling assembly, executing assembly and entry assembly but none point to the plugin which called the method. Any ideas?
Version assemblyVersion = Assembly.GetCallingAssembly().GetName().Version;
UPDATE
Thanks all for the comments and suggestions. I managed to get around the issue by synchronously getting the plugin version and passing it as a string parameter to the async method.
This is probably because how async works.
Async methods will be split into different parts that may be executed at different times, hence being "asynchronous". But this means you will loose the callstack in all but the first part. A result of this is that tasks need to be used to return things. "async", Task, and "await" in effect allow you to pretend the method is running as normal, while doing something completely different behind the scene.
If you are inspecting the callstack directly this illusion will break down. You will just see your method being invoked from the thread pool, with little idea what caused the call in the first place. This is most likely the reason why the calling assembly is different.
There are a few possible solutions: