Error 80131534 when loading addin

by johan.sassner 11. August 2008 10:31

Edit 2008-08-13: Problem solved. See below for the initial error.

I was on the completely wrong track (of course). As i said below i'm creating an addin for SSMS, and addins is loaded from whitin SSMS and it looks for a class implementing interface IDTExtensibility2. All i got from in the output log from Visual Studio was two exceptions (System.NullReferenceException and System.TypeInitializationException) and the first should have put me on the right track but it didn't and i've lost 3 days of coding. I didn't get the contents of the exceptions (for example stacktrace or any innerexceptions) so i had nothing to continue my search.

The error message i got was "Error Message: <Unknown Error>. Error number: 80131534", which didn't help me at all. After 3 days i got a hunch and created a new empty project, adding the addin as a reference and executed it.

Connect connect = new Connect();
Array poff = null;
connect.OnConnection(null, Extensibility.ext_ConnectMode.ext_cm_Startup, null, ref poff);
[/code]

Now i got the exception dialog and was able to trace it to a static class with some static member variables using a helper class. In that helper class i had added a .toString() for one of the parameters and ofcourse the static member variables supplied null in the parameter and there is the System.NullReferenceException.

Problem solved!

------------------

I get the error below when trying to load my addin in SSMS. It might be that .Net framework 3.5 seems to be a bit corrupt on my machine since when i try to re-install framework 3.5 i get an error. Today 3.5 sp1 will be released so i'll try that and update this post.

Edit: I tried to do a repair in "Uninstall or change a program" which reported success, but i still get the same error.

Edit: Installed both sp1 of Visual Studio 2008 and sp1 of .Net 3.5 and still same error.

 

---------------------------
Microsoft SQL Server Management Studio
---------------------------
The Add-in 'xxx addin, SQL Server Management Studio Extension' failed to load or caused an exception.
Would you like to remove this Add-in?
If you choose yes, you will need to reinstall the Add-in to use it again.

Error Message: <Unknown Error>
Error number: 80131534
---------------------------
Yes   No  
---------------------------

 

image

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Extending Visual Studio

Dark color scheme

by johan.sassner 1. August 2008 16:52

I've been using a dark color scheme for Visual Studio (using Resharper options) and also in Sql Server Management Studio.

Attached are both the visual studio 2008 settings that you need to import under Tools->Import and Export Settings, and the .reg file that you need to add.

Make a backup of both the VS settings by exporting your old one first, and make a backup of the compete registry key HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\90\Tools\Shell\FontAndColors (i usually just rename FontAndColors before i import the .reg file).

After applying the new files, restart both VS and SSMS.

 NOTE!!! You do this on your own risk. Those files work on my setup, but they may break your machine. I take no responsibility if you destroy your registry.

 

VS2008_20080729.vssettings (15.53 kb)

sql2005_2008-08-01.reg (146.60 kb)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Extending Visual Studio

IOleCommandTarget

by johan.sassner 1. August 2008 13:27

When creating addins to Visual Studio, some times you want to listen for events for example when the user presses the Undo button (or press ctrl+z or what ever shortcut is set).

On the  IVsTextView interface there is a AddCommandFilter you can ask for these kind of events.

Code below.

using System;

using Microsoft.VisualStudio;

using Microsoft.VisualStudio.OLE.Interop;

using Microsoft.VisualStudio.Shell.Interop;

using Microsoft.VisualStudio.TextManager.Interop;

using VsCommands = Microsoft.VisualStudio.VSConstants.VSStd97CmdID;

using VsCommands2K = Microsoft.VisualStudio.VSConstants.VSStd2KCmdID;

 

namespace Sassner..Utils {

    public class MyIOleCommandTarget : IOleCommandTarget, IDisposable {

        #region Member variables

 

        private const string ClassName = "MyIOleCommandTarget";

 

        private readonly IVsTextView activeView;

        private readonly IVsWindowFrame pFrame;

        private uint pwdCookie;

        // Previous IOleCommandTarget

        private IOleCommandTarget prevIOleCommandTarget;

 

