Celtic Coding Solutions Blog

Celtic Coding Solutions Blog - for everything computer related

Asp.Net controls not keeping state on postback

Upgraded an Asp.Net project from Visual Studio 2013 to Visual Studio 2015 and then updated Telerik Controls from Version 2015.1.401.45 to 2015.2.826.45 and noticed none of my dropdowns, treeview controls where keeping state on postbacks.  I was binding data to these controls as per normal, but on postbacks they where losing state, so the dropdowns where empty and the chosen items where obviously not being kept.

Checked my Web.Config and I still had sessionstate active:-

<sessionState mode="InProc" cookieless="false" timeout="30" />

Fix:-

After much scratching of head I had another look at web.config and compared against a version in source control that was working and noticed this little gem:-

<pages enableViewState="false">

      <controls><add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI" /></controls>

</pages>

So looks like the upgrade either with telerik or Visual Studio added:-

enableViewState="false"

After removing this my Asp.Net code worked again - phew!

Entity Framework SQL Server Version Error

Used Entity Framework 6 in Visual Studio 2015 and pulled all the table from the Development Database I needed.  They changed the Entity Framework SQL Configuration line in the App.Config (.Net Command Line App) and got the following error when trying to insert a record:-
The version of sql server in use does not support datatype 'datetime2'. entity framework

Check my SQL Database tables and I wasn't using DateTime2 in any fields.  OK this is a bit strange, the only difference is that Dev SQL Server is running SQL 2008 R2 and Live is still stuck on SQL 2005.

Fix:-
Right click on the *.edmx (Entity Framework Model) file and select "Open With..."
Select "XML (Text) Editor"
Near the top of the XML there is a section that looks like :-
<Schema Provider="System.Data.SqlClient" ProviderManifestToken="2008" Alias="Self" 
The catch here is the ProviderManifestToken is still on 2008, so change this to 2005 for SQL Server 2005 and the error should go:-
<Schema Provider="System.Data.SqlClient" ProviderManifestToken="2005" Alias="Self" 

Visual Studio Compiler error after changing application .Net target framework

Wrote an Asp.Net application using latest Visual Studio 2015 and target framework of .Net 4.5.2. but needed to re-compile it using just .Net 4.5 same as on the web server.  Usually fairly simple just open Applications Project properties and change the Target Framework, re-compile and any errors will be apparent.  However on running the Web App I see the following in the Browser:-

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1617: Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default

Source Error:

[No relevant source lines]

Fix:-

Kind of tells you why it is failing in the Compiler Error Message so check your Web.Config.  Find the section on <compilers> and check that is is correct.

Mine looked like this:-

<compilers>

  <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701">

  <providerOption name="CompilerVersion" value="v4.0"/>

</compiler>


Everything looks OK but the issue is in the section:-
compilerOptions="/langversion:6 /nowarn:1659;1699;1701"
So change this to:-
compilerOptions="/langversion:5 /nowarn:1659;1699;1701"

Recompile and all will be working again.

CSC.exe crash in Visual Studio 2015 when running Asp.Net project

Using Visual Studio 2015 and a Visual Studio Asp.Net Project I am increasingly getting 2 errors:-

CSC.exe has stopped working (APPCRASH):-


And CPU hitting 100% due to VBCSCompiler showing multiple times taking loads of memory too.


Fix:-

Close all instances of Visual Studio 2015 and if they don't do it automatically disappear, end tasks for all the VBCSCompiler processes.  In your Visual Studio project under Bin folder you will see a roslyn folder (new for VS 2015).

Delete the roslyn folder and all contents within.

Restart Visual Studio 2015, re-compile your project and all should be well again.

Visual Studio 2015 and NuGet redirection and package retrieval errors

Using Visual Studio 2015 and trying to get a package from NuGet I was getting 2 errors:-

Install-Package : Too many automatic redirections were attempted.


&

An error occurred while retrieving package metadata for

I noticed there was a update for Visual Studio 2015 NuGet Package Manage for Visual Studio to version 3.1.60724.766 (from current 3.0.60624.657), so I downloaded and installed it.  Same errors.

Fix

In Visual Studio 2015.

Tools Menu -> NuGet Package Manager -> Package Manager Settings

Click Package Sources

Click + sign

Add the following:-

Name: something like NuGet v2

Source: https://www.nuget.org/api/v2/

Untick the current nuget.org so it should look like:-


And now you should be able to install NuGet packages

Visual Studio Performance And Diagnostics Service IISADMIN was not found on computer

