SysAdmin

Archived Posts from this Category

The Morning Brew #706

Posted by Chris Alcock on 13 Oct 2010 | Tagged as: .NET, Database, Development, Links, Morning Brew, SysAdmin

Software

Information

  • Running Open Source In A Distributed World - Phil Haack discusses distributed Open Source projects, drawing on the wisdom of Karl Fogel’s book ‘Producing Open Source Software - How to Run a Successful Free Software Project’ and discussing the processes to become a core committer on a project, illustrating with the NuPack Project
  • Adopt an Open Source Project - Rob Conery attempts to convince Microsoft (and other large .NET Dependent organisations) to allow their Developer Platform Evangelists to work part time on Open Source Projects
  • All-In-One Code Framework Coding Standards - Sasha Goldshtein highlights the All-In-One Code Framework project’s Coding Standards document - an 80+ page guide to writing code to their standards in C#, C++ and VB.NET written in ‘Framework Design Guidelines’ format (Do / Do not)
  • Caliburn.Micro Soup to Nuts Part 6b - Simple Navigation with Conductors - Rob Eisenberg continues his series of posts on using Caliburn.Micro looking at the use of Conductors for navigation between screens, illustrating with a simple sample of them in use
  • .NET Formatting Reference Sheet - Richard Carr of BlackWasp Software shares a Reference Sheet for the multitude of string format specifiers, showing each with a description and a sample of its output.
  • Dependency Injection for Filters in MVC3 - Javier G. Lozano looks at using the improvements in ASP.NET MVC 3 for Dependency Injection, and how this helps make using Dependency Injection with Filter Attributes much easier.
  • A Simple Wrapper To Make Things More Fluent - John Sonmez continues looking at using wrapping methods with logging (or other cross cutting concerns) and explores creating a fluent-like interface for adding this functionality.
  • When Intel’s Hyper Threading goes bad - Paulo Reichert discusses an instance where having a Hyper-threaded CPU may not make as much difference to your performance as you might thing, looking at what hyper-threading actually means, and how it trick the operating system into running more threads than might be optimal.
  • 7 Freely available E-Books/Guides I found essential for .NET Programmers and Architects - ‘nikosangr’ shares links to 7 really good resources for .NET Developers. I think all of these have been mentioned here before, however all are so good they deserve at least another mention.
    UPDATE: Turns out this link was to a complete copy of another bloggers article. The original (which was included in The Morning Brew previously) can be found here

Community

  • PDC UK - do you fancy a night in with the Microsoft evangelists? - Rachel Collier highlights an event with a difference to be held at Microsoft’s Reading Offices during PDC. On the evening of the 28th and 29th of October you can gather at Microsoft’s Reading HQ to join UK Evangelists to watch live streams of the PDC sessions. Registration is required
  • PDC10 at a university near you. - Phil Cross highlights a similar opportunity for UK Students at a number of Universities around the UK where you can see the Keynotes live, and participate in local Q&A

The Morning Brew #446

Posted by Chris Alcock on 02 Oct 2009 | Tagged as: .NET, Database, Development, Links, Morning Brew, SysAdmin

Software

  • ASP.NET MVC 2 Preview 2 - Phil Haack announces the release of ASP.NET MVC 2 Preview 2. New additions in this preview release include jQuery Validation support for client side validation, Areas allowing you to divide up your project more easily, model validation providers and metadata providers allowing you to support validation and metadata based on something other than the default of Data Annotations. This release is for VS2008 / .NET 3.5 Sp1 only.
  • CruiseControl.NET 1.5.0 CTP Released - CruiseControl.NET - Confluence - The Cruise Control Team announce the release of the Cruise Control 1.5 CTP. This release contains a number of bug fixes, a new range of security settings to allow you to lock down control of the build server, support for a number of new source code control tools such as Git, Mercurial, etc and a number of new tasks.publishers. Looks good, but as its a CTP not recommended for production use