        private readonly object[] commands = {

            VsCommands.Paste, Common.enVsCmd.Paste,

            VsCommands.Cut, Common.enVsCmd.Cut,

            VsCommands.Undo, Common.enVsCmd.Undo,

            VsCommands.Redo, Common.enVsCmd.Redo,

        };

 

        private readonly object[] commands2k = {

            VsCommands2K.CANCEL, Common.enVsCmd.Escape,

            VsCommands2K.UP, Common.enVsCmd.ArrowUp,

            VsCommands2K.UP_EXT, Common.enVsCmd.ArrowUp,

            VsCommands2K.UP_EXT_COL, Common.enVsCmd.ArrowUp,

            VsCommands2K.DOWN, Common.enVsCmd.ArrowDown,

            VsCommands2K.DOWN_EXT, Common.enVsCmd.ArrowDown,

            VsCommands2K.DOWN_EXT_COL, Common.enVsCmd.ArrowDown,

            VsCommands2K.COMPLETEWORD, Common.enVsCmd.CompleteWord,

            VsCommands2K.UNDO, Common.enVsCmd.Undo,

            VsCommands2K.UNDONOMOVE, Common.enVsCmd.Undo,

            VsCommands2K.REDO, Common.enVsCmd.Redo,

            VsCommands2K.REDONOMOVE, Common.enVsCmd.Redo,

            VsCommands2K.COMMENTBLOCK, Common.enVsCmd.Comment,

            VsCommands2K.COMMENT_BLOCK, Common.enVsCmd.Comment,

            VsCommands2K.UNCOMMENTBLOCK, Common.enVsCmd.Uncomment,

            VsCommands2K.UNCOMMENT_BLOCK, Common.enVsCmd.Uncomment,

            VsCommands2K.BOL, Common.enVsCmd.Home,

            VsCommands2K.BOL_EXT, Common.enVsCmd.Home,

            VsCommands2K.BOL_EXT_COL, Common.enVsCmd.Home,

            VsCommands2K.HOME, Common.enVsCmd.Home,

            VsCommands2K.HOME_EXT, Common.enVsCmd.Home,

            VsCommands2K.EOL, Common.enVsCmd.End,

            VsCommands2K.EOL_EXT, Common.enVsCmd.End,

            VsCommands2K.EOL_EXT_COL, Common.enVsCmd.End,

            VsCommands2K.END, Common.enVsCmd.End,

            VsCommands2K.END_EXT, Common.enVsCmd.End,

            VsCommands2K.PAGEUP, Common.enVsCmd.PageUp,

            VsCommands2K.PAGEUP_EXT, Common.enVsCmd.PageUp,

            VsCommands2K.PAGEDN, Common.enVsCmd.PageDown,

            VsCommands2K.PAGEDN_EXT, Common.enVsCmd.PageDown,

            VsCommands2K.LEFT, Common.enVsCmd.Left,

            VsCommands2K.LEFT_EXT, Common.enVsCmd.Left,

            VsCommands2K.LEFT_EXT_COL, Common.enVsCmd.Left,

            VsCommands2K.RIGHT, Common.enVsCmd.Right,

            VsCommands2K.RIGHT_EXT, Common.enVsCmd.Right,

            VsCommands2K.RIGHT_EXT_COL, Common.enVsCmd.Right,

            VsCommands2K.DELETE, Common.enVsCmd.Delete,

            VsCommands2K.BACKSPACE, Common.enVsCmd.Back,

        };

 

        #endregion

 

        #region Events

 

        #region Delegates

 

        public delegate bool KeyVsCommandsHandler(object sender, KeyVsCmdEventArgs e);

 

        #endregion

 

        public event KeyVsCommandsHandler KeyDownVsCommands;

 

        #endregion

 

        public MyIOleCommandTarget(IVsTextView activeView, IVsWindowFrame pFrame) {

            this.activeView = activeView;

            this.pFrame = pFrame;

            // Add new listener

            activeView.AddCommandFilter(this, out prevIOleCommandTarget);

            ((IVsWindowFrame2)pFrame).Advise(this, out pwdCookie);

        }

 

        #region IDisposable Members

 

        ///<summary>

        ///Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

        ///</summary>

        ///<filterpriority>2</filterpriority>

