Social Icons

Featured Posts

Sunday, 12 November 2017

Sql Server - Fix Error - Can not use the backup file because it was originally formatted with 512 and is now on a device with sector size 4096

Recently i encountered Sql Server Error when i try to take backup of database from SSMS (Sql Server Management Studio) i.e

System.Data.SqlClient.SqlError : can not use the backup file "path" because it was originally formatted with sector size 512 and is now on a device with sector size 4096


 Problem is , backup file which was created with different sector size , so it is not possible now to use it. So solution is remove that backup file 

Now add the new file for taking backup and ok

That's it simple. Just remove the old backup file with different sector size.

Friday, 27 October 2017

[Solved] C# - OriginalValues cannot be used for entities in the Added state Visual Studio Error

Hi, recently i encountered runtime error when i try to insert values using Entity Framework

"OriginalValues cannot be used for entities in the Added state"

This could arise because missing column or inserting null value or column width exceeding in insert statement.

You can find the error message in Exception object 


Based on your Error Message you can take corrective action to rectify this.


Friday, 29 September 2017

[SOLVED] access denied can not execute the program csc.exe after publishing .net application web deploy mvc app

Hi, Recently i encountered this error after publishing an application to winhost server.

Error stacktrace is
[Win32Exception (0x80004005): Access is denied]

