Marc Gravell

17

votes
1

answer
405

views

Should an interface-based method invoke that uses “dynamic” still obey C# method resolution rules?

As I understand it, each language can have it's own dynamic handler, so that the appropriate rules are applied. I'm unsure if the following is correct/incorrect; thoughts? Scenario: two interfaces (one implements the other) with some methods: public interface IA { void Bar(object o); } public interf...
Marc Gravell
17

votes
1

answer
371

views

How can I reliably get the actual URL, even when there are percent-encoded parts in the path?

IIS and ASP.NET (MVC) has some glitches when working with urls with %-encoding in the path (not the query-string; the query-string is fine). How can I get around this? i.e. how can I get the actual URL that was requested? For example, if I navigate to /x%3Fa%3Db and (separately) to /x?a=b - both of...
Marc Gravell
18

votes
2

answer
2.9k

views

How can I convert a lambda-expression between different (but compatible) models?

(based on an email conversation, now recorded for information sharing) I have two models used at different layers: public class TestDTO { public int CustomerID { get; set; } } //... public class Test { public int CustomerID { get; set; } } and a lambda in terms of my DTO layer: Expression fc1 = (Tes...
Marc Gravell
18

votes
1

answer
3.6k

views

Why is my razor view complaining “} expected” after upgrade to razor 2 / mvc 4?

I have an existing razor 1 / mvc 3 view, with a few nested if - very simple, but after upgrading to razor 2 / mvc 4 it is complaining at runtime and compile (BuildViews) about } expected. It used to work fine. I've checked all the elements are well-formed / closed I've checked that all the { / } are...
Marc Gravell
19

votes
3

answer
1.7k

views

Using “async” (even if it should complete) as part of a MVC route deadlocks the route; how can this be avoided?

