I have an application which is hosted somewhere (webhostingworld.net) and I have a dilemma. I have a tool (simple plain exe in .net 4 anycpu) that performs some offline stuff and it is started as a ‘scheduled task’ by ‘Parallel Plesk Panel 11.0.9’. Everything went fine until I added a generic method.
- basically, it’s just a dummy method that reads a json string from database and returns it;
- the process just dies, there is no exception thrown – I had to put logging from place to place and the last thing I did was putting logging before calling this method and the first thing inside it. The logging before calling this method is there, the one inside the method is not;
- the method declaration looks like this:
public T Get<T>(string id);
- I contacted them to ask for some feedback – maybe they have seen something in system logs but I doubt they will bring some light;
- on my computer works fine (don’t it always happen like this?);
- tried to compile in all cpu flavours: x86, x64, anyCPU and have the same behaviour …
I ran out of ideeas. I can always try to use the generic object (maybe this could be a better ideea from code size pov – but this is another subject) … but it’s quite frustrating because I wasn’t able to find a good reason why this is happening … So, any ideeas on what’s happening?
Thanks!
Update: The code looks like this:
public T Get<T>(string id)
{
Log.Debug("mary still has that little lamb");
string jsonString = GetASimpleStringFromDatabase(id); // id has values like "ID", "TEMPPATH", "MAIL", etc;
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)))
{
return ser.ReadObject(ms);
}
}
And the call looks like this:
Log.Debug("Let's check if Mary has that little lamb");
MyClass c = deserializer.Get<MyClass>(stuff);
The first logging statement appears (“Let’s check”), the second one (“still has”) does not. The .net framework is identical with the one on my machine (at least in what concerns the version). I am wondering if there is some flag I need to check, something …
Update: I am sorry, but the guys at the support are very slow with their responses. I have no answer on this. I will leave it without ‘templates’. 🙁
2
Answers
The user might only have the “Client” .Net 4.0 runtime installed and you might be using a feature that requires the “Full” .Net 4.0 runtime. See this for more info on the differences.
Also, you could try to hook into the unhandled exception event to log the error. See this for desktop apps, and this for web apps.
If all else fails, you could start stubbing out lower layers of your application to rule out communication or other causes. (i.e. replace the database call with a call to a mock database that returns a hard coded JSON string, etc)
Sometimes the compiler generates code that does not pass verification. If this happens, you can experience issues like this if your code does not have full trust (likely in this case). Verify that your code is verifiable by running PEVerify.