Deploying MVC Application With System.Web.Mvc Update



Error:

Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

This occurred during browsing of MVC Application published in the IIS.

Cause:

Automatic Windows update thus, ASP.Net MVC 3 was included in the update. Web application reference was replaced by newer version.


Fixes:

Open Web config and replace the following highlighted by yellow with the values highlighted by green.

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>


  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.1" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>



Continue Reading

Display Key and Values of AppSettings To DataGridView From External Webconfig Using Vb.Net




Private Sub btnOpenFile_Click(sender As System.Object, e As System.EventArgs) Handles btnOpenFile.Click
        If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then

            Dim appSetDT As DataTable
            appSetDT = New DataTable("AppSettings")

            Dim KeyNameCol As DataColumn = New DataColumn("KeyNameCol")
            KeyNameCol.DataType = System.Type.GetType("System.String")
            Dim KeyValueCol As DataColumn = New DataColumn("KeyValueCol")
            KeyValueCol.DataType = System.Type.GetType("System.String")
            appSetDT.Columns.Add(KeyNameCol)
            appSetDT.Columns.Add(KeyValueCol)

            Dim FileName As String = OpenFileDialog1.FileName.ToString()
            Dim map As New ExeConfigurationFileMap()
            map.ExeConfigFilename = FileName
            Dim config As System.Configuration.Configuration = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None)

            Dim appSettings = config.AppSettings
   
            Dim keyCount As Integer = appSettings.Settings.Count
            Dim keyName As String
            Dim keyValue As String

            'App Settings
            If appSettings.Settings.Count = 0 Then
                MsgBox("AppSettings is empty.", MsgBoxStyle.Information)
            Else
                For Each key In appSettings.Settings.AllKeys
                    keyName = key
                    keyValue = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None).AppSettings.Settings(keyName).Value.ToString()        

                    Dim appRw As DataRow
                    appRw = appSetDT.NewRow()
                    appRw.Item("KeyNameCol") = keyName
                    appRw.Item("KeyValueCol") = keyValue
                    appSetDT.Rows.Add(appRw)
                Next

            End If
            'Load Data Table to Data Grid View
            dgvAppSettings.DataSource = appSetDT
            dgvAppSettings.Columns(0).Width = (dgvAppSettings.Width - 25) / 2
            dgvAppSettings.Columns(1).Width = (dgvAppSettings.Width - 25) / 2
            dgvAppSettings.Columns(0).HeaderText = "Key"
            dgvAppSettings.Columns(1).HeaderText = "Value"

     End If
    End Sub
Continue Reading