John Blumenauer's Blog

.NET Development and Community Nuggets
posts - 46, comments - 13, trackbacks - 0

My Links

News

Twitter












Article Categories

Archives

Post Categories

Development Tools

User Groups

Thursday, October 06, 2011

Slides and Code from NoVa Code Camp 2011 - Dependency Injection, Inversion of Control and Dependency Inversion – A Primer

During my Dependency Injection and Inversion of Container Primer presentation at the 2011 NoVa Code Camp, I had several attendees inquire about whether I could provide the slides and code. The slides and code can now be found here.  I want to give a big THANKS to all who attended.  During the presentation, there were several great discussions which indicated to me the wheels were turning already. 

If anyone has any questions about the topic, please feel free to contact me.  Thanks again!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Thursday, October 06, 2011 7:58 PM | Feedback (0) | Filed Under [ Code Camp Presentations ]

Tuesday, June 15, 2010

Is Merging Assemblies Containing Lambdas with ILMerge in VS2010 not Working? - UPDATED

A little Background

For quite some time now, it’s been possible to merge multiple .NET assemblies into a single assembly using ILMerge in Visual Studio 2008.  This is especially helpful when writing wrapper assemblies for 3rd-party libraries where it’s desirable to minimize the number of assemblies for distribution.  During the merge process, ILMerge will take a set of assemblies and merge them into a single assembly.  The resulting assembly can be either an executable or a DLL and is identified as the primary assembly.

Issue

During a recent project, I discovered using ILMerge to merge assemblies containing lambda expressions in Visual Studio 2010 is resulting in invalid primary assemblies.  The code below is not where the initial issue was identified, I will merely use it to illustrate the problem at hand.

In order to describe the issue, I created a console application and a class library for calculating a few math functions utilizing lambda expressions.  The code is available for download at the bottom of this blog entry.

MathLib.cs

using System;

namespace MathLib
{
    public static class MathHelpers
    {
        public static Func<double, double, double> Hypotenuse =

            (x, y) => Math.Sqrt(x * x + y * y);


        static readonly Func<int, int, bool> divisibleBy = (int a, int b) => a % b == 0;

        public static bool IsPrimeNumber(int x)
        {
            {

                for (int i = 2; i <= x / 2; i++)

                    if (divisibleBy(x, i))
                        return false;

                return true;

            };
        }

    }
}

Program.cs

using System;
using MathLib;

namespace ILMergeLambdasConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 19;

            if (MathHelpers.IsPrimeNumber(n))
            {
                Console.WriteLine(n + " is prime");
            }
            else
            {
                Console.WriteLine(n + " is not prime");
            }

            Console.ReadLine();
        }
    }
}

Not surprisingly, the preceding code compiles, builds and executes without error prior to running the ILMerge tool.

 

ILMerge Setup

In order to utilize ILMerge, the following changes were made to the project.

  1. The MathLib.dll assembly was built in release configuration and copied to the MathLib folder.  The following folder hierarchy was used for this example: image 
  2. The project file for ILMergeLambdasConsole project file was edited to add the ILMerge post-build configuration.  The following lines were added near the bottom of the project file: 
      <Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'">
        <Exec Command="&quot;..\..\lib\ILMerge\Ilmerge.exe&quot; /ndebug /out:@(MainAssembly) 
          &quot;@(IntermediateAssembly)&quot; @(ReferenceCopyLocalPaths->'&quot;%(FullPath)&quot;', ' ')" />
        <Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
      </Target>
    
  3. The ILMergeLambdasConsole project was modified to reference the MathLib.dll located in the MathLib folder above.
  4. ILMerge and ILMerge.exe.config was copied into the ILMerge folder shown above.  The contents of ILMerge.exe.config are:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <startup useLegacyV2RuntimeActivationPolicy="true">
        <requiredRuntime safemode="true" imageVersion="v4.0.30319" version="v4.0.30319"/>
      </startup>
    </configuration>
    

Post-ILMerge

After compiling and building, the MathLib.dll assembly will be merged into the ILMergeLambdasConsole executable.  Unfortunately, executing ILMergeLambdasConsole.exe now results in a crash.  The ILMerge documentation recommends using PEVerify.exe to validate assemblies after merging.  Executing PEVerify.exe against the ILMergeLambdasConsole.exe assembly results in the following error:

   image

Further investigation by using Reflector reveals the divisibleBy method in the MathHelpers class looks a bit questionable after the merge.

image   

Prior to using ILMerge, the same divisibleBy method appeared as the following in Reflector:

image

It’s pretty obvious something has gone awry during the merge process.  However, this is only occurring when building within the Visual Studio 2010 environment.  The same code and configuration built within Visual Studio 2008 executes fine.  I’m still investigating the issue.  If anyone has already experienced this situation and solved it, I would love to hear from you.  However, as of right now, it looks like something has gone terribly wrong when executing ILMerge against assemblies containing Lambdas in Visual Studio 2010.

