Db4oTool -Excluding Class From Enhacement

230 Views Asked by At

First of all this issue only happens when I run the db4oTool against an assembly taregeting the Mono For Android profile, targeting a normal .Net class library works fine.

The issue: I am running the following command as a post build event:

Db4oTool.exe -tp -vv -debug -collections -by-attribute:DoNotDb4OEnhance -not $(TargetPath)

This results in the following error printed to the output window: (Full Log here)

Entering method 'System.Int32 Ats.Loto.Model.EnergyTagExtensions::GetNextTagNumber(System.Collections.Generic.IList1<Ats.Loto.Model.EnergyTag>,Ats.Loto.Model.EnergyType)' System.NullReferenceException: Object reference not set to an instance of an object. at Db4oTool.TA.TACollectionsStep.<TAEnabledCollectionInstantiations>b__4(Instruction candidate) at Db4oTool.Core.InstrumentationUtil.<Where>d__0.MoveNext() at Db4oTool.TA.TACollectionsStep.InstrumentCollectionInstantiation(MethodDefinition methodDefinition) at Db4oTool.TA.TACollectionsStep.Process(MethodDefinition method) at Db4oTool.TA.TAInstrumentation.ProcessMethod(MethodDefinition method) at Db4oTool.Core.AbstractAssemblyInstrumentation.ProcessMethods(IEnumerable methods) at Db4oTool.Core.AbstractAssemblyInstrumentation.ProcessTypes(IEnumerable1 types, Predicate1 filter, Action1 action) at Db4oTool.Core.AbstractAssemblyInstrumentation.ProcessAssembly() at Db4oTool.Core.AbstractAssemblyInstrumentation.Run(InstrumentationContext context) at Db4oTool.Core.InstrumentationPipeline.Run() at Db4oTool.Program.RunPipeline(ProgramOptions options) at Db4oTool.Program.Run(ProgramOptions options) at Db4oTool.Program.Main(String[] args)

If I remove the -collections attribute it will work. I try to exclude the "EnergyTagExtensions" class with the

-by-attribute:DoNotDb4OEnhance -not

switches but it either has no effect or I'm doing it wrong.

Below is the class that I think is causing the db4otool to be unhappy based on the log.

[DoNotDb4OEnhance]
public static class EnergyTagExtensions
{
    public static int GetNextTagNumber(this IList<EnergyTag> source, EnergyType activeEnergyType)
    {
        if (source.Count == 0)
            return 1;

        var concernedTags =
            source.Where(c => c.TagId != null && c.TagId.StartsWith(activeEnergyType.Prefix)).OrderBy(
                c => c.TagIndex).ToList();

        if (!concernedTags.Any())
            return 1;

        return (concernedTags.Max(c => c.TagIndex) + 1);
    }
}

Any ideas on how to get this working? Thanks in advance for any insight.

1

There are 1 best solutions below

4
On

Regarding Db4oTool not "respecting" the filter, the problem is that you need to enter the attribute's fully qualified name.

Also note that you cannot omit Attribute from the attribute name (I assume that you have followed .Net best practices and named your attribute like DoNotDb4OEnhanceAttribute)

I just filled an issue to improve Db4oTool documentation.

Regarding the NullReferenceException, I'll try to reproduce but if I fail to, can you send me, privately, a small sample assembly that reproduces it?

EDIT - Mar/01/2012

I checked Monodroid documentation and found that Func<T, TResult> is indeed defined in mscorlib (on Monodroid), so probably Db4oTool is looking up types in the wrong assembly