Interview Tips Interview Tips, Interview Questions and Answers

5Oct/110

Configure MySql .Net Connector with Entity Framework

To communicate from .NET code to MySQL database using Entity Framework we installed MySql .NET Connector. It worked fine out of the box on developer's workstations but once deployed to hosted web server application started to throw following error:

[NotSupportedException: Unable to determine the provider name for connection of type 'MySql.Data.MySqlClient.MySqlConnection'.] System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInvariantName(DbConnection connection)
System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest)
System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
System.Data.Entity.DbSet`1.Add(TEntity entity)

Apparently, somehow MySQL .NET provider was not registered on server although installation was done properly and all assemblies were present in GAC. Since on shared hosting we did not have access to machine.config by adding the same registration entry to the application web.config file resolved the issue:

 

 <system.data>
    <DbProviderFactories>
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.4.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
    </DbProviderFactories>
  </system.data>

Important: 1) Make sure to register the same version that is installed on the server 2) Provide precise fully qualified name in the type attribute. For example, adding extra space between MySql.Data.MySqlClient.MySqlClientFactory and MySql.Data will make this entry useless and will result in the same error

1Oct/110

Code Issues specific to partial methods

There are several conditions that are applied to partial methods, such as:

    Partial methods must be void
    Signatures of both parts of partial methods must match
    Access modifiers are not allowed for partial methods
    Partial methods must be declared in partial classes
    etc

You don’t have to remember all these conditions if you have the CodeRush code issues feature turned on. When the rule of the partial method declaration is violated, code issues will show you an error or a hint, and you can fix it before you compile the code. These code issues are:
Partial method cannot have access modifiers or the virtual, abstract, override, new, sealed, or extern modifiers

If a partial method has an invalid modifier (e.g., virtual, abstract, override, new, sealed, extern, or an access modifier) you will see an error in the code editor, because partial methods cannot have these type of modifiers:
CodeRush Partial method cannot have modifiers
CodeRush Partial method cannot have access modifiers
Partial method cannot have out parameters

Out parameters are not allowed for partial methods. If a partial method is declared with ‘out’ parameters, you will see an error:

CodeRush Partial method cannot have out parameters
Partial method must be declared within a partial class or partial struct

Partial methods can only reside inside a partial class or a partial structure, otherwise, an error is shown:

CodeRush Partial method must be declared within a partial class
Partial method has only single part

When the partial method has only a single part without a declaration, it does not need to be declared as partial. This code issue has a hint type:

CodeRush Partial method has only single part
13Sep/110

Filtering Data in Web Forms Model Binding

To enable filtering, we’ll update our GetProducts() method to take a keyword parameter like below:

public IQueryable<Product> GetProducts([QueryString]string keyword)

{

    IQueryable<Product> query = db.Products;

 

    if (!String.IsNullOrWhiteSpace(keyword))

    {

        query = query.Where(p => p.ProductName.Contains(keyword));

    }

 

    return query;

}

If the keyword is empty or null, then the method returns all of the products in the database.  If a keyword is specified then we further filter the query results to only include those product’s whose names contain the keyword.

Understanding Value Providers

One of the things you might have noticed with the code above is the [QueryString] attribute that we’ve applied to the keyword method argument.  This instructs the Model Binding system to attempt to “bind” a value from the query string to this parameter at runtime, including doing any type conversion required.

These sources of user values are called “Value Providers”, and the parameter attributes used to instruct the Model Binding system which Value Provider to use are called “Value Provider Attributes”. The next version of Web Forms will ship with value providers and corresponding attributes for all the common sources of user input in a Web Forms application, e.g. query string, cookies, form values, controls, viewstate, session and profile. You can also write your own custom value providers.  The value providers you write can be authored to work in both Web Forms and MVC.

By default, the parameter name will be used as the key in the value provider collection, so in this case, a value will be looked for in the query string with the key “keyword”, e.g. ~/Products.aspx?keyword=chef. This can be easily overridden by passing the desired key in as an argument to the parameter attribute. In our example, we might like the user to be able to use the common “q” query string key for specifying the keyword:

public IQueryable<Product> GetProducts([QueryString("q")]string keyword)

2Sep/110

WPF interview questions

Entry Level

Property Change NOtification (INotifyPropertyChange and ObservableCollection)
ResourceDictionary
UserControls

Mid Level

Blend/Cider
animations and storyboarding
ClickOnce Deployment

Senior

WPF 3D
Differences between Silverlight 2 and WPF
MVVM/MVP
WPF Performance tuning
Pixel Shaders

Entry Level

  • Property Change NOtification (INotifyPropertyChange and ObservableCollection)
  • ResourceDictionary
  • UserControls

Mid Level

  • Blend/Cider
  • animations and storyboarding
  • ClickOnce Deployment

Senior

  • WPF 3D
  • Differences between Silverlight 2 and WPF
  • MVVM/MVP
  • WPF Performance tuning
  • Pixel Shaders
link|improve this answer
29Aug/110

When should I use WPF instead of DirectX?

DirectX is definitely not dead and is still more appropriate than WPF for advanced developers writing hard-core “twitch games” or applications with complex 3D models where you need maximum performance. That said, it’s easy to write a naive DirectX application that performs far worse than a similar WPF application. DirectX is a low-level interface to the graphics hardware that exposes all of the quirks of whatever GPU a particular computer has. DirectX can be thought of as assembly language in the world of graphics: You can do anything the GPU supports. WPF provides a high-level abstraction that takes a description of your scene and figures out the best way to render it, given the hardware resources available. Internally, this might involve using Shader Model 3.0, or the fixed-function pipeline, or software. (Don’t worry if you’re not familiar with these terms, but take it as a sign that you should be using WPF!). The downside of choosing DirectX over WPF is a potentially astronomical increase in development cost. A large part of this cost is the requirement to test your application on each driver/GPU combination you intend to support. One of the major benefits of building on top of WPF is that Microsoft has already done this testing for you! You can instead focus your testing on low-end hardware for measuring performance. The fact that WPF applications can even leverage the client GPU over Remote Desktop or in a partial-trust environment is also a compelling differentiator.

25Aug/110

What is XAML?

  • It is Declarative Markup Language.
  • It simplifies creating a UI for a .NET Framework application.
  • It can create visible UI elements in XAML , and then separate the UI definition from the run-time logic by using code-behind files. This joined to the markup through partial class definitions. XAML represents the instantiation of objects in a special set of backing types defined in assemblies.
  • It enables a workflow where separate parties can work on the UI and the logic of an application, using different tools. ex: Expression Blend and Visual Studio
  • It is Visual designer to create User friendly UI
  • XAML is not dependent on WPF or WPF is not dependent on XAML. WPF Designed to be XAML Friendly
15Aug/110

What is WPF ? Why it is used?

WPF is Object Oriented , XAML based.

  • It Uses DirectX Engine for rendering GUI
  • It do not use GDI 32 programming at all as opposed to Win32 applications
  • It do not require more time or cost for graphics, drawing or animation programming
  • It is Easy to change resolution unlike win32 application
  • It is XAML Friendly.
  • It has .NET API that has integrated to XAML (Xtensible Application Markup Language)
  • Easily select the Controls unlike Win32 Controls.
  • It has the ability to create 3D graphics in windows apps
  • It contains Separate API for graphics and animation
  • Most powerful Windows UI Framework

It is used for the

  • For the better User Interface & the  Design
  • Customization of Controls
  • Integrating Flash, Direct, Win32, Windows Forms
  • For Generic consistency professional look (Using Styles like CSS in Web)
12Aug/110

Mid-level WPF interview questions

Routed Events & Commands
Converters - Added by Artur Carvalho
Explain WPF's 2-pass layout engine?
How to implement a panel?
Interoperability (WPF/WinForms)
Blend/Cider - Added by a7an
Animations and Storyboarding
ClickOnce Deployment
Skinning/Themeing
Custom Controls
How can worker threads update the UI?
DataTemplate vs HierarchicalDataTemplate
ItemsControl vs ItemsPresenter vs ContentControl vs ContentPresenter
Different types of Triggers