Feed Subscribe
Exception has been thrown by the target of an invocation.


How to specify UIHint template only for specific mode in ASP.NET Dynamic Data

by ondrejsv 8. October 2009 16:58

If you want to display a data field in your custom template instead of the default one coming with ASP.NET Dynamic Data, you can by decorating your metadata with the UIHint attribute:

[UIHint("Attributes")] public EntityCollection<Attribute> Attributes

In this case, Attributes collection will be displayed using Attributes.ascx template. Dynamic Date is clever enough to use Attributes_Edit.ascx if you happen to edit the collection. If Attributes_Edit.ascx does not exist, Dynamic Date will use the default template.

However, if you have a template that you want to use only for editing (or inserting) and use the default template otherwise (for read only), you cannot. If you supply the UIHint, you are required to have also a read-only template – in our case, you must have Attributes_Edit.ascx together with Attributes.ascx. You end up copying the content of the default template and renaming it (to Attributes.ascx and so on). As we know that copy-paste is a bad programmer’s friend which promotes low code maintainability and readability, we must come up with another solution.

Dynamic Data delegates deciding which template to use for which field to an instance of the FieldTemplateFactory class. In particular, we are interested in its GetFieldTemplateVirtualPath method which eats a column to get the template for, mode (ReadOnly, Edit, Insert) and UIHint value. We can, of course, extend the default factory to process UIHints in the form realUIHint|mode (e.g. “Attributes|Edit” which means use the Attributes_Edit.ascx for editing but the default template for anything else). The actual code is simple:

public class MyFieldTemplateFactory : FieldTemplateFactory { private const char HintSeparator = '|'; public override string GetFieldTemplateVirtualPath(MetaColumn column, System.Web.UI.WebControls.DataBoundControlMode mode, string uiHint) { if (!string.IsNullOrEmpty(uiHint) && uiHint.IndexOf(HintSeparator) > 0) { string[] sArr = uiHint.Split(HintSeparator); string hint = sArr[0]; string forMode = sArr[1]; // If current mode is the one specified in the UiHint // use it, otherwise fall back to the base implemenation. if (mode.ToString() == forMode) uiHint = hint; else uiHint = ""; } var temp = base.GetFieldTemplateVirtualPath(column, mode, uiHint); return base.GetFieldTemplateVirtualPath(column, mode, uiHint); } }

Associate your custom template factory with the model in the RegisterRoutes method inside the Global.asax:

model.FieldTemplateFactory = new MyFieldTemplateFactory();
Done! :-)
kick it on DotNetKicks.com [digg]

Tags: ,

Input string was not in a correct format when installing SQL Server 2008 with Reporting Services

by ondrejsv 5. October 2009 16:37

I’ve got a fresh Windows 7 copy on my notebook so reinstallation of all applications is a necessary evil. Microsoft SQL Server 2008 proved to be the most evil one.

After starting good old setup.exe I learned from a message box that this program is incompatible with Windows 7 and I must apply SP1 after installation. OK, I selected all features to install without any hesitation, Reporting Services including. Suddenly in the middle of the installation, an “Input string was not in a correct format” popped out at me but the installation was not rolled back and seemed to finish successfully.

Then I wanted to apply SP1 but I couldn’t because the SP1 detected a problem in a previous installation and refused any other work until I resolve it.

A quick look in the log file (C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\DATE_OF_YOUR_INSTALL\Detail.txt):


2009-10-05 10:13:43 RS: System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Int32.Parse(String s, IFormatProvider provider)
at System.Diagnostics.PerformanceCounterLib.GetStringTable(Boolean isHelp)
at System.Diagnostics.PerformanceCounterLib.get_NameTable()
at System.Diagnostics.PerformanceCounterLib.get_CategoryTable()
at System.Diagnostics.PerformanceCounterLib.CategoryExists(String machine, String category)
at System.Diagnostics.PerformanceCounterCategory.Exists(String categoryName, String machineName)
at System.Diagnostics.PerformanceCounterCategory.Exists(String categoryName)
at Microsoft.ReportingServices.Common.RSPerfCounterInstallUtil.Uninstall()
at Microsoft.SqlServer.Configuration.RSExtension.RSPerfCounterUtil.SetPerfCounters()
at Microsoft.SqlServer.Configuration.RSExtension.SQLRSConfigurationPrivate.Install_ConfigRC(Dictionary`2 actionData, PublicConfigurationBase spcb)
2009-10-05 10:13:43 Slp: Configuration action failed for feature RS_Server_Adv during timing ConfigRC and scenario ConfigRC.

Indeed, a problem with my performance counters. Start-run-perfmon and a message box that some of my counters could not be loaded.

First I wanted to sacrifice Reporting Services as I don’t really need them. But I was in a trap: removal failed with the exactly same message (input string…).

I searched the Internet and found a simple command to rebuild performance counters: “lodctr /R”. Just be sure to run it as administrator otherwise it would claim “Error 5”.

And voila – Reporting Services are uninstalled and SP1 installed. :-) (And I believe that you can install the RS now if you want)

Tags: