Pages

Monday, October 1, 2018

Referencing .NET 4.5 dll in .NET Core csproj

Hi All,

After a long time, I realized that I need to share something with the outer world.

Since we are inside the .Net core world and things are moving fast towards making the .Net 4 and pre .Net 4 obsolete. Let's try something that do not have much on the internet.


I have a .Net 4.5.2 application. I had to create a new console application in the solution to do some scheduling (not windows service, obviously). I went ahead and took the pleasure of doing it .Net Core. The latest version by the time of this writing is .Net core 2.1.

I stumbled upon a series of problems with .Net Core, so I thought it might be helpful for others as well, if I posted about those here...

When I created a new project and added a reference for .Net 452 project inside the console application, it went smooth and everything built alright, but as soon as I tried to run the console application it started crashing on the first .Net 452 reference inside the project structure. In my case, it was "System.Configuration".

It was a default error saying... 
System.IO.FileNotFoundException: 'Could not load file or assembly _ _ _. The system cannot find the file specified.'
So, what do I do, I went to Google and tried to find the problem, the first post that I could find was this one by Scott Hanselmann.

But this was not my problem, as this post was related to Nuget Packages, not related to normal assembly reference. After a little more searching I was able to find this StackOverflow Post. which is quite close to my problem.

I only had to modify the CSProj and set the TargetFramework to multiple frameworks as the VS 2017 UI does not allow me to do that...

So, I had to go to another editor or unload the project from visual studio and edit the csproj file. But I prefer VS Code, which is super fast to load and very good tool to help with these kind of operations. I would recommend opening both the editors in parallel on a development machine.

Anyways, I had to add to change this tag in the csproj file...
<TargetFrameworks>net452;netcoreapp1.1</TargetFrameworks>

Notice the change from the <targetframework> to <targetframeworks>, an additional 's' for multiple Frameworks support with .Net Core.

One more thing to care about, you might need to give the specific version of .Net Framework that you are using in other projects, like in above example it is 4.5.2

This is it... Happing Coding... 


Wednesday, October 30, 2013

Whats new in VS 2013 - Peek Definition

Along with some other awesome features of VS 2013. One of my favorites is peek definition.

This feature should have been a part of Visual Studio since day one, but since it was not there, no one really asked about it.

So here is how it really works.

In the previous versions of Visual Studio we had to use the "Go to Definition (F12)"  menu option on the right click menu or the context menu to view the code of some other function, but the problem with it was that the current view was updated and the developer had to track back to the previous location using 'CTRL' + '-' key or maybe closing the file in case the function was in another file

Now VS 2013 gives an option to peek into the definition of another function by opening another smaller window on top of the current code editor window to peek into the code.



Right Click Menu for Peek

Peek Window

Here, the developer can not only view the function but can also see other functions in the same code file by scrolling up and down in the same code file. A developer can also do all sorts of tasks that one can think of in a code editor window, because it is a fully functional code editor window itself.

The developer can get rid of that window by simply pressing the "escape" key.

Monday, October 28, 2013

What's new in Visual Studio 2013 - Hanselman Blog Post

I wanted to shed some light on this, but Mr. Scott Hanselman already did this and out of respect only I am going to share only the link of his blog where he has shared the videos of the new features of Visual Studio .Net 2013.

Here is a link to his blog, which shows top new features in Visual Studio 2013.

http://www.hanselman.com/blog/SCREENCASTSWhatsNewInVisualStudio2013LearnOverLunch.aspx

Enjoy the videos and enjoy the new features of Visual Studio .Net 2013

Friday, October 25, 2013

Converting Comma separated values to Temporary Table in T-SQL

Today, I want to share a technique that we have to use often in SQL while using with .Net. We have to pass a comma separated string into a Stored Procedure and use it as a table (somehow) to manipulate the results.

Since we had to pass the comma separated string to a stored procedure many times. We created a SQL Function for it and then we only had to call it.

Here is how the code for the T-SQL function looks like...

CREATE FUNCTION [dbo].[GetIDsTableFromIDsList]
(
      @IDsList VARCHAR(MAX)
)
RETURNS @IDsTable TABLE ( [ID] INT )
AS
    BEGIN
        DECLARE @ID VARCHAR(10)
        DECLARE @Pos 

        SET @IDsList = LTRIM(RTRIM(@IDsList)) + ','
        SET @Pos = CHARINDEX(',', @IDsList, 1)

        IF REPLACE(@IDsList, ',', '') <> ''
            BEGIN
                WHILE @Pos > 0
                    BEGIN
                        SET @ID = LTRIM(RTRIM(LEFT(@IDsList, @Pos - 1)))
                        IF @ID <> ''
                            BEGIN
                                INSERT  INTO @IDsTable
                                        ( [ID] )
                                VALUES  ( CAST(@ID AS INT) )
                            END
                        SET @IDsList = RIGHT(@IDsList, LEN(@IDsList) - @Pos)
                        SET @Pos = CHARINDEX(',', @IDsList, 1)
                    END
            END  
        RETURN

    END

This function receives a simple comma separated list of IDs and loops over the list and then after inserting all the values into a temporary table. It returns the temporary table

Wednesday, October 23, 2013

What's new in ASP.Net 4.5 - Garbage Collector

There are a few improvements shipped with .Net Framework 4.5, but the first one that I would share some details with, is Garbage Collection. If you would like to read the basics of the Garbage Collection read this

There are some performance improvements in the Garbage Collection process, which I would like to discuss here. GC is always a process which consumes both memory and the processor a lot and it has always been a problem area for websites running under .Net because the process for ASP.Net applications is continuously running and a lot of users are requesting the content and thus creating many objects on the fly and many of those objects are supposed to be destroyed by the GC too often. 

Whenever GC is trying to clean up the memory. It consumes a lot of resources and the GC thread suspends the main website threads and thus the other resources have to wait for the cleanup process to complete before serving further requests of the users.


GC Model in .Net 4.0

Previously (in .Net 4.0), if we could simulate the GC Thread along with ASP.Net website threads. The picture should be something like this...


GC Model in .Net 4.0

As you can see in the above figure that whenever the two processes of GC run (one for each logical processor). The other threads have to wait for the cleanup process to complete before carrying on with the tasks, so user feels the processes to be less responsive while the garbage collector is running.

GC Model in .Net 4.5

Now (in .Net 4.5), the GC Thread takes less time and consumes lesser time, so that other threads are not suspended for longer periods

GC Model in .Net 4.5


Microsoft introduced new features in server GC for .Net 4.5 and as you can see in this figure, the server GC has introduced a new thread for Garbage Collector which is running in the background and is collecting objects from Generation 2, so the main application threads do not suspend much, thus increasing overall application performance. 

Enable Server GC in Config

To enable server GC in your application, you only have to add this to your configuration file.

Enable GC in Config

  

For any queries, please comment below...

References: