Wiki

Clone wiki

CodeCop / FAQs

What prerequisites CodeCop needs to run?

Having at least .NET 4.0 on your machine. Internet connection for the first time it runs on a new machine in order to build its symbol cache.

Can I intercept a method that was inherited from a parent class?

By default you can only intercept methods that are actually declared on a type. When you want to intercept a method that was inherited and it is not overriden in the child class, you have ALWAYS to intercept the method on the parent type.

#!json

{
    "Types": [
        {
            "TypeName": "ConsoleApplication1.ParentClass, ConsoleApplication2",
            "Methods": [
                {
                    "MethodSignature": "ParentMethod()",
                    "Interceptors": [ "WriteMethodNameToConsoleInterceptor"]
                }

            ]

        }

    ],
    "GlobalInterceptors": []

}

How can I intercept a specific method overload?

Simply by specifying on the JSON configuration file the method signature, e.g. imagine a method overload that takes an instance of a type called MyClass and a string as its parameters. Here's how you would intercept it:

#!json
{
    "Types": [
        {
            "TypeName": "ConsoleApplication2.AbstractImplementer, ConsoleApplication2",
            "Methods": [
                {
                    "MethodSignature": "MyMethod(MyNamespace.MyClass, System.String)",
                    "Interceptors": [ "LogInterceptor"]
                }

            ]

        }

    ],
    "GlobalInterceptors": []

}

How about generic methods? How to deal with overloads?

Exactly the same way above. By specifying the method signature. Imagine 2 generic method overloads with a single generic argument T, the first one with no parameters and the second one with a T parameter. This is how you would intercept them:

#!json
{
    "Types": [
        {
            "TypeName": "ConsoleApplication2.MyClass, ConsoleApplication2",
            "Methods": [
                {
                    "MethodSignature": "MyGenericMethod[T]()",
                    "Interceptors": [ "LogInterceptor"]
                },
                {
                    "MethodSignature": "MyGenericMethod[T](T)",
                    "Interceptors": [ "LogInterceptor"]
                }

            ]

        }

    ],
    "GlobalInterceptors": []

}

Should I use the online JSON generator tool to create my copconfig.json file?

You're not obligated to do that, you can generate the JSON manually although doing so becomes more error prone, specially concerning those overload cases mentioned above as well as more complex types.

Can I intercept methods on 3rd-party .NET libraries?

Yes as long as the assembly is not NGen'ed. CodeCop manipulates IL bytecodes in memory, NGen'ed assemblies have been pre-compiled to processor-specific machine code, thus have no IL to manipulate.

How about if the assembly is a strong named assembly?

No problem at all. If you are intercepting a 3rd party signed assembly, just make sure the application that is calling that assembly is also signed.

What methods can be intercepted?

Literally Any (public, private, abstract, virtual, static, generic, async, with out, ref parameters, etc).

Can constructors be intercepted?

Yes all constructor types are supported.

Can properties be intercepted?

Yes. We just treat those as methods because that's what internally they really are. To intercept a property, just add "get_" or "set_" to the property name or signature. If you have a property called Age you could intercept its getter and setter like this:

#!json
{
    "Types": [
        {
            "TypeName": "ConsoleApplication1.MyClass, ConsoleApplication2",
            "Methods": [
                {
                    "MethodSignature": "get_Age()",
                    "Interceptors": [ "LogInterceptor"]
                },
                {
                    "MethodSignature": "set_Age()",
                    "Interceptors": [ "LogInterceptor"]
                }

            ]

        }

    ],
    "GlobalInterceptors": []

}

My app seems to have more startup overhead when bootstrapping for the very first time on a new machine, why?

CodeCop on the first time it runs on a new machine builds a symbol cache for it, so it needs to download some symbols from Microsoft public symbol servers which can take some time specially if your machine is not under a broadband connection. Once the cache is built for that machine the app will run full speed.

How do I deploy CodeCop with my app?

Just follow the deploy page instructions.

Is debugging supported inside Visual Studio once interception occurs?

Yes, full debug support.

The Free version has any limitation in terms of functional features?

No, although it is only limited to intercepting 25 methods. You can compare all products and features here.

I have acquired a license but CodeCop still runs in Free mode, why?

You have probably missed pasting your license key into your copconfig.json file .Or if you are using the Fluent API make sure you pass it as an argument to the AsFluent method of the Cop class. Please make sure you followed the Licensing instructions.

Updated