Week 18 roundup

Last week recap an links:

Image courtesy of kanate / FreeDigitalPhotos.net

Image courtesy of kanate / FreeDigitalPhotos.net

What are your best reads this week? Leave them in the comments below.

Posted in Uncategorized | Tagged , , | Leave a comment

No Default Instance defined solved by doing less

StructureMap threw an exception after some refactoring

StructureMap Exception Code: 202 No Default Instance defined for PluginFamily IDoSomething

Solved by removing duplicates from assembly scan:

ObjectFactory.Initialize(c =>
{
    c.Scan(s =>
    {
        s.TheCallingAssembly();
        // Already loaded with TheCallingAssembly above
        // s.AssemblyContainingType<SomethingImplementation>();
        s.ConnectImplementationsToTypesClosing(typeof(IDoSomething));
    });
});

Turned out the IDoSomething was mapped to 2 implementations (of the same type) and StructureMap could not decide which was the default.

Posted in Development | Tagged | Leave a comment

Week 17 roundup

Last week recap an links:

Image courtesy of kanate / FreeDigitalPhotos.net

Image courtesy of kanate / FreeDigitalPhotos.net

What are your best reads this week? Leave them in the comments below.

Posted in Uncategorized | Tagged , , , | Leave a comment

Strange characters after reading and writing a textfile

This week I helped out my Business Intelligence colleagues again.

After tackling another problem with a regular expression, the end result contained strange characters. In the output below there is a question mark icon where the Pound (£) sign used to be.

"Whatever returned, � 35.00 debited";3;1;"";0;0

The problem is that the system where the code executes uses a different code page. This messes with the encoding. To solve this we used the Enconding.Default as parameter when reading or writing the text file.

string input = File.ReadAllText(sourceFile, Encoding.Default);
// pattern removed for simplicity
string output = Regex.Replace(input, pattern, " ");
File.WriteAllText(destinationFile, output, Encoding.Default);

Posted in Development | Tagged , | Leave a comment

LINQ to Entities does not recognize the method

After my unit tests showed all green, there was still a bug in my code.

System.NotSupportedException: LINQ to Entities does not recognize the method ‘System.Collections.Generic.IList`1[iCal.ISchedulerEvent] ProcessItem(iCal.ISchedulerEvent)’ method, and this method cannot be translated into a store expression.

Solution is to call the ToList() method to get the data into dotNET.

var possibleResults = DbSet
        .Where(item => item.Start < request.End)
        .ToList(); // else the link-to-entities will complain
var result = possibleResults
        .SelectMany(item => ProcessItem(item))
        .OrderBy(item => item.Start)
        .FirstOrDefault();
Posted in Development | Tagged , , | Leave a comment