Kenny's Two Pennies

...and that's just about what it's worth
  Home |  Contact |   |  Login

Thursday, June 25, 2009

.Net COM object and app.config continued...

Well, I found that my previous post doesn't really work. I spent more time and learned the following:

  • I can't easily change the location of the app.config file. The way to do it involves setting up a new AppDomain.
  • The app.config file lives in the directory with the base executable. In the case of a COM object called from within a classic ASP page, this is the directory where w3wp.exe resides. On my computer (running 64-bit Vista), the directory is at C:\Windows\SysWOW64\inetsrv. So I created a w3wp.exe.config in that directory and voila!

That solves the problem of the config file.

My next issue was that I had to call code that wanted to get other file information from the operating directory.

By "operating directory", the code I was calling was using AppDomain.CurrentDomain.BaseDirectory

This gave me a problem, because when running under IIS, I didn't have permissions to scan a directory in c:\Windows. I couldn't even give permissions to the directory, I got an error dialog.

My solution was to change the "operating directory" to the location of the COM dll. To do this, I used the following:

Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", string.Empty)

Since I had directory scanning rights on that directory, it worked -- I can now call a COM object that in turn uses nHibernate to read data from a database.

Whew! 

posted @ Thursday, June 25, 2009 12:25 AM | Feedback (0) |

Wednesday, June 10, 2009

.Net COM object and App.config

I wrote a COM object in c# (a class library that is registered for COM interop), which compiles to a .dll.

I wanted the object to be able to read items from an app.config file (e.g. PmsInterfaceComObject.dll.config). Trouble is, COM interop dll files seem to be hosted by an Application Pool, or other type of .Net executable. Because of this, the configuration provider wants to use the host .Net executable's config file for settings. Not the COM dll's config file.

This is a known issue, this article describes the situation nicely.

I found a way to override the location of the config file at this site. I added some of my own code to discover the location of the running .dll. Here is the result:

AppConfigFilePath = Path
.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase)
.Replace("file:\\", string.Empty)
+ "\\" + Path.GetFileName(Assembly.GetExecutingAssembly().CodeBase) + ".config";

// Force the location of my App.Config file:
  AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", AppConfigFilePath);

Nice, huh?

posted @ Wednesday, June 10, 2009 10:49 PM | Feedback (0) |

Why does is have to be so hard? (Part deux)

Here is another problem/solution:

I moved my COM object (see my previous article) to my client's server. My test classic-asp page failed when trying to do a CreateObject on the COM object. No explanation. No Event Log entry. No nothing. Just a HTTP error 500. Grrr.

I got a little bit more of a clue when I created a .vbs script that did the CreateObject, and ran it using cscript.exe. I got an error message "The system cannot find the file specified". Well, my COM object opens a config file, so I went down that route, with dead ends.

I did a registry search for my COM object.method, and found entries, but no path to where the dll actually lives. I even was able to delete my COM  .dll and got the same error. Hmmm, that's a clue.

