Fun with Powershell, Part 2 – Investigating code Issues Tuesday, 02/21/2012
Posted by Percy in Fun with Powershell, Programming, Technology.Tags: Development, PowerShell, Programming
add a comment
Since I missed posting something last week, I’m putting out two this week to keep up with my resolution. This is the second post in a series of posts about the fun I’m having with Powershell.
Part of me putting this series of posts out there is to help people look at Powershell in a different light – as a developer tool. I think it gets labeled as a SysAdmin tool, which it definitely is. However, I’m finding more and more that when I turn to Powershell to help me, I end up getting the info I need quicker and easier and I write less code. This is another one of those issues.
So, I picked up an unfinished project for a client recently. The project is in the process of being QAed, but there were issues that had been found along the way. The original developer had since left the company, so it was up to me to figure it all out. One of these issues had to do with the rendering of a DataDynamics Active Report. The error that was being thrown had to do with displaying a logo. Basically, it was instantiating a Bitmap object using a stream from an embedded resource, but the stream was returning as null.
new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("{SupposedlyValidReference}"));
So, I started thinking about how I could look into what was causing this issue. I could set up the web application where this issue was being thrown and go straight to debugging. However, in this case, that was a bit more complicated than it sounded. Also, the issue was in a compiled assembly that wasn’t specifically part of the website. I could write a harness to call this report and debug that way. I actually already have something like this written and shared with some co-workers, but even that was a bit more complicated then I wanted. Too, I didn’t need to test the entire report, just this one line. I could write a console app, and pull this code out to see what’s going on. Yea, I could do that somewhat quickly, but not as quickly as I could write some Powershell scripts to see what’s going on. So, that’s what I did.
Here’s the script I whipped up somewhat quickly:
cls
$assemblyPath = "{PathToAssembly}"
$assembly = [System.Reflection.Assembly]::LoadFile($assemblyPath)
$stream = $assembly.GetManifestResourceStream("{ValidPath}")
$stream | Get-Member
Since that was basically the part of the code that was throwing the error. Running that script threw the following error: “Get-Member : No object has been specified to the get-member cmdlet.” That tells me the same thing the error message from the app tells me – my stream object is null. So, I started looking at the path to the resource, and the actual file name. It turns out the file was named ####_Logo.gif, while the resource referenced ####_logo.gif. So, just to see if that was the issue, I changed my script to have the capital L in the resource path. Running that script gave me a valid System.IO.UnmanagedMemoryStream object for $stream.
That’s it. It was just a letter casing issue. However, instead of firing up a new instance of Visual Studio, creating a new console app, adding a reference to this assembly, writing the code and stepping through it, all I had to do was write a simple 5 line script. Really, it could have been 2 lines (Load the assembly, and get the stream).
If you missed out on Part 1, here it is.
Vacation God Moments, Part 2 – God’s Love For Us Wednesday, 02/15/2012
Posted by Percy in Personal, Vacation God Moments.1 comment so far
This is part 2 of some of the lessons that God started teaching me on a vacation a few months ago. Part 1 is here if you’re interested.
As I travel farther into this journey called fatherhood, I’m beginning to see God in a different way. I’m sure every Christian father goes through something similar. As we were driving along the Blue Ridge Parkway that afternoon, Sarah and I got to talking about our child. I had this overwhelming sense of love for this child (it wasn’t the first time) and it hit me that I’ve not even met this child yet. At the time, he or she didn’t even have a name. We didn’t know the gender. How could I love this child so much before I even meet him or her?
I thought about the progression of the relationship Sarah and I had. While she’ll be the first to tell you that I was quick on the “I love you” front, it wasn’t immediate. It definitely didn’t happen before we met. Now, you can go all metaphysical on me and say that God had prepared us for each other, and that our love existed before we knew it, and I would agree. However, from my perspective, it didn’t. We had to meet. We had to spend a considerable amount of time together. We had to engage each other in conversation and activities where we got to know each other. We had to come to a point where we thought we were mutually compatible. Only after doing all that did we get to the “love” point.
That’s not now it is with this child, and that’s not how it is with God and us. I already love this little guy or gal more than I thought I ever could. The most time we’ve spent together is just random kicks, punches or other movements that I can feel. I’ve only seen this child a few times, and those were grainy ultrasound pictures. By all appearances, I don’t know this child. That’s just it, though. I do. I don’t know how, but I do.
That’s the way God sees us. He knows us better than we know ourselves sometimes, yet He loves us anyways. What gets me is that He loved me before I was even born. Honestly, He loved me before my parents were born. How crazy is that? Again, I think Carisa captures the awe in that idea in her song “My King“:
Holy Father, you knew my name. Called me as Your own before the stars were placed.
Wow, “before the stars were placed” God knew who I was and He loved me even then. Before this child even sees the light of day, before he or she even had fully developed eyes, this child was loved.


