Category: Misc

Tomcat stuck, no app is running, doesn’t show any log (catalina.out) messages either

This happened when I tried to restart a tomcat server.
While starting, catalina.out shows no messages related to the apps that should be loading.
Apps, as expected, don’t work either.
To get more information about what is going on, kill tomcat in a particular way:
While killing tomcat use:
kill -3 [pid]
This tells JVM to kill the process and dump the thread stack, which will show right in catalina.out.
In my case, this happened because I initialized a Spring bean which makes a request to another service, which was not running.
Service was not running, because it was being deployed on the same Tomcat server.
Deadlock occurred because my app was stuck waiting for the service app, which, probably, was down the line but never had a chance to start.

Passing property by reference (ref) in C#

In C# it is impossible to pass a property by reference.
This is due to the fact that properties are actually methods in disguise.
They behave like members (which are real objects), but are methods in nature.

Probably, this is done to enhance memory allocation issues for objects in C#.
Whatever the reason is, I faced the problem with passing those properties into the function so that the function alters them.

Initially I tried to do some workarounds using delegates (pointers to the methods).
However, they were not flexible enough to meet my needs.

Here is the final solution, which is based on the Microsoft’s “reflection” library.

public static void assignValueByRef(object obj, string propertyName, object src)
{
PropertyInfo propInfo = obj.GetType().GetProperty(propertyName);

//if “property to set” is INT
if (propInfo.GetValue(obj, null).GetType() == typeof(int))
{
if (src.GetType() == typeof(TextBox))
{
if (((TextBox)src).Text.Trim() != “”)
{
propInfo.SetValue(obj, Convert.ToInt32(((TextBox)src).Text.Trim()), null);
}
}
else if (src.GetType() == typeof(DropDownList))
{
if (((DropDownList)src).SelectedValue.ToString() != “”)
{
propInfo.SetValue(obj, Convert.ToInt32(((DropDownList)src).SelectedValue.ToString()), null);
}
}
}
}

We call the method as follows:
Utilities.assignValueX(objJF,
“PloshadObshaia”,
bridgeControl.FindControl(“FormView1”).FindControl(“dataPloshadObshaia”));

where “PloshadObshaia” is the name of the property of objJF object.

Memory allocation and overflows outlined

Program can store its data in 3 places:

– data area (contains only static variables)

– stack (contains local variables and return addresses when subroutine is called)

– heap (dynamically allocated memory, objects are allocated here due to their size)

Buffer overflow:

– Stack overflow

Limited amount of memory (usually determined when program starts)

Usually caused by 2 errors:

– infinite recursion

– very large stack variables (usually creating too large local variables, therefore arrays larger than a few KB should be allocated dynamically)

ex:

int foo() {

double x[1000000];

}

* when a single-threaded program runs as a multi-threaded, it will be allocated less space per thread. Therefore program that runs OK might crush when multi-threaded.

– Heap overflow

Memory is allocated dynamically

Primarily program DATA is contained

* on average, half of all critical security leaks are based on heap overflows (ex: iPhone, PS3 homebrews)

* more information: http://www.h-online.com/security/features/A-Heap-of-Risk-747161.html

Automating Office Applications on the Server Side

If the aim of the automation is to use a predefined template, then it is not a good idea.
Read article from microsoft:
http://support.microsoft.com/kb/257757/en-us

Hence, ASP.NET code used on the server side sometimes fails to execute due to internal “Interop” reasons.
Also, important to note that during debugging code works OK.
The problem arises only when website is published on the IIS.
Same occurs for both Vista and Windows Server 2003.

The workaround is to call EXE windows forms application from ASP.NET code and then use the file generated by EXE.

How to register COM DLL on the server

Issue:
When I was trying to run the application that used the reference, error occurred:
“System.Runtime.InteropServices.COMException (0x80040154). Retrieving the COM class factory for component xxxx failed due to the following error: 80040154”

1. The COM component needs to be registered on his laptop. Start + Run, regsvr32 c:\wavetracker\componentname.dll
DID NOT HELP, another error:
The module XXX was loaded but entry-point DllRegisterServer was not found.
Make sure that XXX is a valid DLL or OCX file and then try again.

2. http://technet.microsoft.com/en-us/sysinternals/0e18b180-9b7a-4c49-8120-c47c5a693683.aspx
download:
– Process Explorer (a GUI-based version of ListDLLs from sysinternals)
– Process Monitor (fully replaces “RegMon”(another suite from sysinternals) on windows vista )

3. Usually the root of the problem is difficult to identify.
In my case, the problem was the wrong usage of classes and functions of the library on hand.
Hence, sometimes when you use library functions/classes in the wrong way it might give this error.
So, this error NOT ALWAYS means the lack of DLL or its registration!!!