SmartAssembly

Latest version: 6.7

SmartAssembly

Knowledge Base

Using Smartassembly to obfuscate a windows service

Category: Troubleshooting & error messages
Date: 10 Dec 2010
Product: SmartAssembly
Obfuscation a windows service that is installed using InstallUtil.exe from the Net framework leads to many errors, especially System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types

There is a known issue with the installation of a Windows service if you embed one or more dependencies.

In this case, you need to manually install the windows service and not rely on "InstallUtil.exe" (because it will not be able to load the dependencies).

There is a basic sample on how to register a Windows Service without using InstallUtil.exe here:
http://www.codeproject.com/KB/dotnet/WinSvcSelfInstaller.aspx



Also, any exception occurring during the OnStart() and OnStop() events will not be reported by {smartassembly} exception reporting feature.
This is a limitation due to the fact that the CLR already catch the exceptions in these events and report them in the logs:

private unsafe void ServiceQueuedMainCallback(object state) {
    try
    {
        this.OnStart(strArray);
        this.WriteEventLogEntry(Res.GetString("StartSuccessful"));
    }
    catch (Exception exception1)
    {
        this.WriteEventLogEntry(Res.GetString("StartFailed", new object[] { exception.ToString() }), 1);
    }
}

So, you need to check into window's eventlog to get more information on the exception.

Excepting the above, {smartassembly} doesn't have any specific issue with windows service but, as always if you use Reflection in your assembly, you need to exclude for the obfuscation (and pruning) the members called by Reflection in {smartassembly} project or by using custom attributes:
http://www.smartassembly.com/download/HowToUseCustomAttributes.pdf

Document ID: KB201012000473 Keywords: smartassembly,windows,service

Was this article helpful?

Search support
Forums
Visit the SmartAssembly forum.

SmartAssembly

all products