Information

  • New features in ASP.NET MVC 2 Preview - ‘Shaans’ explores a number of the new features of the latest preview release of ASP.NET MVC 2, including some sneak peeks at the VS2010 beta 2 version. UPDATE: This appears to be an extract from the MVC release notes available in full here in MSWord Format
  • Code Contracts Preview: PostConditions - Dino Esposito continues his series over at DotNetSlackers looking at the Code Contracts Functionality, and in this article looks at PostConditions, looking at how they are implemented and how they work, along with comparing them to the use of asserts
  • Why does char convert implicitly to ushort but not vice versa? - Eric Lippert dives back into the past to discover why it is that you can convert from a char to a ushort but not the other way round, explaining how and why such a decision was made
  • Lazy<T>: On Demand Construction in .NET 4.0 - Bill Wagner talks about one of the less publicised features of .NET 4, the ability to make object construction an on demand process by the use of Lazy<T>
  • An Engineer’s Guide to Bandwidth (Yahoo! Developer Network Blog) - Carlos Bueno, a software engineer on the Yahoo Mail project has written a good article looking at network bandwidth with a particular slant for developers. I always feel it is important to understand the process between your code and yor users, and this article seems to fill in a number of those gaps
  • Mike Chaliy: Code-generation DSL with T4 (Text Templates) - Mike Chaliy takes a look at T4 Template generation using a DSL and T4 Templates to easily build configuration section reading code. A nice short understandable example of these sometimes confusing concepts
  • Generically Constraining F# - Part III - Matthew Podwysocki continues his series of posts on Generic Constraints in F#. This part continues on from the previous looking at the remaining constraints that exists, including Constructor, Delegate and Reference constraints.
  • Perspective camera animation on a cube in WPF 3D - Razan Paul Blog - Razan Paul has a number of posts on interesting animations created in WPF with full sample code provided. This one is the spinning cube, and others include roll down, wheel and circle animations, so be sure to take a look at them too.
  • Strive for Functional Cohesion - Chris Eargle talks about Functional Cohesion, and the important decision developers are making all the time about where to place certain functionality in your object mode.

The Morning Brew #405

Posted by Chris Alcock on 05 Aug 2009 | Tagged as: .NET, Database, Development, Links, Morning Brew, SysAdmin

This will be the last of the late editions for a while, my summer break is over and its back to work for me tomorrow so The Morning Brew should be returning to its more usual 8-8:30am (UK) publishing time.

Software

  • Spec# and Boogie Released on CodePlex - Matthew Podwysocki highlights the release of Spec# and Boogie on CodePlex under the Microsoft Research Shared Source License Agreement (MSR-SSLA) and Microsoft Public License (MS-PL) respectivly.

Information

Community

  • Microsoft PDC09 - Microsoft PDC 2009 to be held in LA is now accepting registrations, and until 15th September will be offering a $500 discount

Untrusted Network shares

Posted by Chris Alcock on 30 Oct 2007 | Tagged as: .NET, C#, Design, Development, Software, SysAdmin

One of my longest standing pet hates with desktop software developed in .NET relates to the almost inevitable security exception that will occur if you attempt to run it from a network share. Its always one of the first things I notice about software, as I often download and unzip software onto my desktop (which on my work machine is located on a network share) and then attempt to run it in place. Many large and quite impressive pieces of software that get distributed as .ZIP files rather than installers suffer this plight, and a lot of them don’t handle the exception well (One that springs to mind was the much heralded release of NDepend 2.0).

The good news is that this anguish may well be about to come to an end, as Brad Abrams requests feedback about the .NET teams possible plan to make network shares trusted. As he mentions, there really is no good reason not to trust a network share for running managed .NET code - there is no such protection for unmanaged code, and there is little or no way a normal user would be aware of which is .a NET EXE and which is unmanaged EXE.

To answer Brad’s Questions:

A) Have you ever run into this limitation (a security exception when running a .NET application from a network file share)?

I frequently experience these issues - I tend to use this problem (and if its been worked round in the application) as a yard stick as to how well written the application is.

B) How often do you use network file shares for deploying applications (managed or otherwise)?

Most of my development is web based, however for utilities written for in house use we tend to distribute them on a network share - being able to run these in place would be a great help, as updating them would be easier.