Consider the following (based on the default MVC template), which is a simplified version of some 'stuff' that happens in the background - it completes fine, and shows the expected result, 20: public ActionResult Index() { var task = SlowDouble(10); string result; if (task.Wait(2000)) { result = tas...
Marc Gravell
6

votes
4

answer
262

views

How can I normalize the capitalization of a group-by column?

On SQL Server configured as case-insensitive, group by can have interesting results when the [n][var]char column is not the first group by column. Essentially, it looks like whatever row it encounters 'first' (where 'first' is undefined in the absence of an order): wins for that grouping. For exampl...
Marc Gravell
22

votes
3

answer
1.5k

views

Does Monitor.Wait ensure that fields are re-read?

It is generally accepted (I believe!) that a lock will force any values from fields to be reloaded (essentially acting as a memory-barrier or fence - my terminology in this area gets a bit loose, I'm afraid), with the consequence that fields that are only ever accessed inside a lock do not themselve...
Marc Gravell
2

votes
4

answer
766

views

Windows utility to print and archive from a file drop

Now, I could go ahead and write this using FileSystemWatcher etc, but before I start coding - I wonder if there is a better option that I can re-use (rather than re-invent). From my web-server, I want to drop files (to be printed) into a network share as a queue (ordering not hugely critical). Ideal...
Marc Gravell
12

votes
6

answer
1.5k

views

Developer tool for configuring IIS6

edit: IIS6; I'm not sure IIS7 is an option in the immediate future... From a developer angle, I am constantly changing my IIS settings, or need to merge settings from other teams into different VMs. The 'Save Configuration to Disk' has never really worked well for me. Because we are making lots of s...
Marc Gravell
31

votes
4

answer
13.7k

views

Getting specific revision via http with VisualSVN Server

I'm using VisualSVN Server to host an SVN repo, and for some automation work, I'd like to be able to get specific versions via the http[s] layer. I can get the HEAD version simply via an http[s] request to the server (httpd?) - but is there any ability to specify the revision, perhaps as a query-str...
Marc Gravell
3

votes
3

answer
3.9k

views

How to write a preview pane (master/detail) with HTML and CSS

In the modern era of CSS, how would I create a pair of panels (for example, a preview window like in Outlook, or for master/detail views)? Ideally where the top (master) pane would get scrollbars, etc.? The intended use-case is so that a user can scroll in the top window while always being able to s...
Marc Gravell
13

votes
2

answer
1.1k

views

Using a custom WCF serializer in Silverlight

In 'full' .NET it is pretty easy to swap out the serializer - either in configuration, or via custom attributes. However, I want to do something similar in Silverlight's WCF - i.e. provide a different serialization engine. I will provide the engine (protobuf-net) - I just need to get WCF to use it!...
Marc Gravell
38

votes
2

answer
1.2k

views

Is the “textual order” across partial classes formally defined?

Specifically, in relation to field initializers (in this case, static) - §17.11 in ECMA 334: If a class contains any static fields with initializers, those initializers are executed in textual order immediately prior to executing the static constructor. Now, if we have multiple partial classes in s...
Marc Gravell
39

votes
3

answer
3.1k

views

EntitySet - is there a sane reason that IList.Add doesn't set assigned?

There are 3 ways of adding items to most lists... via a direct public API method, typically Add(SomeType) via the generic IList.Add(T) interface via the non-generic IList.Add(object) interface method and you normally expect them to behave more or less the same. However, LINQ's EntitySet is... peculi...
Marc Gravell
38

votes
2

answer
7.4k

views

Converting an integer to a boxed enum type only known at runtime

Imagine we have an enum: enum Foo { A=1,B=2,C=3 } If the type is known at compile-time, a direct cast can be used to change between the enum-type and the underlying type (usually int): static int GetValue() { return 2; } ... Foo foo = (Foo)GetValue(); // becomes Foo.B And boxing this gives a box of...
Marc Gravell
6

votes
2

answer
1k

views

How can I recognise an EF POCO proxy without referencing EF?

I need to spot EF POCO proxies; MSDN gives some hints based around ObjectContext.GetObjectType(type.GetType()) However, I would really like to do this without the EF reference. For example, with NHibernate, I can check whether the object implements a marker interface, using the name (as a string) 'N...
Marc Gravell
42

votes
3

answer
2.8k

views

Is IIS performing an illegal character substitution? If so, how to stop it?

Context: ASP.NET MVC running in IIS, with a a UTF-8 %-encoded URL. Using the standard project template, and a test-action in HomeController like: public ActionResult Test(string id) { return Content(id, 'text/plain'); } This works fine for most %-encoded UTF-8 routes, such as: http://mydevserver/Hom...
Marc Gravell
4

votes
1

answer
292

views

How to access a basic JSIL library (from C#) in a web page?

I'm trying to get started with JSIL. I've followed the directions as far as I understand. I have a very basic C# dummy project with the code: namespace TestLib { public class MagicType { public int Multiply(int x, int y) { // test instance method return x * y; } public static int Add(int x, int y) {...
Marc Gravell
8

votes
1

answer
846

views

Is pre-release versioning possible in nuget

According to the documentation, pre-release versioning is supported, with an example given of: Within the NuSpec file, specify the version in the element 1.0.1-alpha I am building from a .nuspec file; if I include this line verbatim, then run (at the package manager console): PM> nuget pack 'Nuget\...
Marc Gravell
50

votes
1

answer
9.2k

views

Why is my hidden input writing: value=“value” instead of true/false?

I have an MVC4 site, with (as part of a hidden form): The value of ViewBag.Test is true. The form field is posting to an input parameter of the form: public ActionResult SomeAction(bool somefield = false, ...) but somefield is always false. Upon investigating, I see that the source code has: However...
Marc Gravell
8

votes
1

answer
1.2k

views

Why does fastmember not seem faster than reflection here?

(this is via a question on twitter, re-asked here with permission) I'm trying to validate some objects quickly (to test for nulls), and I thought FastMember might be able to help - however, with the tests shown below I am seeing much worse performance. Am I doing something wrong? public class Valida...
Marc Gravell
4

votes
2

answer
2.5k

views

Does NetworkStream.DataAvailable see buffered data?

Does NetworkStream.DataAvailable know whether the sender's send buffer is empty? Or does it simply indicate whether the receiver's read buffer has data? My assumption is the latter... Specifically, for some socket work involving an ongoing conversation, I currently use a length-prefix so the the rec...
Marc Gravell
65

votes
5

answer
4.1k

views

How can I debug an internal error in the .NET Runtime?

I am trying to debug some work that processes large files. The code itself works, but there are sporadic errors reported from the .NET Runtime itself. For context, the processing here is a 1.5GB file (loaded into memory once only) being processed and released in a loop, deliberately to try to reprod...
Marc Gravell
6

votes
1

answer
1.5k

views

Can I re-use object instances to avoid allocations with protobuf-net?

Context: this is based on a question that was asked and then deleted before I could answer it - but I think it is a good question, so I've tidied it, rephrased it, and re-posted it. In a high-throughput scenario using protobuf-net, where lots of allocations are a problem (in particular for GC), is...
Marc Gravell
67

votes
11

answer
16.3k

views

Using scripts in a master page with ASP.NET MVC

I'm fairly new to ASP.NET MVC, and I'm having a little trouble with scripts... in particular, I want to use jQuery in most pages, so it makes sense to put it in the master page. However, if I do (from my ~/Views/Shared/Site.Master): Then that is literally what goes down to the client - which of cour...
Marc Gravell
25

votes
1

answer
1.2k

views

How can I choose parameters for GC.RegisterForFullGCNotification?

If you want to receive GC notifications (for example, to transfer load between nodes during collection), then you can use the trio of methods, GC.RegisterForFullGCNotification, GC.WaitForFullGCApproach and GC.WaitForFullGCComplete - however, the parameters passed to GC.RegisterForFullGCNotification...
Marc Gravell
25

votes
5

answer
1k

views

How to mutate a boxed struct using IL

Imagine we have a mutable struct (yes, don't start): public struct MutableStruct { public int Foo { get; set; } public override string ToString() { return Foo.ToString(); } } Using reflection, we can take a boxed instance of this struct and mutate it inside the box: // this is basically what we want...
Marc Gravell
8

votes
5

answer
1.3k

views

Can you convince a DataContext to treat a column as always dirty?

Is there a way to force LINQ-to-SQL to treat a column as dirty? Globally would suffice.... Basically, I've got a problem with some audit code on a legacy system that I'm talking to with L2S, imagine: var ctx = new SomeDataContext(); // disposed etc - keeping it simple for illustration var cust = ctx...
Marc Gravell
76

votes
6

answer
7.3k

views

How can I prevent synchronous continuations on a Task?

I have some library (socket networking) code that provides a Task-based API for pending responses to requests, based on TaskCompletionSource. However, there's an annoyance in the TPL in that it seems to be impossible to prevent synchronous continuations. What I would like to be able to do is either:...
Marc Gravell
3

votes
3

answer
1.1k

views

gadget / widget manager

Does anybody know of any pre-canned gadget/widget management framework (along the lines of iGoogle etc) that I would be able to use on an ASP.NET MVC site (presumably loading divs via jQuery etc)? In particular, I'd rather not write all the selection / location code if there is something decent alre...
Marc Gravell
3

votes
2

answer
585

views

Ajax auto-complete, with bespoke popup location

I'm doing something that involves ajax auto-completion of phrases in a . I've got this working well using the jquery autocomplete plugin; however, it is hard-coded into this to position the popup below the . For what I'm working on, the is at the bottom of the page; I ideally want the options to ap...
Marc Gravell
3

votes
2

answer
1.1k

views

MethodAccessException on CF 2.0 List<T>.Sort

I've got some library code that works on a range of .NET runtimes (regular, CF, Silverlight, etc) - but a small block of code is breaking only on CF 2.0, with a MethodAccessException. I'm pretty sure it is a runtime bug, but does anybody know any good workarounds? It works fine in CF 3.5, but I need...
Marc Gravell
8

votes
7

answer
1.3k

views

Influencing AOP with attributes via IoC; code-smell or elegant?

I'm using StructureMap at the moment, generally with convention-based (Scan()) auto-configuration, and I'm looking to add decorator-based caching into the pipeline. If I configure it manually that is fine, but Scan() is just so convenient when you get lots of dependencies... I'm toying with noting c...
Marc Gravell
15

votes
3

answer
9.6k

views

What are the protocol differences between WebSockets versions?

Is there a summary anywhere of the protocol difference between the various WebSockets drafts? The browser support levels are still all over the place, so it is not sufficient just to consider the RFC. Obviously the Sec-WebSocket-Version changes, and I know the early format was pretty radically diffe...
Marc Gravell
15

votes
2

answer
9.2k

views

Why does my project.json / xproj project not open in Visual Studio 15 (preview)?

I have an existing solution involving multiple project.json (and corresponding xproj) projects that I have been working on for some time. It works fine in Visual Studio 2015, but it fails to load in VS 15 (preview), just showing a failed load icon for each. No messages are printed. What is happenin...
Marc Gravell
7

votes
2

answer
2.9k

views

Configuring profiles with StructureMap

important; I'm really looking for a StructureMap answer here. Please don't say how to do it with Windsor, Spring, Unity, or any of the others. I'm playing with StructureMap for IoC - and basically my aim is to have a 'default' profile that defines the core types, and a number of named profiles that...
Marc Gravell
11

votes
1

answer
1.6k

views

OutputCache serving long-stale data

I'm flumoxed... re this and this 'meta' questions... A very basic http request: GET http://stackoverflow.com/feeds/tag?tagnames=c%23&sort=newest HTTP/1.1 Host: stackoverflow.com Accept-Encoding: gzip,deflate which hits a route decorated with: [OutputCache(Duration = 300, VaryByParam = 'tagnames;sort...
Marc Gravell
11

votes
3

answer
2.7k

views

WCF extensions without including the assembly version

As discussed here, I'm trying to add a WCF endpoint-extension; I've got it working, but I need to include the full assembly details: What I would like to do (to avoid issues when updating etc, especially for samples) is to include just the names: (which is what you might expect from standard assembl...
Marc Gravell
141

votes
11

answer
20.2k

views

switch / pattern matching idea

I've been looking at F# recently, and while I'm not likely to leap the fence any time soon, it definitely highlights some areas where C# (or library support) could make life easier. In particular, I'm thinking about the pattern matching capability of F#, which allows a very rich syntax - much more e...
Marc Gravell
37

votes
7

answer
21.6k

views

Identifying NHibernate proxy classes

I'm not an NHibernate user; I write a serialization utility library. A user has logged a feature-request that I should handle NHibernate proxy classes, treating them the same as the actual type. At the moment my code is treating them as unexpected inheritance, and throwing an exception. The code won...
Marc Gravell

View additional