Archive for category Uncategorized
Assembly of the day #2: CustomMarshalers
Posted by Scott Seely in Uncategorized on June 5, 2009
I’m on day 2 of going through assemblies in .NET 4.0. I may miss a day here and there, but I want to find out what is in all the libraries. For some of the bigger libraries, I think I’ll do a namespace breakdown over several days.
The assembly today is CustomMarshalers, and it has very few classes; 4 to be exact.
CustomMarshalers, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
FullTrust: True
In GAC: True
Number of types: 4
Number of namespaces: 1
Types:
Class System.Runtime.InteropServices.CustomMarshalers.ExpandoToDispatchExMarshaler
Class System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler
Class System.Runtime.InteropServices.CustomMarshalers.TypeToTypeInfoMarshaler
Class System.Runtime.InteropServices.CustomMarshalers.EnumerableToDispatchMarshaler
These classes all handle special scenarios for interacting with COM. Since there are only 4 classes, I’ll cover each.
ExpandoToDispatchExMarshaler
The CLR will not use this marshaler automatically. You need to know when it is needed. When P/Invoking a function or declaring a CLR wrapper for a COM object, you may have an object that only implements IDispatchEx. IDispatch was originally created for Visual Basic and allows late bound dispatch to properties. In other words, it allows for duck typing. IDispatchEx allows for an object to add and remove methods to a given object and exists to support dynamic features of Windows Script Host (languages: VBScript and JScript).In the .NET world, one adds and removes members from a type by implementing the System.Runtime.InteropServices.IExpando interface. From reading the documentation, it appears that if your underlying COM object implements IDispatchEx, you should must the infrastructure to marshal to an IExpando.
void UseCustomMarshaler([MarshalAs(UnmanagedType.CustomMarshaler,
MarshalTypeRef=typeof(ExpandoToDispatchExMarhsaler))] IExpando expando);
EnumeratorToEnumVariantMarshaler
COM allows code to enumerate a collection of VARIANT data using the IEnumVARIANT interface. A VARIANT allows one to put an integer, boolean, string, or complex object inside of a uniform binary type. In .NET, one would have a bunch of COM values that one wants to treat as System.Object. The CLR knows to use this marshaler when marshalling between a COM IEnumVARIANT and a .NET IEnumerator.
TypeToTypeInfoMarshaler
COM contains an interface named ITypeInfo. ITypeInfo is used for reading information about objects. Type browsers use ITypeInfo to figure out the characteristics and methods of objects contained in COM type libraries. A type library will be in a .tlb file or embedded in the dll/exe. Compilers use ITypeInfo to compile references to members of a type. If you export a .NET type to COM, the tools that read ITypeInfo need a way to read the information about your .NET types as ITypeInfo. Fortunately, this public type is meant to be used by the framework and not by your code. Still, it’s good to know what the class does.
EnumerableToDispatchMarshaler
This type is automatically used when bridging between an System.Collections.IEnumerable and an IDispatch where a member with a DISPID of -4 (enumerable member) is present. You will typically interact with this class when using tlbimp.exe to consume a type library from within your .NET application.
Summary
Whew-that was a lot of detail to cover. I can’t promise to do this every day, but I know that COM interop is one of my weak points. As you find issues with these descriptions, let me know. These blog entries are simply documenting my trip through the class libraries and all the reading I’m doing.
Question Follow up from Chicago Code Camp
Posted by Scott Seely in Uncategorized on June 4, 2009
One of the questions I had at the Chicago Code Camp in my Google App Engine presentation was about permissions on deleting values from table storage. In GAE, each item in the datastore has a globally unique key-absolutely unique across all entities in your application and, I believe, unique across all objects. The question was this: if I figure out an ID of your objects, can I cause a delete from a second GAE application?
Fortunately, no. At the time of this writing, I have an object (a picture) whose ID is ahJzc2VlbHktc2lsdmVybGlnaHRyDwsSCUltYWdlRmlsZRgCDA. I tried deleting that exact ID from a different application. The delete failed. So, the delete would only work if it comes from the application in question. That’s what I hoped happened, and it does.
Thanks for the great question!
Assembly of the day #1: Accessibility
Posted by Scott Seely in Uncategorized on June 4, 2009
In the spirit of DNRs “Better Know a Namespace”, I’m going to go ahead and try to understand what the 140 assemblies on my machine that appear to be part of .NET 4.0 actually do. I’ll go through these as I can, just as a way to know what exists. Here is the first one:
Accessibility, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
FullTrust: True
In GAC: True
Number of types: 10
Number of namespaces: 1
Types:
Interface Accessibility.IAccPropServices
Interface Accessibility.IAccPropServer
Enum Accessibility.AnnoScope
Value type Accessibility._RemotableHandle
Interface Accessibility.CAccPropServices
Class Accessibility.CAccPropServicesClass
Value type Accessibility.__MIDL_IWinTypes_0009
Interface Accessibility.IAccessible
Interface Accessibility.IAccessibleHandler
Interface Accessibility.IAccIdentity
This assembly provides the interfaces and struct definitions needed to interact with the Windows Accessibility system. The assembly is a managed wrapper for the COM accessibility interface. This interface helps assistive technology products work with applications. It also provides a way to access, identify, and manipulate an application’s user interface. Wikipedia has a great article on the technology.
Too cool! Hunter Hudson is the director of cloud management on Azure
Posted by Scott Seely in Uncategorized on June 3, 2009
For me, Hunter is the first deep contact I ever got into Microsoft. Way back when (1998!) I wrote a book called Windows Shell Programming. At that time, I was spending a lot of time in the Windows Shell newsgroups looking for answers as well as answering questions. At the time, Hunter was a Software Development Engineer in Test for the Windows Shell team. He quickly figured out that I was writing a book on his team’s product and did everything he could to help me understand how various features worked. Hunter is a big part of the reason that the book, my first, came out as well as it did. He actually made sure that I got decent answers from people on the shell team (Raymond Chen reviewed and answered a lot of my questions via Hunter). I didn’t realize that he is now a VIP in Azure land.
He’s a great person. I’m glad to see that he’s a big part of Azure. Way to go, Hunter!!!
System.ServiceModel.Channels
Posted by Scott Seely in Uncategorized on June 3, 2009
I was digging through the .NET 4.0 assemblies and started with a group that is near and dear to my heart: System.ServiceModel.*. I know-that’s the super cool but really hard thing to understand in .NET, at least, that’s what I seem to see all the time. Last night, I poked around in System.ServiceModel.Channels-a new assembly in .NET 4.0. This assembly contains two interesting features:
- The ability to send messages in process.
- The ability to send blobs as is.
The in process channel was frequently asked for by users back in the Indigo beta days. As a matter of fact, this was typically the first channel that the channel team would write to make sure that the latest iteration of the channel model still worked and made sense. Then, the channel was checked into the build verification tests (BVTs), but never into the product. Finally, with .NET 4.0, that class has moved to production in System.ServiceModel.Channels.LocalTransportBindingElement and System.ServiceModel.LocalBinding.
The other interesting item is the blob encoder: System.ServiceModel.Channels.BlobMessageEncodingBindingElement.
I see that, right now, the web is quiet on the documentation for these classes. I’ll be testing them out ASAP and will share what I learn soon after.
Going to Antenna—A Consequence
Posted by Scott Seely in Uncategorized on June 1, 2009
Last night, Lake County Illinois had some fierce lightning going on. When the cloud is ready to make a lightning flash, nature has its ways of determining the most effective path between the cloud that wants electrons and ground, which has an infinite supply of electrons (not really, but for the math, it works out to treat our planet as an infinite supply). That path will flow through the air to the ground for most of the Earth. That said, antennas connected to ground can offer a better choice. Last night, that choice was made with my antenna. When lightning strikes, damage happens.
My antenna is grounded, but some of the surge also went through the coax cable anyhow. I’m happy to report that all the signal goes through a small, $14.99 Maganovox 10 dB Signal Amplifier (model M61116). This unit helps make sure that I don’t lose signal strength at the point where the signal branches to 4 separate locations within the house. When the lightning struck last night, this little job sucked it up and died, protecting all my other equipment. I just purchased another 2 today-one as a replacement and one as a backup. Given that I’m spending $0/month for television access, I’m willing to incur this cost once in a while.
A question you might have is “How did Scott figure this out?” Basic troubleshooting came in handy. Trying to watch the news this morning showed no signal on any channel. Seeing that this was true on multiple TVs told me that a major part of the system was down (presented in order of effort to fix):
- No power to amplifier. Causes: circuit off because the switch was flipped or the circuit breaker was tripped. I checked the switch to the circuit and it was on. None of my breakers had tripped, so this wasn’t the cause. Had either of these been the cause, it would have been under 2 minutes from start to finish.
- Signal amplifier broken. Means I need to replace. With one on hand, it takes more time to setup, check, and replace. Should be a 20 minute job. Tools for me to check: one signal splitter, a ladder, and a helper to see if the TV shows a picture after running the test. Next time I run this test, I’ll bring up the replacement amplifier too, so I can finish the job quickly.
- Check for antenna damage: The only thing I can think of hear is maybe a case where the coax got ripped out of the antenna. The fix here is to replace the connector on the coax cable. Should take about 45 minutes to fix. Tools: wire stripper, coax connector, cable connector tool (either an electric drill or a crimping tool). Setup and cleanup are the killers on this one. Doing the work takes no time at all.
Any other problem would require research, so I hit these in terms of likelihood and ease of checking. None of the circuit breakers had tripped, so I went on to look at the amplifier. I went up to the attic and disconnected the antenna and the master bedroom from the amplifier. I joined those two over a splitter and checked out a normally strong signal (for me, this is WTMJ 4 out of Milwaukee). Since WTMJ came in, I knew where the problem was. I drove over to Menards, picked up the replacement amplifiers, and replaced the broken amplifier, reconnecting the antenna and master bedroom again. That continued to work, so I moved the remaining cables and was back in business.
Totally worth the frustration since I’m in control of when the TV comes back on, not Comcast/Time Warner, etc. And my cable is never out when some digging is going on.
Chicago Code Camp Slides and Source
Posted by Scott Seely in Uncategorized on May 30, 2009
I’ve uploaded my slides and demo code for Chicago Code Camp: Intro to Google App Engine. Enjoy!
Using Virtual Box and Ubuntu 9.04
Posted by Scott Seely in Uncategorized on May 27, 2009
Once you have Virtual Box up and running, you’ll want to install the Virtual Box Guest Additions. To do this, follow these steps:
- Start your Ubuntu VM and log in.
- Press the right CTRL key and select Devices->Install Guest Additions.
- Open up a terminal window (Applications->Accessories->Terminal)
- type in: cd /media/cdrom
- type in: sudo bash ./autorun.sh
- A new window will come up and work for a while. When it is done, it will tell you to reboot the VM. Reboot the VM when you see this message.
- Log in again when the reboot is complete.
- Press [Right Ctrl]+F. You now have full screen mode activated.
I’m posting this because the top rated instructions for Virtual Box and Ubuntu 9.04 that enable Full Screen mode have too many steps.
VirtualBox runs great on Win 7
Posted by Scott Seely in Uncategorized on May 26, 2009
Linux seems to be the OS of choice for utility computing providers. EC2 charges 3 cents/hour for Linux instances (when buying $325 or $500 hours in bulk) compared to the 12.5 cents per hour charged for the comparable Windows instance. Given the price savings, that’s incentive enough for me to try building an app on the Linux system. OK, and the fact that knowing Linux will open up a wealth of Open Source tools to me AND I’ll be able to use the Advanced Packaging Tool (aka apt) to get and install applications. If I go the Windows route, I would lose the apt path, and that’s unacceptable since the Windows installations are a bit more difficult than the Linux ones.
I’m also not willing to give up Windows 7 as my main OS, which means I need a VM to run things. My filter process to pick out a VM host is simple: if I can install Ubuntu AND have the wireless card in my Dell XPS 13 work, I’m done with the search. Here’s how the search panned out:
Windows Virtual PC
Installed but wouldn’t run on Windows 7. I couldn’t find any other VM software on my installed image, and I gave up after 20 minutes of digging around the Internet and my PC. FAIL.
Total time spent: 45 minutes.
VMWare Workstation
This seemed to be the next, obvious choice. Everything installed great, but I couldn’t figure out how to share my wireless card with the Ubuntu VM. After 20 minutes, I again called off the search and moved on to something else. Remember, I’m just trying to get Ubuntu to work on my machine and talk to the Internet over my wireless card. If I fail on everything I try, I’ll do more research, but I gave up here too.
Total time spent: 55 minutes.
Virtual Box
Installed quickly, then allowed me to get Ubuntu set up. Wireless worked immediately-no thinking required on my part.
Total time spent: 20 minutes.
So, if you are running a 64-bit Windows 7 instance (or maybe something else?) and need to run Ubuntu 9.04, I can state that downloading an Ubuntu ISO and installing using the defaults onto a Virtual Box VM just works. I’m not going to investigate any other options-I’m happy enough with how things have been working, including speed of execution.
Chicago is the biggest Tech Hub you Never Knew About
Posted by Scott Seely in Uncategorized on May 21, 2009
.and that is going to change, because it isn’t good to keep such things a secret!
You out there. Did you know that Chicago is a major technology hub. We just hide the technology in mundane things: finance, insurance, shipping, and other forms of commerce. Amazingly, a lot of this tech is profitable. Very profitable.
Trading firms are coming up with some incredible innovations in automated trading to notice when the market is moving a certain way and then take advantage of the few seconds where noticing is profitable and turn that observation into profit. Parallelization, grid computing, and more is happening in a wealth of areas. Unfortunately, broadcasting these discoveries and strategies is a losing proposition because many of these trading strategies only remain profitable while no one else has figured out the pattern. As soon as the pattern becomes common knowledge, the systems become too optimized to do anything good with the application and the developers have to find the next neat thing before their competition picks up on the fact. Due to the speed with which this cycle executes, the trading firms wind up staying quiet about the cool thing they figured out. That’s right, by the time the new algorithm or technique would be newsworthy, it’s a dead end.
Thankfully, that scene is broadening. Chicago has a lot of stellar talent that figures out all sorts of hard computer science problems. Warehousing systems and delivery companies constantly work on ways to find optimal solutions to the traveling salesman problem in p-algorithms type systems (instead of np) by finding heuristics that get good enough solutions.
Chicago is also home to Motorola’s cell phone division-a company that has brought out a number of innovative phones (though they have experienced a bit of a drought lately). Boeing is here-the company that makes air travel possible over much of the globe.
For you web geeks, talent abounds in the city. 37signals calls Chicago home. So does EveryBlock. By the way, if you use Google App Engine and Python, it’s likely you use Django which was co-authored by EveryBlock’s founder.
Crowd sourcing is at home in Chicago. crowdSPRING and threadless take crowdsourcing to a whole new level. Guess what, they are in Chicago too!
fastroot provides an awesome hosting experience. That job is made easy since the fattest Internet pipes in the US flow through Chicago. A lot of Internet research that happens between University of Wisconsin-Madison and University of Illinois Champaign-Urbana (top 10 CS schools for the longest time!). Those high speed pipes flow through Chicago. Another reason if financial. Because of the markets in Chicago, data has to flow as fast as possible. Without solid infrastructure, the financial markets couldn’t work. If you are founding an Internet business, you want to host in Chicago to minimize transmission delays to the coasts.
There are plenty more examples, but I think you are getting the idea. If you aren’t moving to Chicago for your startup (lower rent, cost of living, and cost of labor than any other tech hub), you should be asking yourself why you haven’t looked into Chicago. I think you’ll be surprised at what you find.
You must be logged in to post a comment.