C) If you think we should make this change, when would be a good time? Is it something we should do sooner in a service pack of the .NET Framework or later in a full release of the framework. Note, we are DONE with .NET Framework 3.5, so there is zero chance it is getting in that release.

From my point of view a patch as soon as possible, and have it included in the next release of the framework - Since this is a relaxation of the current restriction, I can’t see that it would cause any more problems in terms of support of existing application, as a reduction of the support incidents caused by this issue would reduce.

D) Can you ask your local network admin what they think of this issue? Would they be in favor of this sort of change? If so, when?

This change should simplify deployment - allowing Managed EXE to run from shares should mean that local disks can be more locked down as there would be no need to copy programs locally to run them.

All in all, I’m very much in favour of this change - It will level the playing field, give a more consistent user experience, and reduce the problems people have with winforms applications.

Relocating Temporary ASP.NET Files

Posted by Chris Alcock on 15 Oct 2007 | Tagged as: .NET, ASP.NET, Development, IIS, SysAdmin

When you first request a page from the an ASP.NET application, the .NET framework takes the ASPX file and generates code to actually execute the page. This code is then compiled by the framework and the results of the compilation are stored in the Temporary ASP.NET files directory within the framework directory (usually located in c:\windows\Microsoft.NET\Framework). When the ASPX of the compiled DLL changes this code is re-generated and recompiled.
On a server that hosts lots of ASP.NET applications this store of temporary compiled code can occupy a considerable amount of space. On machines with a limited amount of space on their OS partition this can begin to cause problems. Thankfully the ASP.NET framework does allow the location of this directory to be specified as a custom location.
As with most server wide settings you need to make a change to the Machine.Config (for .NET 1.1) or Machine wide web.Config (for .NET 2). The crucial part of the configuration is the Compilation element within system.web. The compilation element has an optional attribute called tempDirectory that allows a new directory location to be specified overriding the default setting of %FrameworkInstallLocation%\Temporary ASP.NET Files.

<system.web>

   <compilation tempDirectory="d:\TempASP.NETFiles\">

      ...

   </compilation>

</system.web>

One thing to watch out for when making this change is the file permissions on your new Temporary ASP.NET files - copying the permissions from the original location will do the trick nicely.

The Evil ASP.NET Tab and other adventures with MMC

Posted by Chris Alcock on 27 Feb 2007 | Tagged as: .NET, ASP.NET, IIS, SysAdmin

Today I encountered a strange problem with IIS6 restarting without notice on a server that had recently had the .NET Framework 2.0 installed on it. In our particular case the problem was made worse by the fact that the IIS restart was unsuccessful leaving the server in a some what crippled state. We traced the problem to clicking on the ASP.NET in the IIS Management MMC, not making any changes to the settings, then clicking OK on the properties dialog.
Usually making a change to the version of ASP.NET will cause a restart of IIS (and there are alternative ways that avoid the restart), however in this case it seems as though just viewing the tab and then clicking OK was enough to cause ASP.NET to restart the IIS Service. I’ve still not discovered precisely why this is happening, but for the time being I wanted to implement a work around to avoid the problem by disabling the ASP.NET Tab.

I thought doing this would be easy, after all enough people seem to have problems with the tab not being there. Common causes of the tab being missing seem to be running the IIS MMC on x64, or having installed an earlier beta of .NET 2.0. The fixes in most cases seem to be modifications to the registry or re-running aspnet_regiis -i to re-register ASP.NET.

While it is possible that by fiddling with the registry I could break the ASP.NET tab that didn’t seem to be a good solution, so I carried on digging. It turns out that the ASP.NET Tab is implemented as an MMC Snap-in extension, and can be disabled with two clicks of the mouse once you’ve found the setting. So, to disable the ASP.NET tab within the ASP.NET management MMC:

  1. Start the MMC console (Start > Run > ‘mmc’ OK)
  2. Open the IIS management mmc (Console > Open > ‘%windir%\system32\inetsrv\iis.msc’ OK)
  3. Edit the Snapin Settings (Console > Add/Remove Snap-in)
  4. Choose the Extensions Tab, and disable the ‘ASP.NET Management Extension’ by unticking ‘Add all Extensions’ and the unticking the ‘ASP.NET Management Extension’.
  5. OK the changes and then save the console (Console > Save )