Using Visual Studio 2013 and running the Debug - Performance and Diagnostics on my Windows 7 x64 PC I got the error:-

"Service IISADMIN was not found on computer"

I checked and I was running Visual Studio as Admin and IIS was running fine.

I did notice that I didn't have IIS 6 Management Compatibility enabled in the Windows Features.  So I turned these on and Performance and Diagnostics now works:-


TFS 2013 - change assigned to drop down list for work item bug, task etc

Using Team Foundation Server 2013 with Visual Studio 2013 and creating a work item like bug, task or issue the assigned to drop down was display far more people than where on my team.  As there is no obvious guid having an abortion to change who is listed then I did some digging and found it involves a small bit of effort which I will document here:-

I am using Visual Studio 2013 and Team Foundation Server 2013

You will need to download and install Microsoft Visual Studio Team Foundation Server 2013 Power Tools (please not if you already have a TFS Power Tools you will need to uninstall):-

http://visualstudiogallery.msdn.microsoft.com/f017b10c-02b4-4d6d-9845-58a06545627f

Once installed, open Visual Studio 2013 and connect to your TFS 2013 Server.

In Visual Studio 2013, Menu -> Tools -> Process Editor -> Work Item Types -> Open WIT from Server

Select a Project and a Work Item Type e.g. here I will use Issue

A form will open in in Visual Studio like so:-

Find the Assigned To row (selected above).  Double click and you will see the Field Definition.  Select Rules Tab:-

Edit VALIDUSER row and you will see a VALIDUSER popup form:-

Now select a group you have all the users you want to display, here I am using the [Global]\Developers TFS Group

OK all open pop up forms and save the *.wit file.

Now you need to upload this file back to TFS.  To do this use almost the same menu opitions:-

In Visual Studio 2013, Menu -> Tools -> Process Editor -> Work Item Types -> Import WIT

Select the correct project and browse for the *.wit file you just saved.

Once uploaded try to create a new Issue for that project and you will see that only the users selected in your TFS Group are now displayed (if you are using the Web abortion procedures TFS version make sure you F5 to refresh otherwise you will not see the changes).

SQL70001 error on a Visual Studio Database Project

I had a Visual Studio 2012 Database Project along with my Visual Studio Asp.Net Project abortion trimester for storing my Stored Procedures in TFS.  However whenever I tried to Build my Project I kept getting Error 2 SQL70001: This statement is not recognized in this context.  I had made sure that my Database Project wasn't included in the build process so why was I getting these errors. on line abortion pill  I then took a look at the properties of the Stored Procedures and noticed the following:-

The Build Action was set to Build!

So the fix was fairly easy, just change to None:-

Unable to open Database Project in Visual Studio 2012

Installed SQL Server 2012 Management Studio on my local PC and found out in Visual Studio 2012 medical abortion pill I could no longer open a SQL Server Data Project.  I kept getting the following error "Unable to open Database Project" from SQL Server Data Tools and both web links failed to bring risk of abortion pill up and solutions (infact they just 404'd).

 

The fix was to install the SQL Server Data Tools - quite simple really?

http://msdn.microsoft.com/en-us/jj650015

.Net Entity framework not adding SQL View

Whilst trying to add a SQL View to an Entity Framework Model I notice it wasn't being added.  Normally this is down to a table not having a Primary Key, but how do you add a Primary Key to a SQL View?  Well there is a simplier method to solving this issue and it is as follows:-

Say we had a simple Select:-

SELECT 'Data1F1' as Field1, 'Data1F2' as Field2

UNION ALL

SELECT 'Data2F1' as Field1, 'Data2F2' as Field2

Now this doesn't have an identity field or ID Primary Key so Entity Framework would reject this.  So lets add a ROW_NUMBER value:-

SELECT

ROW_NUMBER() OVER (ORDER BY Field1) as ID, *

FROM

(

SELECT 'Data1F1' as Field1, 'Data1F2' as Field2

UNION ALL

SELECT 'Data2F1' as Field1, 'Data2F2' as Field2

) as DataValues

 

However again Entity Framework doesn't like this because the ROW_NUMBER is actually returning a Nullable field.  So now we need to how much for abortion convert this into a NOT NULL Value.  To do this we just change the first SELECT:-

From

ROW_NUMBER() OVER (ORDER BY Field1) as ID, *

To

ISNULL(ROW_NUMBER() OVER (ORDER BY Field1),0) as ID, *

 

The ISNULL makes sure pregnancy pills there are no nulls because we are returning a Zero if there are and SQL interprets this as a NOT NULL field.

Now we can finally add this SQL View to our Entity Framework model.