Tutorials, tips&tricks, snippets..



Visual Studio

HOWTO: close the TCP connection of other process calling Windows API

We know that TCPview, for example, can close the TCP connection for the other process without closing the process. So how to implement it? Suppose there is a process connecting to the a remote ip and port, how to terminate that connection?

Continue reading “HOWTO: close the TCP connection of other process calling Windows API”

What is the difference between Public, Private and Protected?

We always see the Access Modifiers in our code, but do we really know them?

Continue reading “What is the difference between Public, Private and Protected?”

No connection string named ‘MyEntities’ could be found in the application config file

This error occurs when you haven’t set the correct value in your config or when you have one project calling another project. How? Why? Let’s see the details!

Continue reading “No connection string named ‘MyEntities’ could be found in the application config file”

How to create a log file with C#

As the title said, here how you can create useful log files for your applications. This code creates the folder where you want to create the files (if the folder doesn’t exist) and creates one file per day.

Continue reading “How to create a log file with C#”

Create a COMvisible dll

If you have to create a dll with C# (or and use it in old .NET framework, you have to create a COMvisible dll. How? Let’s start!

Continue reading “Create a COMvisible dll”

Entity Framework 6: audit / track changes

Entity Framework is very powerful. It takes care of the dirty jobs and it makes your programmer’s life easier. A very useful feature you can use is override the saveChanges method, for example, to audit/track the changes made.

Continue reading “Entity Framework 6: audit / track changes”

How to see executed sql code within entity framework

If you want to track what entity framework (6.0 or more) is doing, you can convert your actions in sql code.

What you have to do is:

using (var db = new AccessData.Entities())
//logger: is a function to write output in a file txt
db.Database.Log = s => Utility.Logger(s);
var list = db.myTable.Where( x => x.NOME = "piero");
//you will find in your txt file the sql code of the
//operation above (SELECT * FROM myTable where NOME="piero");

Note: For those using Entity Framework 6 and up, if you want to view the output SQL in Visual Studio (like I did) you have to use the new logging/interception functionality. More infos here.

BadImageFormatException using IISExpress

I had written this post about the BadImageFormatException, when I had found again this error. Why? The solution in my linked post is simply and clear, it works! What’s difference? That was my first time I found this error while developing a WCF.. but does it matter? Or the error is somewhere else? After some struggling hours, here is my solution to this problem when working with WCF.

Continue reading “BadImageFormatException using IISExpress”

How to solve LoadFromRemoteSources error

The issue was something like there are some references into the application from the network shared folder. When compiling the application there was a weird error saying (or similar):

Continue reading “How to solve LoadFromRemoteSources error”

Powered by

Up ↑