Archive for .Net

Using Visual Studio 2010 CTP with VMWare

// April 30th, 2009 // No Comments » // .Net, VMWare, Visual Studio

I recently need to run Visual Studio 2010 October 2008 CTP with VMWare since Microsoft Virtual PC can’t handle USB at all. For my company that is a big limitation since we have hardware locks that sits in the USB port. VMWare to the rescue!

Step one is to convert the Virtual PC image to an VMWare image. Luckily that’s an fairly easy process, if you are a lucky owner of VMWare Workstation. If not, there is a free converter tool to download from the VMWare site, but I have not tried that one for myself since I have VMWare Workstation here. Follow these steps to convert the image:

1. File -> Import or Export -> Next -> Next
2. Source Type = Other -> Next
3. Virtual Machine = select the VPC image -> Next -> then wait, takes a while
4. Source Data = Convert all disks and maintain size -> Next -> Next
5. Destination = Other Virtual Machine -> Next
6. Virtual Machine Name = whatever -> Location = Choose path -> Next
7. Import and convert (full clone) -> Next -> then wait, takes a while
8. Bridged network -> Next -> Next
9. Finish!
10. Wait for the conversion to complete. Mine took around 30 min.

Ok, that wasn’t too hard, eh? Most of the steps are the default values in the wizard. So, now we have a shiny new VMWare image ready to boot. And it will boot just fine. The “minor” problem is that the CTP expired Jan 1 2009. WT*? And there is no new CTP out yet, so what to do? You need to set back the date in the image and make sure that neither VMWare nor Vista override that setting with automatic synchronization of the date and time. After a LOT of googling and finugeling and trickery I finally got it right. Find the .vmx file for you VMWare image and add the following lines:

rtc.startTime = 1226188800
tools.syncTime = "FALSE"
time.synchronize.continue = false
time.synchronize.restore = false
time.synchronize.resume.disk = false
time.synchronize.resume.memory = false
time.synchronize.shrink = false
time.synchronize.tools.startup = FALSE

Make sure you don’t have duplicate entries. If you do, VMWare will whine when you try to boot. The cryptic number 1226188800 is a UNIX timestamp that equals Nov 09 2009, which is well within the expiration limits for the CTP.

Only a few more things to be aware of, then you should be all set. After you boot, go into the date and time settings in Vista and make sure that the “internet time synchronization” is turned off. Install VMWare tools (if it is not already there) and then go to it’s settings and double check that the time synchronization is turned off there too.

Phew! If you carefully followed the steps outlined here you will be able to run the CTP for ETERNITY! Why anyone would actually do that is beyond me, but hey, who am I to judge?

If this helped you in any way, please let me know in the comments. Thanks!

Solving Visual Studio’s trust issues

// April 8th, 2009 // No Comments » // .Net, Security, Troublesolving, Visual Studio

I use Subversion for all my code. I also like to keep my checked out code on a mapped network share since it has backup and is accessible from outside my main dev machine. With this setup you will sooner or later (probably sooner) run into the problem with Visual Studio not trusting the network share, and subsequently hitting you in the face and kicking you in the groin. To make our beloved studio behave more decent, I executed the following line of goodness into a Visual Studio Command Prompt:

caspol -machine -addgroup 1 -url file://h:/* FullTrust -name DevShare

This will put the mapped drive “h:” in the “Full Trust” group. Just replace the drive name (and perhaps choose another name than “DevShare”) with your specifics, and you should be good to go! Hopefully this will help someone. If not, you could check out the following post on StackOverflow.

Generating C# from an UML model with T4

// April 7th, 2009 // 1 Comment » // .Net, T4, Tools, UML

It would take quite a few blog entries to cover all that goes into the heading of this post. So I won’t do that :-). I’ll try to be short.

Code Generation with T4

Code Generation with T4

First some background though. I’m using a product called Enterprise Architect to do all my UML modeling. It is a decent product that is not too expensive. It has built in support for generating code in various languages, C# being one of them. Problem is the template language for the code generation sucks. Enter Visual Studio and T4! That would be T4 as in “Text Template Transformation Toolkit”, not the Terminator Salvation movie. Sorry to disappoint you there.

The short story is that T4 is a templating tool built right into Visual Studio! If you’re using VS 2008 you already have it installed. For more information and a great link resource, check out Scott Hanselman’s blog post about T4 (and also listen to his accompanying Hanselminutes podcast that covers the topic).

So basically I have created T4 templates that communicates with my UML model and generate all relevant classes and connections between them. Hopefully I will find the time to do a more complete writeup on these topics and also provide you with some code. Until then, all you need to know is that for me, T4 is a great tool!

Fluent NHibernate - verifying mappings with reflection

// March 9th, 2009 // No Comments » // .Net, NHibernate

I recently started to evaluate Fluent NHibernate which is a handy tool for getting rid of the NHibernate mapping XML files. I’m not going to go into more detail on either NHibernate itself or Fluent NHibernate in this post. Instead I’m going to share a nifty little piece of code I crafted to automate the process of verifying the mappings you create. Fluent NHibernate has a very useful generic class called PersistenceSpecification. You use it like this:

new PersistenceSpecification<Order>(Session).VerifyTheMappings();

By just executing the VerifyTheMappings method in your unit tests you instantly see if something is wrong with you mappings. Very nice! Now, you could add this line of code for each mapping class you have, and all would be well. But then again you might forget to add that line when creating new mappings. Wouldn’t it be nice if there was a way to make your unit test automatically find new mapping classes and test them for you? By using a little bit of reflection magic I ended up with this:

