Friday, March 2, 2012

Debugging my .NET assembly after New-Object

Don't judge me.  I have to work with Access Databases, this forces me to to built 32bit assemblies.  To automate my applications I have to use 32bit PowerShell.  I also for some arbitrary reason do most of my work .NET 4.0.

So I go to: C:\Windows\syswow64\Windowspowershell\v1.0\
I created a new "powershell.exe.config" containing:


<?xml version="1.0"?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
          <supportedRuntime version="v4.0.30319" />
    </startup>
</configuration> 
The same can be done to create a "powershell_ise.exe.config"

Then fired up my 32bit .NET 4.0 powershell.
Changed directory to my build folder.  And called an Add-Type.
Of note: if you do this, and need to rebuild the app, you will need to close powershell and reopen.  The Add-Type loads the assembly, so it is locked from being written by the compiler.
In Visual  Studio, I loaded my solution, went to Debug/Attach to process, and found the 32bit Powershell instance.  I was concerned that I wouldn't be able to tell it apart from my 64bit Powershell instance, so I have processExlorer up and used the handy "Find Window's Process (drag over window)".  When I found the process Visual Studio did identify it as 32-bit.

I set a break point in my class constructor, did a New-Object, and that pretty yellow step threw highlight showed up in Visual Studio.

- Josh

No comments:

Post a Comment