Now when you start the IIS Manager the ASP.NET tab won’t be there.

Sadly the tab is still there in the Computer Management MMC (Computer Management > Services And Applications > Internet Information Services), and looking at the computer management MMC in the same way as above does not yield the same choice of Extensions, so if anyone knows how to influence Computer Management in the same way, please let me know!

Web Service Connection Problems

Posted by Chris Alcock on 06 Feb 2007 | Tagged as: .NET, C#, Development, IIS, SysAdmin, Web Services

Setting the scene

Web Services are very simple to consume using .NET code, and its all to easy to forget what is actually going on when you add that Web Reference to your project in Visual Studio. Once you’ve entered the URL for you web service and clicked the Add Reference button, Visual Studio requests the service description WSDL file, and code generates classes to represent the data and the web service methods. I found delving into this generated code taught me quite a lot about the way XML serialization and web services actually work.

Behind the scenes the web service proxy uses classes in the System.Web.Services.Protocols namespace to actually perform the calls to the service, and these calls end up as System.Net.WebRequests containing the correctly encoded data that makes up the message.

Problems with Web Requests

Quite a lot of the problems with web services I encounter during deployment are actually problems with the System.Net.WebRequest. The most common cause of problems seems to be problems where web access is provided via some form of HTTP Proxy Server, and this typically results in an exception of the form:
[WebException: The underlying connection was closed: Unable to connect to the remote server.]

If you have access to the machine running your application its a very good idea to check if the machine can make a request to your Web Service endpoint using a web browser. This also allows you to check the settings to see if web traffic is passing through a proxy - failing this, check with the people responsible for the network.

If you find that there is a proxy involved, there are a couple of strategies available to resolve the problem.

  • Make Changes in machine.config to affect all applications
    machine.Config is one of the .NET framework’s main configuration files, and can be found in the framework directory. Settings in the defaultProxy section with that attribute usesystemdefault="false"allow system wide setting of a default proxy server overriding an OS setting:<configuration>
        <system.net>
            <defaultProxy>
                <proxy
                     usesystemdefault = "false"
                        proxyaddress="http://proxyserver:port"
                        bypassonlocal="false"
                    />
                </defaultProxy>
            </system.net>
        </configuration>
  • Configuration change for your application only
    If you don’t control the machine your application is running on then its unlikely you will be able to make changes to machine.config, but thankfully the above section will also work in your web.config or app.confg files
  • Programmatic Solution
    You can set the proxy settings in code:

    using System.Net;

    MyWebService ws= new MyWebService();
    WebProxy proxyObject = new WebProxy("http://proxyservername:port", true);
    MyWebService.Proxy = proxyObject;
    MyWebService.MyWebMethod();

All of the above methods apply to Web Service classes and also the WebRequest Classes

But what if there isn’t a proxy?

I discovered this week that the proxy problem is not the only cause of a web application which calls a web service throwing the exception:
[WebException: The underlying connection was closed: Unable to connect to the remote server.]

The next step I took in investigating this problem was to create two very simple test applications - one ASP.NET based like the code I was having problems with, and another a simple console application I could run as Administrator on the machine in question.

Test.aspx

<%@Page language="c#"%>
<%
System.Net.WebRequest r = System.Net.WebRequest.Create("http://av.com");
string resp = new System.IO.StreamReader(r.GetResponse()
                   .GetResponseStream()).ReadToEnd();
Response.Write("Response:");
Response.Write(resp);
%>

test.cs

using System;
using System.Net;
using System.IO;

public class Test
{
   public static void Main()
   {
      WebRequest r = WebRequest.Create("http://av.com");
      string resp = new StreamReader(r.GetResponse().GetResponseStream()).ReadToEnd();
      Console.WriteLine("Response:");
      Console.WriteLine(resp);
   }
}

Both of these make WebRequests to the Altavista search engine, and therefore tested requests out onto the Internet, returning the HTML from the Altavista homepage. As expected the ASP.NET based version gave the same exception as before, however the console application revealed not one, but two exceptions:

Unhandled Exception: System.TypeInitializationException: The type initializer for "System.Net.Sockets.Socket" threw an exception.

---> System.Net.Sockets.SocketException: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full
  at System.Net.Sockets.Socket.InitializeSockets()
  at System.Net.Sockets.Socket..cctor()

Which is followed by a more standard looking timeout exception

[WebException: The operation has timed-out. ]

Changing the test code to request a page from the local IIS server to no effect confirmed that it was unlikely that this was an HTTP proxy problem.

Quite a lot of searching the web, lead me towards an Microsoft Bulletin Bulletin
BUG: You receive a “The operation has timed-out” error message when you access a Web service or when you use the IPAddress class
which sounded somewhat familiar, and suggested that the problem might be caused by have more than 50 protocol bindings . Running the enum.exe utliity linked in the MS article revealed that this machine had over 100 bindings. Performing the same check on a number of other machines revealed that a more typical value was about 20, so something was not quite right with this machine. Removing some unneeded protocols from the networking setup resolved the issue, with both console application and ASP.NET test page returned the expected HTML, and most importantly the failing web service calls in the web application now works.

When APIs evolve - or how I lost my lunchtime by installing the .NET 2.0 Framework

Posted by Chris Alcock on 17 Jan 2007 | Tagged as: .NET, COM Interop, IIS, SysAdmin

In the presentation about Good API Design I talked about in yesterdays post one of the key points made was that once an API is defined you should never make changes to it that will break your client’s code. An example cited throwing exceptions based on values previously considered fine.

As luck would have it I encountered an actual example of precisely this problem today while installing the .NET 2.0 Runtime on a development server. This server runs a number of .NET 1.1 applications and a number of classic ASP applications consuming COM components written in .NET 1.1.

Things didn’t start well, with the framework installer stopping the IIS instance for the better part of 10 minutes while installing, however it did restart it again once it was done (unlike MSDTC and SQL Server when installing anything from the Windows Components section of Add Remove Programs on Windows 2003).

Matters got worse when someone mentioned that one of the components on the server was now misbehaving - specifically one that uses the ASP.NET Cache to provide caching capabilities.

Whenever a web application tried to create this object (via Server.CreateObject) it was getting an invalid pointer error. Other COM components developed in a similar way were working fine, so I assumed there was something wrong with the registration of the component. Un-registering and re-registering the component gave no joy - neither did calling it from a simple VBScript file.

To make matters worse, a simple .NET test application was working just fine using the exact same library.

After a bit of head scratching and pondering the SysInternals (Now a part of Microsoft) Process Explorer revealed that instead of using the .NET 1.1 version of System.Web both CScript and the IIS DLLHost were loading the .NET 2.0 version. The code for the component hadn’t changed, so maybe the .NET framework had.

Loading the source code for the component into Visual Studio 2005 and attempting to compile and run a the simple test application revealed the problem, a Null Reference Exception from within the framework.

As the COM Component was using the ASP.NET System.Web.Cache it was creating a HTTP Context instance internally. This code looked like this:

private System.Web.HttpContext context = new System.Web.HttpContext(null);

Poking round the disassembled code of System.Web in Reflector didn’t reveal what it was that was causing the exceptions, although I did only go a few functions deep, however it did reveal an alternative way of getting to the cache.

Changing our code to use a call to System.Web.HttpRuntime.Cache to obtain the cache instance fixed our problem, and a quick rebuild of the component against .NET 2 and redeploy to the server and we were back up and running.

Lessons learned from all this:

  • The .NET Framework installer will stop IIS and keep it stopped for a large part of the install - useful to know considering I’ll be installing it on some production servers soon
  • Both IIS and CScript seem to run all .NET COM Components through the most up to date version of the .NET framework, regardless of the version the component is registered or compiled with
  • .NET applications (like our test applet) will run in the .NET framework version they were compiled against if available

Next Page »