Tag Archives: C#

Using DiffMerge with Visual Studio

I won’t take credit for this, but it is necessary if you ask me. The TFS merge tool is awful. I am posting the link below for the credit.

http://statestreetgang.net/post/2008/01/Using-DiffMerge-with-Visual-Studio-and-Team-Foundation-Server-client.aspx

Go to Tools, Options, Source Control, Visual Studio Team Foundation Server, Configure User Tools, and Add.

From there it is pretty intuitive.

Important excerpt:

The above just shows the simple configuration for comparing files.  It doesn’t show how to configure DiffMerge as your merge tool.

First, the above arguments work, however the documentation says to use the following arguments when setting up DiffMerge for comparing:  /t1=%6 /t2=%7 %1 %2

To configure for merge, Add a new setting (step 3), repeat step 4, select Merge in Operation, repeat step 5, and use the following command line:  /m /r=%4 /t1=%7 /t2=%8 /t3=%6 /c=%9 %2 %3 %1


Issues integrating AXIS Web Services with .NET

I have been integrating with ITIM 5.0 using the unsupported Web Services that use AXIS 1.3. All of the issues I have experienced were fixed in 1.4, and seeing as the product is over 5 years old, I don’t understand why they chose to stick with an older version. There are several issues I have found besides the well published one about how AXIS represents arrays by pointing to a centralized value store. One of those issues is namespacing. AXIS tends to generate WSDL with a namespace, but the return values do not have a namespace, .NET just fails to find the value during deserialization. It took me forever to find out why, but I solved it by manually removing the namespace requirement from the proxy code. The second issue I ran into was how the WSDL represents collections of items. The collection is named SomeCollection with the items underneath being named Item. When the service returns, the items are named the same as the collection (SomeCollection contains SomeCollection(s)). I had to manually rename all of these references in the proxy to be the same as the collection. These cost me countless hours. If I find anymore I will post them here. Obviously the solution is to upgrade to 1.4, but IBM won’t support it or turn over the source code to do so.


A real JavaScript and CSS include method

After being displeased with the lack of a real JavaScript include method, and the complete absence of a CSS include method in ASP.NET, I started putting this into all of my BasePage classes. It uses Page Context to protect itself from double entries.

        protected void RegisterJavaScriptInclude(string path)
        {
            if (!Context.Items.Contains(path))
            {
                HtmlGenericControl js;
                js = new HtmlGenericControl();
                js.TagName = "script";
                js.Attributes.Add("type", "text/javascript");
                js.Attributes.Add("src", path);
                Page.Header.Controls.Add(js);
                Context.Items.Add(path, "JSINCLUDE");
            }
        }

        protected void RegisterCssInclude(string path)
        {
            if (!Context.Items.Contains(path))
            {
                HtmlGenericControl css;
                css = new HtmlGenericControl();
                css.TagName = "link";
                css.Attributes.Add("rel", "stylesheet");
                css.Attributes.Add("type", "text/css");
                css.Attributes.Add("href", path);
                Page.Header.Controls.Add(css);
                Context.Items.Add(path, "CSSINCLUDE");
            }
        }

Clone Wars: Object copy using reflection

Ever needed to copy the properties of one object to another where the objects did not inherit from an Interface or Abstract class? In defense of the pragmatic programmer, this situation should never happen. However, I have run into this situation twice when dealing with web services from an external Java source. You first must call a Session service to get a “ticket” back that must be included at the top of each subsequent web service request. The session object is just an xml serialized object that must be deserialized into a SessionObject. The problem is that when Visual Studio creates the proxy against the WSDL for the other services, they each encapsulate their own version of SessionObject. Even though they have the same schema, they are not the same object to .NET. This particular web service suite requires this type of object sharing a lot, so I created a helper function that would simplify the object copy using reflection. The thing I like is that you could theoretically fill a simple object based on a more complex object that contained more properties.
private object CopyObject(object objSource, object objTarget)
{
  Type typeSource = objSource.GetType();

  foreach (PropertyInfo propTarget in objTarget.GetType().GetProperties())
  {
     PropertyInfo propSource = typeSource.GetProperty(propTarget.Name);
     object valueSource = propSource.GetValue(objSource, null);

     if (propSource.PropertyType.Equals(propTarget.PropertyType))
     {
        propTarget.SetValue(objTarget, valueSource, null);
     }
     else if (valueSource == null)
     {
        propTarget.SetValue(objTarget, null, null);
     }
     else
     {
        object newTarget = Activator.CreateInstance(propTarget.PropertyType);
        newTarget = CopyObject(valueSource, newTarget);
        propTarget.SetValue(objTarget, newTarget, null);
     }
  }

  return objTarget;
}


Die, Die My Darling: a GAC alternative

The Global Assembly Cache is an excellent feature and does provide a solution to prevent DLL Hell (if you are a software company with a release strategy that is). What about the rest of us that live in the real world with aggressive timelines and budgets. We have one release called “Production”. The GAC is a decent solution for the globalization of custom framework and helper assemblies for a suite of applications, but not the right solution for most of us, especially those in the corporate sector.

The Pros: globalized assemblies, supports multiple concurrent versions, assemblies usually run with full trust, can be installed/uninstalled with a setup project.

The Cons: cannot be xcopy deployed, gacutil is unreliable, must physically be on the machine as an administrator to install, IIS applications do not automatically restart after a DLL is published, complicates the development cycle.

What are the alternatives? If the GAC was all-that-and-a-bag-o-chips you wouldn’t see forum after forum post asking for ways to get around it.

All of my applications (ranging from ASP.NET to Windows Services) reference a fairly large central framework that handles database actions, caching, encryption, etc. Trying to copy this DLL around could mean deploying it to 25 or more different bin directories (and the list will continue to grow). This would have forced me to create a fairly robust automated deployment mechanism comprised of manifests and such. Yuck. My previous solution was to use the GAC — a very hard sell to someone like me in the first place. After months of compounding small frustrations, I decided to look for alternatives. The answer is surprisingly simple, yet nearly impossible to find searching the Internet.

Information on assembly binding can be found here: http://msdn.microsoft.com/en-us/library/0ash1ksb.aspx

Basically this will redirect JIT compiler to an alternate assembly file when it attempts to compile the library. There was one trick which threw me off for a day or two getting this to work. CodeBase only accepts an HREF not a file path. You must use the URL file path syntax you might see when accessing a directory through Internet Explorer. The benefits of this method are the same as using assemblies directly in the bin folder, but you only have to deploy to a single location. You can even point to different versions for different applications if necessary.

<runtime>
<assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
<dependentAssembly>
<assemblyIdentity name=”nBaked” publicKeyToken=”2a6f8gc6611eh9s1″ culture=”neutral” />
<codeBase version=”1.0.0.0″ href=”file:///C:/nBaked/bin/nBaked.dll” />
</dependentAssembly>
</assemblyBinding>
</runtime>