Error 1001: Service has been marked for deletion

Another of those stupid windows errors!

I was working on this windows service recently. While developing this I code the changes, build the app and run the service installer. (The service installer project is quite cool. I admit). But every now and then when I uninstall the service and try to reinstall it I get this error:

Error 1001: Service has been marked for deletion

I know its marked for deletion. But why is it not deleted yet? I used to restart the system as a solution to this problem. But soon enough I began to see the stupidity behind some of the windows apps. I had the Service Control Manager running to start/stop the service. After uninstalling the service if you happen to open the SCM window, it gets a lock on the service entity and marks it as ‘Disabled’. Now when you try to install the service again Error 1001 pops up.

The solution to this was to just close the SCM and install the service. SCM is one of the core windows utilities. You expect it to behave right?

System.Xml.XmlSerialization – Assembly bind failure (MDA Error)

When Im debugging my application I ask Visual Studio to throw all exceptions in my code. (I do this by checking everything in Debug > Exceptions) It seems like a good thing to have while debugging applications – to know the exceptions you’re getting even if you’re catching them and handling them. This setting in combination with the use of System.Xml.Serializers seems to constantly throw this error in my application:

System.Xml.Serialization assembly binding failure

This gets annoying after a while as my code seems to be perfectly alright, no errors, but this window keeps popping up at this line:

XmlSerializer xmlSerializer = new XmlSerializer(type);

I looked at the error in detail and it seems to be looking for an assembly named My.Namespace.XmlSerializers. Of course there’s no such assembly and the compiler will get a System.IO.FileNotFoundException. The best solution I could Google out was to uncheck the BindingFailure and prevent the exception from showing up every time.

This worked only in stopping me from getting annoyed, whenever that error showed up, but I knew there still was some error and it was being handled somewhere! I had to figure out what was going on…

Enter Reflector (Now a RedGate product. An addition a cool line up of .NET tools)

I have a trial version of Reflector on my machine and this is an excellent opportunity to figure out what in the world is happening in System.Xml.Serialization. I disassembled the entire System.Xml assembly and searched for the keywork ‘XmlSerializers’.

Looks like there is code to generate a custom assembly to handle type passed to the current serializer. Every call to this creates this assembly in a temp location and runs the deserialization through this assembly. There seems to be multiple options for the ‘temp location’ to generate this assembly. Once the assembly is generated, it is delay loaded at runtime. During this the assembly loader searches for all the possible temp locations and each time it fails to find the assembly in one of the temp locations, it throws a FileNotFoundException. This exception is rethrown as a bind failure.

So… I don’t know why the serialization/deserialization logic needs to be this complicated. But, in case of the core .NET library, it just is. I also have noticed that the memory footprint of System.Xml.Serialization classes to be quite big. This whole process of creating a temp assembly probably adds to it. I know there are better solutions for XML deserialization out there. I will soon get onto searching for one and evaluating it against System.Xml.Serialization methods. I’ll add an update to this post when I do find one (eventually…)

In conclusion, System.Xml.Serialization classes and methods are an expensive way to serialize objects to XML or to deserialize XML to objects. This throws a BindingFailure exception as the library internally uses a try catch to handle delay loading a temp assembly. Though this code is internal to the assembly, this error shows up if we enable throwing all exceptions as the delay load is happening in the context of our application.

So, the best solution to avoid (seeing) this error is what’s been suggested by many – in Visual Studio uncheck BindingFailure in Debug > Exceptions under ManagedDebuggingAssistants

Problem starting Apache/IIS on Windows 7 Port:80

Recently I had severe problems running Apache on Windows 7. There are several reasons why this can happen. I have identified 5. The problem and the solution(s) are presented in this blog post.

You might come across this problem if you’re having trouble starting Apache or IIS. The first thing you should do is to go check your error logs. First thing to do is to go to your system event log. Do Start>[Type “event viewer”]>[Enter]. Select ‘System’ from the left side and check for any logs.

With Apache I was getting a service-related error code: -1

Now I checked the apache error log (C:\xampp\Apache\logs\error.log) and saw that it was ‘not able to bind to port 80’. This means that some other process was using port 80. So, I googled for a command to check the process that’s using port 80. The command was:

netstat -ano

Now if your process id (last column) that’s using port 80 [::]:80 or is not 4 (PID), then your solution could be simple:

Solution 1

If your PID is not 4 after the above step, go to Task Manager>Performance>Resource Monitor. Here find the process that was using port 80 and kill it. 🙂

Solution 2

If the process that stole your port 80 was Skype, use this link:

Solution 3

If PID 4 (The NT kernel process ‘System’) was hogging port 80. Go to your Service Control Manager (Type in ‘Services’ in Start Menu), Find the service named ‘RemoteDesktopManager’ and disable it.

Solution 4

Again if it was PID 4, there could be a problem with the infamous http.sys. To solve this problem, use this link:

Solution 5 (This was my problem actually)

If you are running SQL Server Reporting Services, you’d be surprised to know that it steals your port 80. If you have SQL Server (05/08) installed on your system, goto Start > Microsoft Sql Server 20xx > Configuration > Sql Server Configuration Manager. Find the Reporting services and stop it. Also make it ‘Manual’ to be safe.

And Viola! My apache service is running. If it was IIS in your case, you’d have that running too 🙂

If this didn’t help you, comment. If this did help you, comment.