Quantcast
Channel: RazorGenerator Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 525

Commented Unassigned: Workaround for bug in Mono framework [112]

$
0
0
Mono's implementation of System.Web is crap (see https://github.com/mono/mono/blob/master/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationHost.cs#L194 for an example on "how to write terrible code").

When MvcWebConfigTransformer tries to use WebConfigurationManager.OpenMappedWebConfiguration, it crashes at the location linked above. This prevents compilation of views under Mono at all. There isn't much RazorGenerator can do to fix this at the source (short of reimplementing System.Web).

So in order to work around this issue, I'm suggesting that line 44 to line 64 of MvcWebConfigTransformer.cs is wrapped in a try-catch, such that the code becomes:

```
try
{
var config = WebConfigurationManager.OpenMappedWebConfiguration(configFileMap, directoryVirtualPath);

// We use dynamic here because we could be dealing both with a 1.0 or a 2.0 RazorPagesSection, which
// are not type compatible (http://razorgenerator.codeplex.com/workitem/26)
dynamic section = config.GetSection(RazorPagesSection.SectionName);
if (section != null)
{
string baseType = section.PageBaseType;
if (!DefaultBaseType.Equals(baseType, StringComparison.OrdinalIgnoreCase))
{
_transformers.Add(new SetBaseType(baseType));
}

if (section != null)
{
foreach (NamespaceInfo n in section.Namespaces)
{
razorHost.NamespaceImports.Add(n.Namespace);
}
}
}
}
catch (IndexOutOfRangeException)
{
// Bug in Mono framework.
// Configure namespaces using the RazorGenerator directives file instead.
}
```

As stated in the code above, users can specify the namespaces using the directives file (which I've tested to confirm works). I feel as though this is an appropriate workaround given that:

a) There's not much RazorGenerator can do to work around the issue, other than implementing code to search for Web.config and use an XML reader to get the namespaces out.
b) There's an appropriate and easy workaround (using the directives file), for the small percentages of users using RazorGenerator with Mono.
c) Mono's implementation of System.Web and System.Web.Configuration is terrible in many other ways, so there's not much point trying to fix the issue upstream in Mono (especially given that I've already worked around several other bugs related to their implementation of System.Web).

At the moment I've built a version of RazorGenerator with this try-catch in it, but obviously long term I want to discard my patch and just use the upstream RazorGenerator version.
Comments: I'll test this next weekend since I don't get time after work during the week.

Viewing all articles
Browse latest Browse all 525

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>