[ExternalException (0x80004005): Cannot execute a program. The command being 
executed was "E:\web\nrgwareh\bin\roslyn\csc.exe"

It is an mvc application using visual studio 2017 , targeted framework is 4.6.2.

I just published using webdeploy method. it is successfully deployed but when i try to run i encountered this one like

when i run locally its working fine. But here problem is winhost doesn't allow csc.exe to run which is roslyn compilation.

When we create a web application either webforms or mvc using .net framework 4.5 > then project is pre installed with roslyn csc.exe compilation. although it was successfully published to hosting environment, but some servers doesn't allow to run that roslyn compiler.

Solution 1:

Here solution is just compile and deploy project without any roslyn or any csc.exe files.

just go to Nuget manager, find  the package Microsoft.CodeDom.Provider.DotnetCompilerPlatform , uninstall it.

Now rebuild and re publish, then this problem gone away.

Solution 2:

In some hosting environments we have option to allow or run csc.exe files, just change that setting or allow read/write to exe files, it get's fixed.

Hope it can be useful to some folks.

Tuesday, 5 September 2017

[Solved] Extender Provider failed to return an Extender for this project - Visual Studio Community 2015

Hi.., Recently i encountered visual studio designer exception when i try to open EDM file in visual studio " Extender Provider failed to return an Extender for this project " like this below

Problem is i have been running the application 5 hours plus time, without stopping in local.

Then when i try to view edmx file, encounter this exception.

To stop this exception just reload the project so that all objects gets created again and available to view.

When an application is running idle for hours, it is better to reload that project.

You don't have to delete obj and bin folders. But for different situations it may work. Possibly when this exception encountered while in working in designer mode by simply reloading project, you can remove that exception.

Saturday, 18 February 2017

[Solved] : failed to create component 'Report Viewer' System.runtime.interopservices.COMException(0x8004D745)

Hi there. Recently i encountered this error when i migrated visual studio 2008 windows application to vs 2012 . Here i am dragging  report viewer to control on windows form, then i encountered a long list of error message

Problem is project reference is enabled for version 10.0.0 for report viewer but toolbox is adding version.

Solution: just add the System.ReportViewer.Winforms version remove version.

You will get these kind of designer errors when you migrate to higher version. Just check the references added to project properly.

Hope it helps you.

Wednesday, 21 August 2013

Data Binding with WPF : Binding to XML


In this article i will explain How to bind XML Data to Application UI in WPF. What are the different ways to specify the XML Data to Applicaiton, How to bind the xml elements to UI in wpf etc.

Download SourceCode and Video Explaining How to bind Xml Data to ListBox in WPF 


       In wpf for accessing xml data in your application you can use XmlDataProvider Class. This class provides declarative access to xml data for binding. XmlDataProvider Class provides three ways to access XML Data.

  1. You can embed inline XML Data within the tag inside XmlDataProvider Class.
  2. You can use Source to specify the Uri of the XML file.
  3. You can use Document property to specify the XmlDocument as binding source.
One Important property of XmlDataProvider Class is XPath which defines the level binding source in XML file.

 Embedding Inline XML Data:


If you see the XAML code XML Data is embed with in tag. This XML file has root element as Authors and child element Author with two attributes name and age.

          So for accessing these XML element in ListBox, i specified the itemsource to AuthorNames, XPath=* means it will returns all the data in XML. We can use XPath to query against the XML data
XPath=*[@age>25] will returns the Authors whose age is greater than 25. In this way query against Data.

Accessing XML Data By Setting Source:

             I Have an XML File as Follows:

I am displaying these data in UI as follows
Accessing XML Data Using XmlDataProvider

Here is the XAML Code:

  In this example i am loading main root elements i combobox, based on the combobox selection ListView is loaded with the Model, Based on the selection in ListView then Brand Price details will be shown. 
Watch this Video explaining How to Bind Xml Data to ListBox in WPF


        I hope you got some basic details about accessing xml data in wpf and bind it to UI.

       Don't forget to Comment and share it for our friends if you like this post. Thank You.


Thursday, 15 August 2013

Data Binding in WPF with Example


In this article i will explain

Download SourceCode And Video Explaining Binding in WPF 


Data Binding in WPF:

       One of the WPF Powerful feature is it's Data Binding Concept. It is the process establishing connection between Application User Interface and Business Logic.  It requires a Binding Source and Target .

Data Binding Architecture in WPF
Establishing Binding in WPF

           Source provides the data, and Target displays the data. Data Binding Connects UI to Data. When Source Data values changed then UI is updated. This Updation depends upon the Different types of Data Binding Modes. These Data Binding Decreases the code when compare to general binding. It also enables Template Binding means we customize the data more precisely by specifying which property to bind to which control.

    So a Binding Consists of 4 major Components:
  • Source
  • Source Path
  • Target Depenedency Object.
  • Target Dependency Property.
   Here Target can be any Element or any accessible property that is derived from Dependency Object for example TextBox controls Text Property is an Dependency Property. If you see the object hierarchy in wpf almost all controls are derived from Dependency Object. When coming to Source, it can be any public property, CLR object, Ado.Net DataSet, XMLDataProvider, ObjectDataProvider etc.

wpf binding in diagramatic format explanation
Binding a TextBox Text Property to a TextBlock Text Property

 If you see the above image it gives you clear picture about data binding in wpf. Here Source is a TextBox, Text property of this textbox is bind to TextBlock Text Property. You can see the Code and  output below.

Element as Binding Source Example:

Output is

WPF Simple Binding example
WPF Simple binding

In the above example if you type any text in textbox then immeadiatly it is displayed in TextBlock. Upto now we saw How to bind an element to another element, Now Let's see how to bind properties to XAML elements.

   Now add a class to your project and name that as MobileShop which consists of three properties ShopOwner, Shop Number, and Address as below

Now add a new window to your project and drag three textboxes ,three labels for displaying above three properties. XAML code looks like below.

Now in the Constructor of the Window write below code

As you may see that we have created an instance of class MobileShop and assigned the data for properties.
After that we assigned the object to DataContext Property of the Window. Here DataContext will hold the Data. This property exist for almost all controls that derived from Dependency Object i.e Panel Controls like Grid, Canvas, StackPanel, Wrappanel, Content Controls like Label, Button  etc. If we set our object as DataContext to a higher level control then all child controls can inherit that object. Read More About DataContext in WPF.

      So now in our present example we set object as DataContext for window parent control  so all the child controls have default data source, so we don't need to set Source we just need to mention the Path to which it binds. So in our example we only mentioned Path as below.

The same example can also be done without writing single peace of line code in code behind file, by writing only XAML code as below

Here first we have to set the namespace reference to access class files in the same project. i.e


Now we can access all contents in the project using local reference like below.

Binding in Code behind file:

 We can also perform data binding in code file. 
  • Create the Binding Object
  • Set the Binding Source
  • Set the path
  • Bind the object to Target using SetBinding Method.
Here is an example on how to perform binding in code behind file.

Binding Modes in WPF:

       Mode is the one property of the binding element which determines the flow of data between binding source and target. Four Binding Modes available.
  1. OneWay.
  2. OneTime.
  3. OneWayToSource.
  4. TwoWay.
OneWay:  If Mode is OneWay means Data flows from source to target whenever source is changed.

OneWay Binding Mode Image
OneWay Binding Mode
Here Target UI will be updated only if the source changed. Use this to display read only data in the UI.

OneTime:  If the Mode is OneTime then data flows from source to target when application starts or datacontext changes.
OneTime Binding Mode
OneTime Binding Mode
   You can use this to show read only data. This can be used to compare the changes occurred in UI. This Mode very useful source doesn't implement INotifyPropertyChanged Interface.

OneWayToSource: This is completely opposite to OneWay mode. In this Mode if target UI value is changed by user then it is updated in the source if the source is dependency property or it is implemented by INotifyPropertyChanged Interface.
OneWayToSource Binding
OneWayToSource Binding Mode
   In this case target is not updated if source is updated because of changes occurred in target.

TwoWay:  If the Mode is TwoWay then Whenever the Source is updated then target is updated, in the same manner if the target value is changed by user then Source is updated with target value and If the binding Source is bind to multiple targets  then all the targets are updated with Source data.

TwoWay Binding Example
TwoWay Binding Mode
          Use this Mode when User can change binding source and all it's targets.
For Understanding Binding Modes  briefly read this Binding Modes in WPF with example

 We have seen Binding Source is updated in OneWayToSource and TwoWay Binding Modes. More Precisely we can control the binding source updation by using UpdateSourceTrigger.

UpdateSourceTrigger in WPF:

          UpdateSourceTrigger is one of the property of Binding class. This Property defines the timing of binding source updation. This Property has three Options available. These are  LostFocus, PropertyChanged, Explicit. 

                Suppose you bind a property to a textbox, then if UpdateSourceTrigger is set to LostFocus then all the changes occurred in the textbox is updated in the source when TextBox Lost focus. If UpdateSourceTrigger is set to PropertyChanged then binding source is updated for every change in target. and if the UpdateSourceTrigger is Explicit then binding source is updated only when we explicitly called UpdateSource ( ) method.


               I hope now you will able to work with wpf bindings. Download the Source Code and watch the Video about Bindings in WPF. Let me know if you need any clarification.

             Don't forget to Comment and share for our friends if you like this post.