Cull'log

Stefan Cullmann's Blogging

<November 2008>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456


Navigation

CodeGen

Blog roll

Nice to have

Code Generation

Subscriptions

Post Categories

Article Categories



Adventures writing Visual Studio Add-Ins

I thought it would be nice to integrate an ASP.NET like template language inside my Greenator-AddIn. Instead of reinventing the wheel, I decided to use the m3rlin.engine Assembly. m3rlin is a XML-centric templating code generator by Joseph Cooney. It generates code by hosting the ASP.NET runtime.
In my last post, I described an issue about creating an appdomain; which is needed to host the asp.net runtime. This problem was solved in signing the assembly and publishing the assembly in the GAC.
Today I examined another really strange behaviour inside of Visual Studio Add-Ins. M3rlin.engine calls HttpRuntime.AspInstallDirectory(), and that call gets me a System.ArgumentNullExeption (Parameter name str). First I thought that I might not be allowed to call it inside of a com interop. I decided to examine this in a separate add in. I generated a new visual studio add in (“AddInTest”) and placed the following code inside the Connect class.:

public void Exec(string commandName, EnvDTE.vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
{
     handled =
false
;
    
if
(executeOption == EnvDTE.vsCommandExecOption.vsCommandExecOptionDoDefault)
     {
         
if
(commandName == "AddInTest.Connect.AddInTest")
          {
              
try
              
{
                   
string
x = System.Web.HttpRuntime.AspInstallDirectory;
                    MessageBox.Show (x);
               }
              
catch
(SystemException ex)
               {
                    MessageBox.Show (ex.GetType().ToString()+": "+ ex.Message);
               }
               handled =
true
;
              
return
;
          }
     }
}

I started the project and clicked the „AddInTest“ button and was surprised to get the wanted result: “C:\Windows\Microsoft.Net\Framework\v1.1.4322”. Opening a solution and executing the button again is still ok.
But starting VS-Studio, first opening a solution and then executing the button raises the System.ArgumentNullExeption. Even more confusing: it depends on the opened solution. Some of them will reproduce the error. others will give me the right result. I can't get why.

M3rlin.engine needs the value of HttpRuntime.AspInstallDirectory to set the “hostingInstallDir” of the created appdomain and run the ASP.NET host. I moved the function call inside of the new appdomain (AppDomain.CurrentDomain.SetData(".hostingInstallDir", HttpRuntime.AspInstallDirectory). Now every thing runs fine.

posted on Sunday, March 28, 2004 7:41 PM by stefan@cullnet.de





Powered by Dot Net Junkies, by Telligent Systems