Friday, June 15, 2012

The referenced assembly could not be resolved because it has a dependency on "System.Data.OracleClient, Version=4.0.0.0

One of my friend was having trouble in compiling the application.  He saw the following warning message in Visual Studio. Since he was accessing the SQL server he neglected it. He didn't reference Oracle from any of his projects in the solution. He emailed me the solution , I checked the code and dint find anything wrong there.


The referenced assembly could not be resolved because it has a dependency on "System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project




Solution:


Change the application Framework Target from .Net Framework Client Profile to Main

Root Cause:
.NET Framework 4 Client Profile does not include .NET Framework Data Provider for Oracle. Since Microsoft.Practices.EnterpriseLibrary.Data has a reference to System.Data.OracleClient this error is thrown.

Sunday, June 3, 2012

Asp.net set theme : Theme vs. StyleSheetheme

You can set the theme of an asp.net page using the StylesheetTheme or Theme property

What is the difference between two?
If you use the StyleSheetTheme attribute, settings can be overridden because properties defined by StyleSheetTheme are applied before a page’s control property set. If you use the Theme attribute, settings cannot be overridden because properties defined by Theme are applied after a page’s properties.


If you provide both the properties, aspnet takes the value specified in "theme" property.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" StylesheetTheme="black" Theme="red" %>

Copy Local Property of a Reference

The Copy Local property of the reference is tricky. I was expecting once i set this property to true it will automatically copy all the related dlls to the build path. But unfortunately this is not the case. All the assemlies are not copied.

From  MSDN (http://msdn.microsoft.com/en-us/library/ez524kew%28VS.80%29.aspx)
At run time, components must be either in the output path of the project or in the Global Assembly Cache (GAC). If the project contains a reference to an object that is not in one of these locations, you must copy the reference to the output path of the project when you build the project. The CopyLocal property indicates whether this copy needs to be made. If the value is True, the reference is copied to the project directory when you build the project. If False, the reference is not copied.

If you deploy an application that contains a reference to a custom component that is registered in the GAC, the component will not be deployed with the application, regardless of the CopyLocal setting. In previous versions of Visual Studio, you could set the CopyLocal property on a reference to ensure that the assembly was deployed. Now, you must manually add the assembly to the \Bin folder. This puts all custom code under scrutiny, reducing the risk of publishing custom code with which you are not familiar.
By default, the CopyLocal property is set to False if the assembly or component is in the global assembly cache or is a framework component. Otherwise, the value is set to True. Project-to-project references are always set to True.

ASP.net Special folders

Asp.net/visual studio has some special folders which has its own functions. We shouldnt be creating these folders for any other purpose.

  • App_Browsers: Contains custom browser definition files (.browser files) that ASP.NET uses to identify browsers and determine their capabilities. The .NET Framework includes a standard set of browser definition files in <windir>\Microsoft.NET\Framework\<ver>\CONFIG\Browsers.
  • App_Code: Contains source code for classes (.cs, .vb, and .jsl files) that the developer intends to compile as part of the application.
  • App_Global- Resources: Contains resources (.resx and .resources files) that are compiled into satellite assemblies and have a global scope. Resource files are used to externalize text and images from your application code. This helps you support multiple languages and design-time changes without recompilation of source code.
  • App_Local-Resources: Contains resources (.resx and .resources files) that are scoped to a specific page, user control, or master page in an application.
  • App_Themes: Contains subfolders, each of which defines a specific theme (or look) for your site. A theme consists of files (such as .skin, .css, and image files) that define the appearance of webpages and controls.
  • App_Web-References:Contains web reference files (.wsdl, .xsd, .disco, and .discomap files) that define references to web services.
  • Bin: Contains compiled assemblies (.dll files) for code that the application requires to execute. Assemblies in the Bin folder are automatically referenced in your application.
These folders are protected by ASP.NET. If users attempt to browse
to any of these folders (except App_Themes), they will receive an HTTP 403 Forbidden error.

Common HTTP/1.1 Methods

  • GET -  Gets an object, such as a webpage, from the server. A GET request for a specific URL (Uniform Resource Locator) retrieves the resource.
  • POST - Sends data to the web server for processing. This is typically what happens when users enter data on a form and submit that data as part of their request, but it has other meanings when used outside the bounds of HTML forms.
  • HEAD - Retrieves the meta information for an object without downloading the page itself. HEAD is typically used to verify that a resource hasn’t changed since the browser cached it.
  • OPTIONS - Used by client applications to request a list of all supported commands. You can use OPTIONS to check to see if a server allows a particular command
  • PUT -Allows a client to directly create a resource at the indicated URL on the server. If the user has permission, the server takes the body of the request, creates the file specified in the URL, and copies the received data to the newly created file.
  • DELETE - Deletes a resource on the web server if the user has permission.
  • TRACE - Used for testing or diagnostics; allows the client to see what is being received at the other end of the request chain
  • CONNECT - Reserved for use with a proxy that can dynamically switch to being a tunnel, such as with the SSL protocol.
  • DEBUG  - Starts ASP.NET debugging. This command informs Visual Studio of the process to which the debugger will attach

DatabaseFactory.CreateDatabase error- Object synchronization method was called from an unsynchronized block of code.

Yesterday one of my friends called me and said that he was getting an unusual exception form one of the projects which I had created long back. The only change he made was to add the latest Microsoft.Practices.EnterpriseLibrary  library 5.0.414.0

The error was 
 Object synchronization method was called from an unsynchronized block of code.

The error observed was at the following line

Database db = DatabaseFactory.CreateDatabase(_conStringName);

This was a code which was runninig successfully foer years. Initially I suepected trhat my firend had accidentyly made some mistake but when I reviewed the code I didn’t see much changes. I quickly made the following changes in the code &amp; it worked !!!
SqlDatabase db = new SqlDatabase(_conStringName);

I think Microsoft should be more careful in making such changes which affect the existing runninig code. 

HTTP header status codes


The status code available in the http header are usefull. Following are some of the common status codes


Status Code GroupDescription
1xx InformationalThe request was received, and the server is continuing to process.
2xx SuccessThe action was successfully received, understood, and accepted.
3xx Redirect CommandThe client must access a different resource instead.
4xx Client ErrorThe request has a syntax error or the server does not know how to fulfill the request.
5xx Server Errorhe server failed to fulfill a request that appears to be valid.



Status CodeDescription
100 Continue
200OK
201Created
300Multiple Choices
301Moved Permanently
302Found
400Bad Request
401Unauthorized
403Forbidden
404Not Found
407 Proxy Authentication Required
408Request Time-out
413Request Entity Too Large
500Internal Server Error
501Not Implemented

Improvements in ASP.net 4 with Visual Studio 2010



• Simplified deployment of applications, settings, and data.


• Easy redirection of search engine–friendly URLs to different pages.

• Cascading style sheet–friendly rendering for many controls.

• Applications that start up before the first user request.

• Extensible request validation for more flexible security.

• Easy setting of meta tags at run time.

• The ability to enable view state for individual controls to reduce page sizes.

• Static client IDs to allow web server controls to be reliably accessed from JavaScript.

• The inclusion of AJAX jQuery scripts in Visual Studio templates.

• Improved Language-Integrated Query (LINQ) capabilities for creation of strongly

• typed queries for collections and databases.

• Dynamic Data templates for rapid development of data-driven websites.

• Compressed session state data.

• A new Chart control for quick creation of interactive three-dimensional charts.

• Built-in ASP.NET MVC 2 for creation of layered applications that are easily testable.