Some notes on software development... RSS 2.0
# Tuesday, 09 October 2012

The default MSBUILD xml produced by Visual Studio 2010 is missing <Private>True</Private> for the reference.

To fix this simply set the reference Copy Local to False, save the file, then set Copy Local to true.

The correct MSBUILD xml is now produced in the project file.

 

Links:
Stack Overflow - reference dll not copying to bin with deployment project causing error

Tuesday, 09 October 2012 13:48:46 (GMT Standard Time, UTC+00:00)  #    -
Visual Studio
# Wednesday, 06 June 2012

This post is an extension to How to Bind to Enums on JSON Objects in ASP.NET MVC 3 from www.codetunnel.com so please see that excellent post for more details.
This class basically extends the MVC default model binder to include Enum property support. This allows models with enum properties to be correctly set (bound) when JSON is sent to the controllers action method.

The class is nearly identical to codetunnel’s version, I just included the Enum.Parse statement so that it also supports enum name values being passed in.

 

So the class looks like this:

    public class DefaultModelBinderEx : DefaultModelBinder
    {
        /// <summary>
        /// Fix for the default model binder's failure to decode enum types when binding to JSON.
        /// </summary>
        protected override object GetPropertyValue(
            ControllerContext controllerContext,
            ModelBindingContext bindingContext,
            PropertyDescriptor propertyDescriptor,
            IModelBinder propertyBinder)
        {
            var propertyType = propertyDescriptor.PropertyType;

            if (propertyType.IsEnum)
            {
                var providerValue = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);

                if (providerValue != null)
                {
                    var value = providerValue.RawValue;

                    if (value != null)
                    {
                        var valueType = value.GetType();

                        if (valueType == typeof(string[]))
                        {
                            valueType = typeof(string);
                            value = ((string[])value)[0];
                        }

                        if (!valueType.IsEnum)
                        {
                            return Enum.Parse(propertyType, value.ToString());
                        }
                    }
                }
            }

            return base.GetPropertyValue(controllerContext, bindingContext, propertyDescriptor, propertyBinder);
        }
    }

..and then you just need to update the Application_Start method in the Global.asax file with this line:

ModelBinders.Binders.DefaultBinder = new U413ModelBinder();

Now your default binding will support models with Enum properties.

Wednesday, 06 June 2012 13:20:35 (GMT Standard Time, UTC+00:00)  #    -
ASP.NET MVC
# Thursday, 31 May 2012

If you are unfortunate enough to be working with VB6, VBScript, Classic ASP and COM components on a 64-bit machine you need to make sure your calling code is running the same process type as the COM component.

When you register a 32-bit COM component on a 64-bit machine it adds all the relevant bits to the HKEY_CLASSES_ROOT\Wow6432Node\CLSID node in the registry.
Here I have registered a 32-bit COM component and searched for it’s class id:

image

If the consuming client is running in a 64-bit process, when it tries to create the object it will fail because it will look in the default 64-bit area of the registry.

For my tests I have a COM component registered called HTestLibrary.

VBScript 
I have the following VBScript to create the object:

    Dim y
    Set y = CreateObject("HTestLibrary3.MyClass3")

    MsgBox y.GetTestString3()

Running the VBScript directly on 64-bit machine caused the following error:

image

By default the the script runner (cscript or wscript) is run under a 64-bit process so the COM registry lookup fails. To run the script under 32-bit process you need run the 32-bit version of cscript or wscript, this can be done by using the 32-bit version of CMD:

%WINDIR%\SysWoW64\cmd.exe

image

Classic ASP
The error you get when using Classic ASP in 64-bit mode is ‘Automation server can't create object’. To fix this you need to set the application pool for the website to run under 32-bit process so in the advanced settings for the application pool set the ‘Enable 32-Bit applications’ setting to true:

image

Links:
MSDN - COM Component Compatibility
SO - How do I run a VBScript in 32-bit mode on a 64-bit machine?

Thursday, 31 May 2012 09:25:09 (GMT Standard Time, UTC+00:00)  #    -
Classic ASP | COM | VB6
# Tuesday, 15 May 2012

After downloading the YouTube .NET client and referencing the assemblies in my test project it failed immediately with the following Could not load file or assembly Google.GData.Client….

image

Checking the warnings shows a differing version dependency for one of the newly referenced assemblies. To fix it you have to double click the warning message and Visual Studio will automatically add the correct binding redirection info to your app.config file:

image

or add the following binding configuration XML info yourself:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Google.GData.Extensions" publicKeyToken="0B4C5DF2EBF20876" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-2.0.1.0" newVersion="2.0.1.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Google.GData.Client" publicKeyToken="04A59CA9B0273830" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-2.0.1.0" newVersion="2.0.1.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Tuesday, 15 May 2012 19:52:56 (GMT Standard Time, UTC+00:00)  #    -
YouTube
Navigation

Sign In
Extras
Statistics
Total Posts: 116
This Year: 0
This Month: 0
This Week: 0
Comments: 36
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2018
Hadrian Phillips

All Content © 2018, Hadrian Phillips
DasBlog theme 'Business' created by Christoph De Baene (delarou)