Error: Only one element allowed per config file and if present must be the first child of the root element. No Comments


I have this project that I need to add a customized configuration settings in app.Config or web.Config.
After implement necessary class, I then added ConfigSections element in app.Config. However, when I ran the application I received this error ‘Only one element allowed per config file and if present must be the first child of the root element.’.

To resolve this issue, the must be the first element of the root config which is the .
So, it should be like as shown below.
BEFORE:

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3.     <startup>
  4.         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  5.     </startup>
  6.   <configSections>
  7.     <section name="LogConfig" type="DN.Services.Logging.LogConfiguration, DentalNetworkServices"/>
  8.   </configSections>
  9.   <LogConfig LogError="true" LogInfo="false" LogSuccess="false" LogWarning="false" />
  10. </configuration>

AFTER:

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3.   <configSections>
  4.     <section name="LogConfig" type="DN.Services.Logging.LogConfiguration, DentalNetworkServices"/>
  5.   </configSections>
  6.   <startup>
  7.     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  8.   </startup>
  9.  
  10.   <LogConfig LogError="true" LogInfo="false" LogSuccess="false" LogWarning="false" />
  11. </configuration>

How to bring to front the custom form in setup project No Comments


  1.  public class MsiWindow : IWin32Window
  2.     {
  3.         private IntPtr _hwnd;
  4.         static MsiWindow  _window;
  5.         static object obj = new object();
  6.  
  7.         public MsiWindow(IntPtr handle)
  8.         {
  9.             _hwnd = handle;
  10.         }
  11.  
  12.         public IntPtr Handle
  13.         {
  14.             get { return _hwnd; }
  15.         }
  16.  
  17.         private static IntPtr GetMsiHandle()
  18.         {
  19.             IntPtr hwnd = IntPtr.Zero;
  20.  
  21.             foreach (var proc in Process.GetProcessesByName("msiexec"))
  22.             {
  23.                 if (proc.MainWindowHandle == IntPtr.Zero)
  24.                     continue;
  25.  
  26.                 if (string.IsNullOrEmpty(proc.MainWindowTitle))
  27.                     continue;
  28.  
  29.                 hwnd = proc.MainWindowHandle;
  30.                 break;
  31.  
  32.             }
  33.  
  34.             return hwnd;
  35.         }
  36.  
  37.         public static MsiWindow GetMsiWindow()
  38.         {
  39.             if (_window == null)
  40.             {
  41.                 lock (obj)
  42.                 {
  43.                     if (_window == null)
  44.                     {
  45.                         _window = new MsiWindow(GetMsiHandle());
  46.                     }
  47.                 }
  48.             }
  49.             return _window;
  50.         }
  51.  
  52.     }

to use this class

  1. frmConfig config = new frmConfig();
  2. frmConfig.ShowDialog(MsiWindow.GetMsiWindow());

Issue: FileUpload inside MultiView not working on First Postback in ASP.Net No Comments



I had this problem in one of my project job, it took me sometime to figure out who was the culprit.
However, when I look at the source view of the loaded page on the browser, the “form” element has no enctype=”multipart/form-data” attribute which is required in uploading a file. While the FileUpload element was in the 3rd view, I need to put a fake or dummy FileUpload that will always visible (style=”display:none”) to engine.

Asp.Net Mvc no intellisense in views No Comments



I have experienced this problem after installing visual studio 2013 web express, doing google answers resolved this problem.
To resolve this problem, find the web.config under “Views” folder and add the highlighted element below.

  1.  <appSettings>
  2.      <add key="webpages:Version" value="3.0.0.0"/>
  3.  </appSettings>

Sql Server Installation Wizard Disappear No Comments


I have this problem when I tried reinstalling SQL SERVER 2008 R2 and SQL SERVER 2012. Just following this thread from Microsoft, it solved this problem.

Here’s how I did it
1. Find the SqlSetup.log in temp folder by typing %temp%.
2. If the you see this type of error “Error: Cannot load .Net security policy file” then, your good (just execute step 3)
3. Bring up the command promp (runAs admin) and type this – “C:\Windows\Microsoft.NET\Framework64\v2.0.50727\CasPol.exe -machine -reset”.

Error:Configuration system failed to initialize exception in Vb.net No Comments



I had this problem when I have converted my VB.Net Project Framework from 3.5 to 4.
My solution is to delete the app.config, after that I open the project properties, goto Settings Tab and just alter / add a dummy text and save it, Visual Studio will generate a new app.config.

Error: Mixed mode in assembly in .NET 4 No Comments



This error usually appears after converting a project from .net any lower verson to .net 4 and this project also had referenced another .net project with lower version.
To solve this error simply add the below configuration into your project app.config or web.config inside element.

  1. <startup useLegacyV2RuntimeActivationPolicy="true">
  2.     <supportedRuntime version="v4.0"/>
  3. </startup>

Issue: SelectedItem of the Listview is delayed No Comments



I have developed an asp.net website and I used the Listview control for some of the website navigation and define its style.
Now, the problem was when you clicked the link on the first time, the selected item would not be highlighted as what I have defined the style when selected, and on the second.. third.. time of selection, the previous selected link would be the one highlighted and not the current one. As usual GOOGLE is the world wide web friend, I ran into a blog that encountered the same problem as mine.
Here’s what I have done to solve the problem.

On the SelectedIndexChanging event of the Listview, I set the SelectedIndex and reload the data of the listview and now its working.

  1. protected void lvwSequence_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
  2. {
  3.             lvwSequence.SelectedIndex = e.NewSelectedIndex;
  4.             this._processPresenter.LoadWFSequence();
  5. }

Issue:Listview inside UpdatePanel not working No Comments



I had this web project using ASP.Net, its all good until I had to use a ListView control to create a list clickable items. And, because I want it to be more responsive so I wrapped it with UpdatePanel, however, when you click a link inside it, it would do a full Postback instead of partial Postback. I also took me sometime to figured it out. One solution that I used was I added an ClientIDMode=”AutoID” on the page directive.

How to concatenate rows in sql server using XML No Comments


  1. SELECT DISTINCT
  2.       fileid
  3.     , STUFF((
  4.         SELECT N', ' + CAST([filename] AS VARCHAR(255))
  5.         FROM tblFile f2
  6.         WHERE f1.fileid = f2.fileid —- string with grouping by fileid
  7.         FOR XML PATH ('')), 1, 2, '') AS FileNameString
  8. FROM tblFile f1