        public void Dispose() {

            RemoveMyIOleCommandTarget();

            ((IVsWindowFrame2)pFrame).Unadvise(pwdCookie);

        }

 

        #endregion

 

        #region IOleCommandTarget Members

 

        /// <summary>

        /// Enable commands

        /// </summary>

        /// <param name="pguidCmdGroup"></param>

        /// <param name="cCmds"></param>

        /// <param name="prgCmds"></param>

        /// <param name="pCmdText"></param>

        /// <returns></returns>

        int IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) {

            for (uint i = 0; i < cCmds; i++) {

                if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97) {

                    VsCommands cmd = (VsCommands)prgCmds[i].cmdID;

                    for (int j = 0; j < commands.Length; j += 2) {

                        object command = commands[j];

                        if (cmd == (VsCommands)command) {

                            break;

                        }

                    }

                } else if (pguidCmdGroup == VSConstants.VSStd2K) {

                    VsCommands2K cmd = (VsCommands2K)prgCmds[i].cmdID;

                    for (int j = 0; j < commands2k.Length; j += 2) {

                        object command = commands2k[j];

                        if (cmd == (VsCommands2K)command) {

                            prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED);

                            return VSConstants.S_OK;

                        }

                    }

                }

            }

 

            return prevIOleCommandTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);

        }

 

        /// <summary>

        /// Handle the execution of the command

        /// </summary>

        /// <param name="pguidCmdGroup"></param>

        /// <param name="nCmdID"></param>

        /// <param name="nCmdexecopt"></param>

        /// <param name="pvaIn"></param>

        /// <param name="pvaOut"></param>

        /// <returns></returns>

        int IOleCommandTarget.Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) {

            try {

                if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97) {

                    VsCommands cmd = (VsCommands)nCmdID;

                    for (int i = 0; i < commands.Length; i += 2) {

                        object command = commands[i];

                        if (cmd == (VsCommands)command) {

                            if (null != KeyDownVsCommands) {

                                if (KeyDownVsCommands(this, new KeyVsCmdEventArgs((Common.enVsCmd)commands[i + 1], pguidCmdGroup, nCmdID))) {

                                    return NativeMethods.S_OK;

                                }

                            }

                            break;

                        }

                    }

                } else if (pguidCmdGroup == VSConstants.VSStd2K) {

                    VsCommands2K cmd = (VsCommands2K)nCmdID;

                    bool foundCmd = false;

                    for (int i = 0; i < commands2k.Length; i += 2) {

                        object command = commands2k[i];

                        if (cmd == (VsCommands2K)command) {

                            foundCmd = true;

                            if (null != KeyDownVsCommands) {

                                if (KeyDownVsCommands(this, new KeyVsCmdEventArgs((Common.enVsCmd)commands2k[i + 1], pguidCmdGroup, nCmdID))) {

                                    return NativeMethods.S_OK;

                                }

                            }

                            break;

                        }

                    }

                    if (!foundCmd) {

                        // Common.LogEntry(ClassName, "IOleCommandTarget.Exec", cmd.ToString(), Common.enErrorLvl.Information);

                    }

                }

 

                return prevIOleCommandTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);

            } catch (Exception e) {

                Common.LogEntry(ClassName, "IOleCommandTarget.Exec", e.ToString(), Common.enErrorLvl.Error);

            }

            return NativeMethods.S_OK;

        }

 

        #endregion

 

        private void RemoveMyIOleCommandTarget() {

            try {

                if (null != prevIOleCommandTarget) {

                    activeView.RemoveCommandFilter(this);

                    prevIOleCommandTarget = null;

                }

            } catch (Exception e) {

                Common.LogEntry(ClassName, "RemoveMyIOleCommandTarget", e.ToString(), Common.enErrorLvl.Warning);

            }

        }

 

    }

}

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Extending Visual Studio

Powered by BlogEngine.NET 1.4.5.7
Theme by Mads Kristensen

About the author

I've been working with software for a long time now. Started on ABC80 in the early 80's, then Commodore 64/Amiga. Working as a systemdeveloper today with focus on .Net.

Now proud father of Malte

Page List

Calendar

<<  January 2009  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar