Lumberjack²

by Administrator 5. Februar 2017 06:54

I rewrote most of Lumberjack to get some nice benefits like:

  • Searches for additional meta data.
  • Rest services support
  • Extensible via MEF

Lumberjack is to WCF what Fiddler is to HTTP. It's a debugging tool that allows inspectiing WCF calls transparently without having to modify the environment. It uses standard WCF hooks for global message inspections.

There is additional support for WCF Rest services (e.g. inspecting/searching for headers).

In addition to all this, the application can be extended to provide custom message analysis features.

 

 

To find out more about Lumberjack², check the project site.

Tags:

C# | My Stuff | Projects | Tools | Wcf

SqlFs

by Administrator 27. Oktober 2016 13:14

I did a small test with Dokan. It emulates a file system showing the contents of Sql Server tables as csv and html files. Here's what it looks like:

Check it out here, if you're interested.

Tags:

C# | Fun Stuff | My Stuff | Projects | SQL

Lumberjack

by Administrator 21. Oktober 2015 13:55

I created a little tool that allows you to trace WCF service calls on a machine. Checkout the project page if you're interested.

Tags:

ASP.NET MVC | C# | My Stuff | Projects | Wcf

PBars

by Administrator 17. Oktober 2015 06:40

I created a little handlebars-style templating library for .NET. Check out the project page if you're interested.

Tags:

C# | My Stuff | Projects

Analyzing method usage with Mono Cecil

by Administrator 4. Februar 2012 05:37

In a current project we wanted to have a way to prevent the usage of some standard overloads in our code and perform a check in the build process. We already have some infrastructure in place to check for things like missing comments and improper dependency injection attributes, so I put some thoughts into how this can be pulled off with a minimal amount of work.

I worked with Mono Cecil in a previous project and decided to give it a shot for static analyis.

When it comes to overloads, just scanning the source code for the name of method calls is not enough and some in depth knowledge is required. Mono Cecil offers an easy way to reflect on assemblies without actually loading them. This comes very convenient since you do not have to load all your dependencies to get ready to go. Furthermore it allows even working on Silverlight aseemblies which would be very hard to use for such a test in a build environment.

I did a little class called AssemblyScanner which I will use in this article. The source is attached. I first define a dictionary of method overloads that should not be used:

protected Dictionary<string, string> deniedOverloads = new Dictionary<string, string>()
{
    {"System.String System.String::Format(System.String,System.Object[])", "string.Format without specifiying CultureInfo"},
    {"System.String System.Int32::ToString()", "int.ToString() without specifying a CultureInfo"}
};

The value in the dictionary is just some nicer display for the user. The key is the part that matters. As you see, I want to prevent the usage of string.Format without specifying a culture and the use of int.ToString without a culture. A real goody since we're not working with reflection is, that we do not have to handle assembly references. I do not care where these methods actually live, so this approach is somehow version resilient (e.g. .NET framework updates).

The next step is to iterate over all methods in the assembly to scan. This is quite easy to do:

// Iterate over all types in the given assembly.
AssemblyDefinition assembly = AssemblyFactory.GetAssembly(assemblyName);
foreach (ModuleDefinition module in assembly.Modules)
{
    // The reader is used to obtain debugging information to locate positions
    // in the source code.
    using (ISymbolReader symbolReader = new PdbFactory().CreateReader(module, assemblyName))
    {
        foreach (TypeDefinition type in module.Types)
        {
            foreach (MethodDefinition method in type.Methods)
            {

              // Analyis goes here
            }
        }
    }
}

Probably the only interesting part here is the symbol reader. I did not notice this the last time working with Cecil, but that library has support for working with PDB files (debug information). This allows to find the location of the source code for an IL instruction in the assembly. Pretty neat Cool

When analyzing a method, we iterate over it's IL instructions. IL is a little like assembly, you've got an OpCode which represents the command you're doing and optional Operands that define the arguments to use. When using the debug information you may have a SequencePoint attached to your IL instruction. The sequence point is a link to the source code (file/line/character). Since this point is not given for each instruction I just track the last one available and update it when a new one is defined.

The core is then to search for CALL operations that reference the overloads you are scanning for:

// Scan for CALL operations with an operand matching our denied
// signatures.
if (instruction.OpCode.Equals(OpCodes.Call) && deniedOverloads.ContainsKey(instruction.Operand.ToString()))
{
    // Emit a result.
}

As shown in the example this works for static methods like string.Format as well as for instance methods line int.ToString. The reason is, that both calls use the same opcode but differ in their operand. The operand has a property indicating whether a this reference (object instance) is available.

Here's the source code for the project. Feel free to play with it.

SigCheck.zip (166,51 kb)

Tags: , , ,

C# | My Stuff | Projects

nTray

by Administrator 15. Januar 2012 10:20

I did a little tool that allows hosting .NET assemblies performing background tasks, check it out here.

Tags: ,

C# | My Stuff | Projects | Tools

IE9 Document Compatibility Mode

by Administrator 11. Januar 2012 02:57

IE9 has some options for backwards compatibility that might really get in your way sometimes. I came across a problem where a style was not correctly applied because IE decided to go with IE7 compatibility. First of all you can manually switch to another mode using the developer tools (F12):

You can configure IE to not use it's heuristic approach and add settings for using a specific compatibility mode, however this probably won't be an option most of the time since your users would have to do it or you need some type of GPO. You may add a meta tag to your pages that set the compatibility:


<meta http-equiv="X-UA-Compatible" content="IE=9"/>

This looks much better from a developer's perspective since you might add it using a master page. However even nicer is embedding a snippet into web.config that sets an HTTP header with the same effect:


<system.webServer>
   <httpProtocol>
      <customHeaders>
         <clear />
          <add name="X-UA-Compatible" value="IE=9" />
      </customHeaders>
   </httpProtocol>
</system.webServer>

Here is an extract from the HTTP response headers that I captured using Fiddler:

[code]HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNetMvc-Version: 3.0
X-AspNet-Version: 4.0.30319
X-UA-Compatible: IE=9[/code]

Check out this MSDN article for more information on the subject.

Unfortunately I did not find out what makes IE think that it should switch to some compatibility mode in the first place. This is really annoying.

 

 

Tags:

ASP.NET | ASP.NET MVC | C# | Tweaks

Nancy Host Header Binding

by Administrator 10. Januar 2012 02:10

It was quite a suprise to me to find out that Nancy uses host header binding by default. I created my Nancy host like this:

var Host = new NancyHost( new Uri( "http://localhost:8080 ), ServiceEndpointBootstrapper );

This works fine when calling the app using localhost, however if you use for instance 127.0.0.1 or the machine name you will see:

HTTP Error 400. The request hostname is invalid.

Host header binding means taking the host from the request headers. Here is a snippet of the browser request for the nancy host that does not work:

GET http://MyServer:8080/ HTTP/1.1
Host: MyServer:8080

The host header is the one taken into account - it is matched against the one used to verify whether nancy should pick up the request. You see the use of host headers mostly when running multiple web sites on one ip and port, especially with web hosting companies that cannot use different ports for obvious reasons and cannot affort to have a dedicated IP for each site.

I do not know if there is a way to disable host header binding, however you can bind multiple endpoints using the NancyHost constructor. Perhaps the default is not that bad because it allows you for instance to just host an app locally which is a nice model for some applications.

Tags: , ,

C# | Nancy

Nancy Json Response Size Limits

by Administrator 12. Dezember 2011 14:43

I noticed that Response.AsJson causes errors with larger responses - first I was quite sure to have spotted a flaw, but this is intentional. There are two limits you can set for JSON objects, the total size and the recursion depth. You can set those via

Nancy.Json.JsonSettings.MaxJsonLength = <length in bytes>;
Nancy.Json.JsonSettings.MaxRecursions = <recursion depth>;

I guess the intention is similar to the limits on messages in WCF. Unfortunately there is no real reference documentation for Nancy at this point so it takes some time to dig such stuff out. I hope this will change in the future since this project is really well made and the team is great on supporting in their forums.

I'll add this to SoapWatch when I find time.

Tags: , ,

C#

SoapWatch

by Administrator 3. Dezember 2011 11:34

I added a small article about a little one day project that I used to fiddle around with Nancy and FiddlerCore.Check it out here.

Tags: , , ,

C# | My Stuff | Wcf

About the author

for comments and suggestions contact:

 

Month List