Category: .NET

The ALTER TABLE statement conflicted with the FOREIGN KEY constrain

I've been trying to apply a new migration and I was getting the following error: The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_dbo.Parent_dbo.Childs_ChildId". The conflict occurred in database "parents_db", table "dbo.Childs", column 'ChildId'. In my case, the table contained data. Therefore, either you have to assign a default value, set it as

Continue Reading

MediaElement Not Firing Events

Today, we encountered quite an interesting problem. MediaElement wasn't firing events. Using simple speech synthesis on Windows 8.1 using the speech synthesiser we tried:

None of the variations worked. The speech worked just the event wasn't getting fired. After a bit of digging it turned out that in order to fire events MediaElement must

Continue Reading

Databindings - small values treated as 0s

Today, I encountered an interesting problem with WinForms. In the application, NumericUpDowns (shown below) were used with small values e.g. 0.00001 etc. However, after we refreshed the panel, the value was being set to the default value. Digging further into the problem it turned out that the default Microsoft DataBinding converter was unable to convert

Continue Reading

How to use - (dash) in the ASP.NET MVC call?

ActionName attribute can be used:


Continue Reading

How to override MongoDB connection details in appsettings.json on Azure

It is actually pretty simple to override the connection settings in Azure. If you manage your connection inside the appsettings.json:

Then in Azure you should define these in Application Settings -> App settings. Seperate the layers by ":" (semi-colon). For example: Key: MongoConnection:ConnectionString Value: mongodb://admin:abc123!@localhost. Similarly, the database (key) MongoConnection:Database value: YourDb

Continue Reading

Extracting Username and Password from Basic Authentication

Basic authentication is one of the most fundamental ways in which authentication can be performed. It does not require multiple calls and is very easy to learn. In this article, I will present how to use C# (usually with WCF) to extract basic authentication credentials from the request. Step 1 - Understanding Basic Authentication Whenever

Continue Reading

Set background color for all buttons in WPF

Hehe, simple enough thing, but took long enough. You need to use resources to do it.

In there you can define styles:

It is simple enough to read: apply it to buttons. Property: Background set the value to whatever color you like.

Continue Reading

Lists of Lists in C# - if one is updated, all are updated.

I was doing an assessment for university regarding password cracking. They say that experience is something that cannot be learnt. Never that notion has been more true than today when I was attempting to create a list of lists: List<List<string>>. I had "virtually" unbounded memory, but I had to make sure that I could maximise

Continue Reading

Serializing Anonymous DataMemeber

I've been working win MVC Web API and encountered an annoying problem. It does not, by default serialise anonymous data members.

When you try to serialise this kind of data you get this beautiful exception:

Converting anonymous type to a string also caused exception. But there is also JavaScriptSerializer:

Now using getter,

Continue Reading

Useful Linear Trendline Class in C#

I've searched and searched trying to find a simple class to calculate a slope and intercept from a set of points. Here is the outcome, but I probably modify it to use LINQ rather then loops

Continue Reading