A couple of Google searches later, I found my answer. I have to register my COM object (written in c#) using regasm *and* use the /CODEBASE argument, which causes the location of the COM .dll to be noted in the registry.  DOH!!!

I did that, and now it works.

Now, had I only been told that the error was coming from the .Net run-time, and that it was not finding the COM object dll, and maybe even a hint saying that /CODEBASE may be necessary if the assembly is not in the GAC, then my life would have been soooo much easier. Instead I just wasted a coupla more hours.

Seems I am on a rampage against terse (or none at all) error messages. Come on, people (Microsoft)!!!! It's 2009! Don't make my life as a software developer so dang hard!

 

posted @ Wednesday, June 10, 2009 8:24 PM | Feedback (0) |

Saturday, May 16, 2009

Why does it have to be so hard?

I just spent a whole day trying to figure out why I was getting the infamous "ActiveX component can't create object" error. Grrrrrr.

I wrote an COM object in c#. I followed all of the rules. I was able to late-bind to it and use it in vb6. It is a really simple COM object with just one method that returns the string "yep". I plan on getting more fancy with it later.

I figured since VB6 worked, I could access it from a classic ASP page.  Wrong.

Well, first, I have a 64-bit laptop running Vista. No, I'm not going to bash Vista. I actually don't mind it at all. Except the 64-bit part -- seems I'm always having to make adjustments because of something I happen to be doing in 32-bit mode. The fact is, the majority of code out there is still 32-bit.

Here is how my easter-egg hunt went:

  1. Write the COM object. That was a piece of cake.
  2. Write a a classic ASP page to call the COM object. Another piece of cake.
  3. Run the ASP page. Oops. Can't do that within Visual Studio 2008. Cassini doesn't do classic ASP
  4. Found out that Vista Home Premium has IIS, but you have to install it. Well, ok. done.
  5. Why does Microsoft have to keep rearranging the furniture. The IIS 7 UI is way different that IIS 6.
  6. Finally got to run my asp page. Got the ActiveX component can't create object error.
  7. Why Microsoft can't give more details than that completely amazes me. Found numerous google results of people with this problem, and responses of "try this", "try that". Well, I would know EXACTLY what to try if I know specifically what the dang problem is.
  8. Is my COM object ok? Wrote a VB6 app to instantiate and use it. No problem.
  9. Is it an IIS problem? Wrote a .vbs script, it also gets the error. Interesting.
  10. Went thru many detours. Including downloading and installing Microsoft's Debugging Tools For Windows. That looks interesting, if I only knew how to use it.
  11. Found this link. Interesting! The cscript utility has a syswow64 compatibility version. That worked! Am I on to something?
  12. Went into IIS, DefaultAppPool, changed advanced-option "Enable 32-bit applications" to true. Still no go. Actually it turns out that this is a necessary step, but not the only one. Again, WHY couldn't the error message say that the problem had to do with running the app in 64-bit mode? Huh? Huh? And WHY was it defaulted to false? When most apps are still 32-bit?
  13. Went back into IIS, DefaultAppPool, changed "Identity" from NetworkService to LocalSystem. WOOHOO! it worked. It was a permissions problem. Nice to know. Couldn't Microsoft tell me that in the first place?

Bottom line: Persistence pays off, but at the expense of hair loss.

And: Informative error messages would be nice. Not these terse, cryptic, useless ones like "ActiveX component can't create object". Come-on -- can't the largest operating system company in the world do better than that?

posted @ Saturday, May 16, 2009 2:34 PM | Feedback (0) |

Saturday, July 05, 2008

My first Silverlight App

Here is my first published Silverlight App: http://sudoku.kenhales.com.  It solves Sudoku puzzles. It isn't a finished product by a long shot.  Here is my take on Silverlight so far:

  • It is better than ASP.NET by quite a ways, but there is going to a learning curve I still need to get past.
  • I think I will be doing a lot more line-of-business work in Silverlight, including an inventory module for my company's Field Service system (at http://poolcarepro.com).
  • I hope it becomes a popular dev and execution environment -- I do not want to end up with legacy code that is out of the mainstream -- like Delphi or PowerBuilder.
  • I love c#, and definitely relish the idea of providing a rich user experience over a browser, but without having to use JavaScript.

My plans for this Sudoku solver program include:

  • Provide a better way of entering values.  I am thinking some kind of specialized combo box.  One that has an animation to expand a pop-up to show a 3x3 grid of the numbers 1-9, plus a 'clear' button.
  • Ability to save and load existing puzzles.
  • Experiement with Expression Blend (I simply did bare-bones XAML on this so far) to give it more pizzaz.

If anyone has any comments or suggestions, I'm all ears.

posted @ Saturday, July 05, 2008 9:45 AM | Feedback (0) |

Saturday, September 29, 2007

Regex problem / solution

My brother gave me a list of zip codes and their cities.  I needed this list to construct a query that gives revenue information by city, given a couple of tables -- one with account numbers and their zip code, and another with account numbers and revenue.

The revenue information query was easy.  The harder part was getting the danged list of zip codes / city pairs into a table.

Here is what I had to work with:

91605 Los Angeles
91606 Los Angeles
91607 Los Angeles
91630 Thousand Oaks
93115 Fillmore
93552 Palmdale
(etc)

There were only about 60 lines of this stuff, and I figured the easy way would be paste the list into SQL Server's Management Studio query window, do a search and replace to convert the list into a bunch of INSERT statments, and then execute, to actually insert the pairs into a table I already had in place.

Piece o' cake, huh?

I thought I had regular expressions down.  Turns out I pretty much did, but it was the replace string that kicked my butt.  Here was my matching string:

^{[0-9]+}:b+{.*}

It basically says, from the start of a line, match up a string of 1 or more digits and "tag" them for replacement.  Then expect 1 or more spaces or tabs, and then a string of character up to the end of the line.  Tag the string of characters as well.

And here is the replacement string:

insert into zipcities(zipcode, city) values('\1', '\2')

This creates a list of my "insert" commands.  the \1 substitutes the first "tagged" data (the 1 or more digits), and the \2 does the same with the city names.

Here is the result:

insert into zipcities(zipcode, city) values('91606', 'Los Angeles')
insert into zipcities(zipcode, city) values('91605', 'Los Angeles')
insert into zipcities(zipcode, city) values('91607', 'Los Angeles')
insert into zipcities(zipcode, city) values('91630', 'Thousand Oaks')
insert into zipcities(zipcode, city) values('93115', 'Fillmore')
insert into zipcities(zipcode, city) values('93552', 'Palmdale')

Nifty, huh?

The part that kicked my butt?  I naturally assumed that the replacement string followed regular expression rules (the parentheses needed to be escaped with a leading '\' character).  Turns out the replacement string does  not use any regular expression syntax at all.  It just uses the \1, \2, etc. for repacements.  I think this replacement syntax is not universal -- Management Studio does it this way but other engines may use another replacement syntax.  I'm not sure about that though.

There, I have documented this for future reference!

posted @ Saturday, September 29, 2007 9:42 AM | Feedback (0) |

Quote of the day...

So you've got a problem, and you want to use Regular Expressions to solve it. Now you've got two problems.

posted @ Saturday, September 29, 2007 9:02 AM | Feedback (0) |

Monday, September 24, 2007

Forever Seeking Software Architecture Nirvana

I consider myself a pretty experienced software developer -- I have been at it for over 30 years.

All along the way, I have found myself encountering new products and tools, and new ways of organizing code.  One of the (neat) aspects of software development is that there is always something new to learn.

And so now I find myself again immersing myself into new concepts that I had not been familiar with before.  Funny thing is, some of these concepts are not new.  They have been around since I first started programming.  Oh how I wish I had paid more attention to the PARC people!

My latest topics are these:

Throw in some data access stuff (LINQ and NHibernate), and I have a lot to think about.  I'll post some of my thinking on all this later.

btw I'm listening to Tom Harrell's new album "Light On".  Over and over.

posted @ Monday, September 24, 2007 5:33 PM | Feedback (1) |

Sunday, July 15, 2007

A whole new level...

After upgrading from the old .Text blog engine to its replacement SubText, I contacted Kent Chen to see if he planned on upgrading his .Text skin files.  He was unaware of SubText as well, and after switching to it, he sent me the upgraded skin.  Thanks Kent!

SmartCarOnSteroids

On Kent's blog he mentioned Live Writer, which I hadn't heard of before.  I downloaded and installed it, and, wow!  Now creating posts is a lot easier.

Plus, now I can insert pictures.  And wrap text to the side of it.  No, the car isn't mine.  I don't even wish it was.  I just found the picture to be screaming for a snide remark.  Like, who says you can't have fun while saving the planet by driving a Smart Car?

posted @ Sunday, July 15, 2007 9:20 AM | Feedback (0) |

Saturday, July 07, 2007

Finally back...

It has been a crazy several months.

This site was put on hold, for several reasons.  One of the main ones is described in my previous post.  I finally found out that the blog engine I use (DotText), which I thought was becoming obsolete, is in fact alive and well under a new name (SubText).  Woohoo!  I have upgraded, and was able to migrate my old posts with (almost) no problem.  I am hoping that as a result, I will not be getting spam comments.

Another reason is also descibed on a previous post -- the World of Warcraft MMO game.  I cannot belive how much time I put into that game.  It has been very fun, but I am finally just recently getting out of addiction mode.  Shiblon is at level 70, which is as high as you can go.  I have several other "toons", but I am slowing down a lot.  I have actually gone for a day or two at a time without even logging on at all!

I still am wanting to do more technical (software development) posts.  I am wondering if I should create a separate blog for them.  Actually I am thinking I could use four blogs -- Family, Software, Music, and Politics.  But that seems like too much.  Not sure yet.

Anyway, I am back, and plan on posting more often.

posted @ Saturday, July 07, 2007 10:37 PM | Feedback (0) |