protected virtual void VerifyFluentMappingsByReflection(Assembly assembly)
{ 
    // Get all mapping types to test
    foreach (System.Type type in assembly.GetTypes())
    {
        // Make sure it is a generic type
        if (!type.BaseType.IsGenericType)
            continue;
 
        // Check if it inherits from FluentNHibernate.Mapping.ClassMap<>
        if (type.BaseType.GetGenericTypeDefinition().Equals(typeof(FluentNHibernate.Mapping.ClassMap<>)))
        {
            // Invoke VerifyTheMappings()
            Type typeGeneric = typeof(PersistenceSpecification<>);
            Type typeConcrete = typeGeneric.MakeGenericType(new Type[] { type.BaseType.GetGenericArguments()[0] });
            Object specificationObject = Activator.CreateInstance(typeConcrete, Session);
            MethodInfo verifyTheMappingsMethodInfo = typeConcrete.GetMethod("VerifyTheMappings");
            verifyTheMappingsMethodInfo.Invoke(specificationObject, null);
        }
    }
}

You can use this method in a unit test. Just add it to a class and execute it by passing in the assembly where your keep your mappings. Feel free to use the code in any way you like, and please give me a shout in the comments if you like it! :-)

SQL Server 2008 - Can’t save changes!

// March 9th, 2009 // No Comments » // .Net, SQL Server, Troublesolving

When using the SQL Server 2008 Management Studio I bumped into the following message while creating some new tables: “Saving changes are not permitted”.

Error Message

Error Message

Now, a warning that this is happening is just dandy, but totally preventing me from performing it was not what I expected. To get around the “problem” you need to disable an option. Simply select “Tools->Options”, then “Designers”, and finally uncheck the option “Prevent saving changes that require table re-creation”.

Options

Options

Ohh well, where was I now…

Neat tricks with CMD.EXE!

// August 12th, 2007 // No Comments » // .Net, Troublesolving

I recently needed to debug a service that run as the LocalSystem user. I was getting some strange errors and I suspected that user access rights was the culprit. I needed to be able to run some commands as the LocalSystem user through a shell (cmd.exe). I tried the most obvious solution, which to me was to use the “Run As…” command, but this didn’t work since the LocalSystem account can’t be used in this fashion. I found the solution in this blog post.

Be aware that the trick doesn’t work if you are connected to another computer through Remote Desktop! The CMD.EXE will be spawned at the local screen but not on your RDP connection.

TechED 2006: Day 5

// June 16th, 2006 // No Comments » // .Net, General, TechEd 2006

It’s been a long week, no doubt about it. Someone said that TechEd is a marathon and I have to agree. It’s going to take some time to process all the information that is uploaded to the brain. But, it’s been a great week!

I finally got the “basic” WCF presentation I needed and I think I have a good overview of what WinFX, sorry .NET 3.0, is all about. WCF is surely going to make all of our lifes easier. But as with everything learned here I’m going to need to try the stuff myself before I really get the grasp on the details.

Today we also booked tickets to the famous Boston “Duck Tour” and to the Premium Outlet called Wrentham Village. If we are lucky we are going to Wrentham in a limo!

TechED 2006: Day 4

// June 16th, 2006 // No Comments » // .Net, General, TechEd 2006

Thursday at TechEd 2006 was a looooong day. The sessions started early and there was the big attendee party directly after the sessions ended.

The first session in the morning was yet another great performance from Scott Hanselman called “Deploying and Managing Your Own Enterprise Framework”. As always, Scott keeps coming back to “the real world” (air quotes), which really adds an extra weight to everything he says. He’s not just *talking* about things that he never built. He (and Corillian) has actually implemented stuff and run it in production.

We also made time to see Sweden *barely* win over Paraguay. We actually screamed out loud when Ljungberg (or “lungberg” as they say over here) finally got the ball in the net (and not just hitting the net on the wrong side of the goal). It was nice to let go of over 170 minutes of frustration.

Then it was time for the big party! We got to see Fenway Park in all it’s glory. We concluded that it would have been nice to have some kind of emotional attachment to baseball and/or Fenway Park before we got there, but all in all it was a nice evening with alot of free food.

TechED 2006: Day 3

// June 16th, 2006 // No Comments » // .Net, General, TechEd 2006

Wednesday was kind of slow for me, I didn’t really attend any mind blowing sessions. I did a few hands on labs which was good. I also realized that I’m going to need to attend a “basic” session on WCF (Windows Communication Foundation), since some of the presentations today had been more rewarding if I had had more knowledge on that topic.

I also checked out some sessions on the Windows Presentation Foundation (WPF) which looks very promising. I guess it’s going to be some time before I can actually get to code any of this, but it’s good to know whats coming. I also found out that WPF will be available for Windows XP (I thought it was only coming for Vista).

TechED 2006: Day 2

// June 16th, 2006 // No Comments » // .Net, General, TechEd 2006

Today I finally got to see and hear Scott Hanselman IRL, and he didn’t disappoint me! Scott and Patric talked about their hard core “contract first” approach. They used to have the specifications in Word documents, but now they have moved this into a contract that is described in WSDL. The use these contract to generate a lot of things (among them the Word documents they need to hand out to exec’s to make them feel comfortable). This is a great approach that I’m going to look into more when I get home.