Debugging Office interop assemblies: how to get rid of automatic add-in disable? - office-interop

I know this is not particularly programming related, but some of you here may know the solution.
I have a project using Excel interop in C#, and C++/CLI wrappers for ugly C++ code, all in the same project. I can debug the whole code nicely by attaching the debugger to Excel.
Now, each time I stop debugging (for whatever reason), Excel hard disables my addin. I must open a fresh excel, do 15 clicks to reenable it to start a new debugging session.
I must add that Excel loading times are pretty high, since we use another team's huge XLL (necessary to run my addin).
This behavior is pretty annoying, I'd like to disable automatic disabling of add ins. Does someone knows how to do ? I have no objection to programmatically set/unset registry keys.

Related

Inspecting COM objects in VS 2017 debugger

I'm currently migranting an VBA powerpoint add-in to VSTO.
For weeks I've been struggling with Visual studio degug for COM objescts. AS you can see on the image below, the object types show {system._ComObject} and object inspection becomes a challenge since one must use the dynamic view, which is quite inconvenient in my opinion.
Looking around I've found a recommendation to activate the option "use managed code compatibility mode" in the general debugging settings, as you can see on Debugging setting
I also followed another the recommendation to set the property "Embed interop Types" on all my office related references to false.
After applying these changes. VoilĂ ! The inspection began do work just as I wished to and as you can see here: Debug working properly
I was almost in heaven. My ecstasy lasted till I tried to change some code during debug and was informed by visual studio that
"managed compatibility mode does not support edit and continue".
Now I'm back in hell. With edit and continue I miss a decent COM object inspection. With COM inspection I cannot change code during debug.
This situation looks awkward and I would expect more from VS 2017.
Does anybody know how can I get decent COM inspection and edit and continue at the same time?
Does anybody know how can I get decent COM inspection and edit and
continue at the same time?
I am afraid that you cannnot get what you want.
Since you just debug a com object which is more like optimized, mixed, or SQL Server common language runtime (CLR) integration code(use ), as the official document said, Edit and Continue function does not support it.
Usually, to debug those mixed codes in VS, you should enable Use Managed Compatibility Mode or enable native code debugging, but those options cannot work well with Edit and Continue as the official document said.
You can check this document to know unsupported changes or supported changes to code.
So for your issue, there is no such option to use both of them.
As a suggestion, you should break the debugging process first, make some changes to your code. Then start Debugging to debug the new changes.
Besides, if you still want this feature, you could suggest a feature on our User Voice Forum. The Team will check your request carefully and hope they will give you a satisfactory reply.

VS2010 - Break on events without intellitrace

I have VS2010 professional and Im working with a large code base that Im unfamiliar with. I want to know what code gets executed when a certain event occurs (namely, when I click a specific button). I know this could easily be done with Intellitrace, but that requires an Ultimate subscription (which is outrageously expensive). Is there any other way I can do this? Ideally without installing anything new (even if its free), but thats not a deal breaker.
You can see what .NET code is executed with Runtime Flow (developed by me, 30-day trial).

Can I avoid restarting Outlook as part of the change/test cycle for my VSTO AddIn?