RESOLUTION

After some correspondence with Mike Barnett from Microsoft, he suggested using the /targetplatform option instead of the ILMerge.exe configuration file.

Ex.

>ILMerge.exe /targetplatform:v4,c:\Windows\Microsoft.NET\Framework\v4.0.30319 /out:foo.exe Program.exe MathLib.dll

I added the /targetplatform option to my project file target section:

  <Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'">
    <Exec Command="&quot;..\..\lib\ILMerge\Ilmerge.exe&quot; /targetplatform:v4,c:\Windows\Microsoft.NET\Framework\v4.0.30319 
      /ndebug /out:@(MainAssembly) &quot;@(IntermediateAssembly)&quot; @(ReferenceCopyLocalPaths->'&quot;%(FullPath)&quot;', ' ')" />
    <Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
  </Target>

After adding this to the project file and deleting my ILMerge configuration file, everything worked fine, including the verification by PEVerify.

Updated Solution Files ILMergeLambdaExpressionUpdated

Thanks Mike!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Tuesday, June 15, 2010 12:15 AM | Feedback (1) |

Saturday, June 12, 2010

NoVa Code Camp 2010.1 Building Extensible Silverlight Apps with MEF

A big thanks to everyone who attended my “Building Extensible Silverlight Apps with MEF” session today at NoVa Code Camp 2010.1.  I always enjoy presenting sessions where the attendees already have the wheels turning about how to use concepts being presented in their applications.  It makes for a really interactive session.  The slide and code can be found HERE.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Saturday, June 12, 2010 10:28 PM | Feedback (0) |

Friday, June 11, 2010

NoVa Code Camp 2010.1 – Don’t Miss It!

Tomorrow, June 12th will be the NoVa Code Camp 2010.1 held at the Microsoft Technical Center in Reston, VA.  What’s in store?  Lots of great topics by some truly knowledgeable speakers from the mid-Atlantic region.  This event will have four talks alone on Azure, plus sessions ASP.NET MVC2, SharePoint, WP7, Silverlight, MEF, WCF and some great presentations centered around best practices and design.

The schedule can be found at:  http://novacodecamp.org/RecentCodeCamps/NovaCodeCamp201001/Schedule/tabid/202/Default.aspx

The session descriptions and speaker list is at:  http://novacodecamp.org/RecentCodeCamps/NovaCodeCamp201001/Sessions/tabid/197/Default.aspx

We’re also fortunate this year to have several excellent sponsors.  The sponsor list can be found at:  http://novacodecamp.org/RecentCodeCamps/NovaCodeCamp201001/Sponsors/tabid/198/Default.aspx.  As a result of the excellent sponsors, attendees will be enjoying nice food throughout the day and the end of day raffle will have some great surprises regarding swag!

I’ll be presenting MEF with an introduction and then how it can be used to extend Silverlight applications.  If you’re new to MEF and/or Silverlight, don’t worry.  I’ll be easing into the concepts so everyone will leave an understanding of MEF by the end of the session.

 

Don’t miss NoVa Code Camp 2010.1.  See YOU there!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Friday, June 11, 2010 8:26 AM | Feedback (0) |

Thursday, June 10, 2010

Frederick .NET User Group June 2010 Meeting

FredNUG is pleased to announce our June speaker will be Pete Brown.  Pete was one of FredNUG’s first speakers when the group started and we’re very happy to have him visiting us again to present on Silverlight!  On June 15th @ 6:30 PM, we’ll start with a Visual Studio 2010 Launch with pizza, swag and a presentation about what makes Visual Studio 2010 great.  Then, starting at 7 PM, Pete Brown will present “What’s New in Silverlight 4.”  It looks like an evening filled with newness!  

The scheduled agenda is:  

  • 6:30 PM - 7:15 PM – Visual Studio 2010 Launch Event plus Pizza/Social Networking/Announcements
  • 7:15 PM - 8:30 PM - Main Topic: What’s New in Silverlight 4 with Pete Brown 

Main Topic: 

What’s New in Silverlight 4?

Speaker Bio:

Pete Brown is a Senior Program Manager with Microsoft on the developer community team led by Scott Hanselman, as well as a former Microsoft Silverlight MVP, INETA speaker, and RIA Architect for Applied Information Sciences, where he worked for over 13 years. Pete's focus at Microsoft is the community around client application development (WPF, Silverlight, Windows Phone, Surface, Windows Forms, C++, Native Windows API and more).