We are developing a small Outlook plugin using VS2010 / VSTO.
It's a new thing for us so we're wondering what's possible and what's not possible in an Outlook plug-in versus our more familiar Winforms stuff. So we're making small piecemeal changes and checking frequently by running it in Outlook.
At the moment our change/test cycle works like this:
In the Visual Studio IDE add, change, fix or extend the code in some small way
F5
Ding! Warning that Outlook is already running. Lose a life.
Close Outlook
F5
Outlook starts, test the change
It's the restarting Outlook that makes it so slow.
Is there any way to debug without restarting Outlook? Or, what would be even better, is there any way to debug-and-continue?
If not, is there anything at all we can do to make this bit of dev a touch more fluent/faster?
As far as I'm aware you can't make code changes and continue debugging. You need to reload Outlook so that it loads in the new DLL. You could always write your own code that monitors a particular DLL and loads it in real-time, eg
Assembly assembly = Assembly.LoadFrom("dllPath");
AppDomain.CurrentDomain.Load(assembly.GetName());
Type t = assembly.GetType("typeName");
Then you can work on your DLL, modify the code and re-load the thing with outlook still running. Probably more hassle than it's worth though.
Outlook 2007 is very quick to start on my machine (but I've got a beefy i5 machine) - it literally takes 2 seconds to open. If your Outlook is really slow to startup, consider doing the following:
Remove all of the other addins that you've got installed in Outlook.
Is it possible that you can detach from your current mailbox and only have an offline one?
Detach from all of your other mailboxes
Install more memory on your machine so that everything is cached (cheap option, memory is very cheap these days)
Close down all other apps on your computer
Setup your mailbox so that it's practically empty
Is Outlook itself taking ages to load? (Eg for the initial splash screen to go away) Or is it chugging away after it's opened?
As far i know, We can't debug outlook while it is already running. Because it can't load our new DLL's until and unless you restart it.
As LachlanB said, We can use AppDomains to load the DLL dynamically and make it work with Outlook. Absolutely It will work, but we are taking control of loading our application's DLL into Outlook process.This might require some additional work on design and coding part. Normally this will be the job of Outlook to load addins DLL.
My Suggestion is, simply don't change your applications design and coding to enable debugging. It's not a best practice. Instead concentrate on, why your outlook is getting loaded very slowly?
You can try LachlanB's second suggestion on configuring outlook to load faster. use that steps to cleanup your outlook. You can also try discussion in MSDN forums http://social.technet.microsoft.com/Forums/en-US/exchangesvrclients/thread/a117fa73-8f19-4716-9603-eb756b609cd5

Is it possible to Edit and Continue in Visual Studio 2010 without pausing execution?

I recently watched a bit of Notch's Ludum Dare live stream. He uses Eclipse's hotswap feature extensively while he works on his game. (here is a video of what I am referring to http://www.twitch.tv/notch/b/302823358?t=86m30s)
I would like to do the same with C# and XNA. Fortunately, Visual Studio has an Edit and Continue feature. However, I would like to edit my rendering code while it is running instead of pausing it.
Is it possible for me to setup Visual Studio to do the same? I noticed that there is a checkbox for Break all processes when one process breaks. Is it maybe possible to set up my rendering loop in another thread so that the game keeps rendering while I make a change?
Update: This answer is now available as a video.
I've been struggling to find a way to do this. I know this doesn't answer your exact question. But really what you are looking for is a workflow where you can make code changes with zero (or near-zero) delay, and I think I've figured out the closest you can get with just Visual Studio. (And therefore avoiding a huge engineering effort and dealing with "abnormal" projects).
The way to achieve this workflow is actually astonishingly simple, once you think of it:
Use shortcut keys!
The first way I came up with is to just use the normal edit-and-continue method of setting a breakpoint. Only by using the keyboard you can do this considerably faster. This only works with code being called in a loop (eg: draw/update). Click the code you want to modify, add a breakpoint (F9), the breakpoint will almost immediately be hit, modify your code, remove the breakoint (F9), and then run the code again (F5).
This is pretty good. You don't have to use the mouse to hit the relatively small "Add breakpoint" target in the left hand column. But it does move the input focus to the beginning of the line, so you generally have to use the mouse again to fix that before you can start editing.
I want something faster. So I came up with a better solution:
Again, using the keyboard: Press Ctrl + Alt + Break to "Break All". This enters the debugger almost instantly, without having to worry about setting a breakpoint or if the code you want to modify is running in a loop. This will change the editor window and caret focus to the document where execution break, but you can then immediately fix it by pressing Ctrl + - for "Navigate Backwards".
Then you can make your edits and simply press F5 to see them in action. You only have to use the mouse once (or not at all) to initially pick where you want to start typing - just as you would expect.
Admittedly Ctrl + Alt + Break and Ctrl + - are horrible key combinations for something you want to be able to do extremely quickly. And it would be better if there was just one key to press.
If you have the full Visual Studio, you could probably turn it into a macro or add-in. Express doesn't have those - so the best you can do is modify your key bindings (Tools, Customise, Keyboard...) and bind it to two keys that are adjacent, that you can press in quick succession. Or use an external macro utility.
Personally I have set up the two key combinations to be pressed in succession (you don't seem to need a delay between the two) by a macro set to a spare button on my mouse. Which works reasonably well - as I'm usually selecting text at the same time. I might add a keyboard macro later too.
So far I've identified two minor pitfalls of this method:
When you run the app again, Visual Studio gives it focus. It would be nice if it kept focus. Adding a left mouse click to my macro is a partial solution to quickly re-editing code.
"Navigate Backwards" does not retain the text selection, only the caret position.
i can tell you how, but you arn't going to like it:
1) run your game executable in a visual studio instance (game.exe --> vsInstanceA)
2) code your modifiable code in a seperate dll, using a seperate visual studio instance (modifiable.dll --> vsInstanceB)
*note that doing this lets you compile your modifiable.dll, thus doing compile time error checking, etc.*
... and now is where it get's tricky ...
3a) game.exe needs to reference the modifiable.dll. NOT the .vcproj, the actual dll
3b) when you hit a "magic key" (have game.exe look for a key-press), have game.exe unload the modifiable.dll, and reload it. You can easily do this via the Assembly and AppDomain classes provided in mscorlib. Of course this means you need to unload any dependant systems in game.exe.
note, there's a lot of hand-waving in this 3b) section, it's quite a lot of work but pretty straight forward (example google search: https://www.google.com/search?q=dynamic+load+dll+.net)
... and after that, you are good to go ...
3-alt) some other choices if 3b) doesn't suit you:
you can invoke msbuild.exe to rebuild modifiable.dll when you press
"magic key"
you can use the CSharp compiler dll's to dynamically
recompile each class instead of the entire modifiable.dll
but unfortunatly, in my 10+ years of .net development, this is the only way, unless someone has created a 3rd party product to do it (IE: they do what i mentioned, for you)
This may not be exactly what you're looking for but it's what I've been doing. Just throw in a break point while your game is running. Once it's stopped, you can edit things, remove the break point, and then hit F5 to continue.
For the most part, this allows you to edit things while the game is running and continue running the game afterwards but it doesn't work for everything. You can't add or remove class level things and also can't add/remove entire functions or the parameters. Mostly, I do this to test out different numbers and equations for smaller things that get hit every update.
To answer the original question "in Visual Studio 2010 without pausing execution?"
No. For Java there is JRebel which allows this.
I can quickly imagine why Microsoft haven't done this - if you have some sort of committee or group of people designing things - it's easy for even one person to come up with good arguments where this "dynamic software updating"/hotswap will break. It's just too easy to shoot down. Or if they proceed with it, it will be through some entirely new "enterprise framework" that requires lot of steps, work and understanding to get anywhere, because they want to use it for complicated online scenarios.
I'd prefer there was some simple way to do this - I'll take the risks, and put up a lot of disclaimers that if you want hotswap services that talk to external systems then you need to use that complicated framework or whatever.
The most typical scenario where this could safely be used with low risk is prototyping and tweaking some sort of engine with either high startup cost or more likely, to study behaviour if something running in the engine (like rules) is buggy and to exhibit the bug, a lot of things has to happen and it's possible you don't encounter the bug always. That is the case where having this could save weeks of debugging time, atleast would have in my case.
I'm used to work in Java using IntelliJ Idea + DCEVM (Dynamic code evolution VM).
Unfortunately i haven't found anything getting closer to that configuration at Microsoft C# platform. It really sucks and you can't do much about it. You can use some user defined macros, but you can't still do much in Edit and Continue mode without restarting Debug session).
However if you can, try to use newest .NET Core which offers much better productivity using Dotnet Watch. Still not so fast as DCEVM but much better than traditional VS + .NET hot reload experience. Details here.

Break on Arbitrary Event in Visual Studio

I'm trying to trace some legacy code at work, Visual Studio 2003 and .Net 1.1. There are actions done on Keypress and Text change that I know happen but, the Text fields themselves are made dynamically or are a control. I need to find the code that is executed when these things happen. Because of some poor architecture decisions on this piece of software the code is very spaghetti and hard to manually figure out.
What I would like to do is set Visual Studio into a mode where it would break when a specific event is handled regardless of the handler. This way I can get into the code and see through what is being done to make the translations and set variables.
Ultimately I'm trying to trace down when this code accesses the database to do lookups and updates so, allowing to watch for when a database connection happens would also be helpful and achieve much the same thing.

Resources