From his first sprite graphics and custom character sets on the Commodore 64 to 3d modeling and design through to Silverlight, Surface, XNA, and WPF, Pete has always had a deep interest in programming, design, and user experience. His involvement in Silverlight goes back to the Silverlight 1.1 alpha application that he co-wrote and put into production in July 2007. Pete has been programming for fun since 1984, and professionally since 1992.

In his spare time, Pete enjoys programming, blogging, designing and building his own woodworking projects and raising his two children with his wife in the suburbs of Maryland. Pete's site and blog is at 10rem.net, and you can follow him on Twitter at http://twitter.com/pete_brown

Pete is a founding member of the CapArea .NET Silverlight SIG. (Visit the CapArea. NET Silverlight SIG here )

 

  •  8:30 PM - 8:45 PM – RAFFLE!

Please join us and get involved in our .NET developers community!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Thursday, June 10, 2010 8:19 AM | Feedback (0) |

Friday, May 28, 2010

Materials from Parallel Programming Pattern Presentation at Charlottesville .NET User Group Meeting

On Thursday, May 27, I had the privilege of presenting “A Look at Parallel Programming Patterns” at the Charlottesville .NET User Group’s monthly meeting.  Those folks in attendance had many great questions and were obviously very interested in what the Parallel Task Library has to offer.  The code and slides can be found HERE.  Thanks again to CHODOTNET for having me in town to speak.  If you experience any problems downloading the slides or code, please let me know.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Friday, May 28, 2010 7:35 AM | Feedback (0) |

Saturday, May 22, 2010

Richmond Code Camp 2010.1 – Developing WPF Applications using Model-View-ViewModel

The code and slides from my Developing WPF Applications using Model-View-ViewModel session at Richmond Code Camp can be found HERE. During the session, a number of the attendees had some really great questions which tells me they’re really thinking about how to start using MVVM in their own apps.  I’ll be interested to hear feedback as they start investigating and introducing MVVM in their applications.  If you experience any problems downloading the slides or code, please let me know.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Saturday, May 22, 2010 11:01 PM | Feedback (1) |

Richmond Code Camp 2010.1 – A Lap Around MEF

Thanks to all the attendees who came to my Lap Around MEF session at Richmond Code Camp today.   It seems many developers are seeking ways to make their applications more dynamic and extensible.  Hopefully, I provided them with a number of ideas on to get started with MEF and utilize it to tackle this challenge.  The slides from my session can be found HERE.  If you experience any problems downloading the slides or code, please let me know.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Saturday, May 22, 2010 10:52 PM | Feedback (0) |

Tuesday, May 11, 2010

Frederick .NET User Group May 2010 Meeting

FredNUG is pleased to announce our May speaker will be Kevin Griffin.  Kevin has been speaking at several community events this spring and we’re pleased he’s stopping by FredNUG to present at our May meeting.  On May 18th, we’ll start with pizza and social networking at 6:30 PM.  Then, starting at 7 PM, Kevin Griffin will present “Awesomize Your Windows Apps.”  

The scheduled agenda is:  

  • 6:30 PM - 7:00 PM - Pizza/Social Networking/Announcements
  • 7:00 PM - 8:30 PM - Main Topic: Awesomize Your Windows Apps with Kevin Griffin 

Main Topic Description: 

Awesomize Your Windows Apps

With the release of Windows 7, many developers might be looking to take advantage of the features Windows 7 offers. This presentation offers attendees a broad overview of the Windows API Code Pack, which is a managed library for .NET developers to use for accessing some of the underlying functionality of Windows that was typically reserved for Interop fans. Topics and demos include Windows 7 taskbar functionality, Task dialogs, Libraries support, and more.

Kevin GriffinSpeaker Bio:

Kevin Griffin is a .NET Developer for Antech Systems, located in Chesapeake, VA. He's an ASPInsider and the leader of the Hampton Roads .NET Users Group. Additionally, he serves as an INETA mentor for the state of Virginia. Often, he can be found speaking at or attending other local user group meetings or code camps. He enjoys working with new technology, and consistently works on being a better developer and building the best software he can.

Follow Kevin on Twitter: http://www.twitter.com/1kevgriff

Read Kevin's Blog: http://www.kevgriffin.com

 

  •  8:30 PM - 8:45 PM – RAFFLE!

Please join us and get involved in our .NET developers community!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Tuesday, May 11, 2010 7:17 AM | Feedback (0) |

Wednesday, April 14, 2010

Exciting New Job Announcement!

I’m extremely excited to announce that I’ve accepted a position with Applied Information Sciences (AIS).  The innovative work and company values at AIS are aligned with what I was seeking in my next position.  Also, over the past year or so, I’ve met some really talented individuals who work at AIS, so when the opportunity presented itself, I decided it was time to make a change.

I look forward to the challenges ahead and working with a team of highly talented and motivated individuals.    

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Wednesday, April 14, 2010 8:29 AM | Feedback (1) |

Powered by: