Showing posts with label VB. Show all posts
Showing posts with label VB. Show all posts

Friday, November 14, 2008

Error: ASPX page has not been pre-compiled, and cannot be requested

Sometime we find that our web site was working perfectly on our development machine but start displaying error “ Error: ASPX page has not been pre-compiled, and cannot be requested” in many of forums I foud many of our peers are still struggling with same issue.

The simple workaround for that I have found is :

1. If you are using any 3rd party component , remove them from web.config, then using Add Reference add all reference to them again.
2. Instead of setting the WDP's Output Assemblies property to “Merge all outputs to a single assembly” and deploy, use Publish Web Site under the Build menu.
3. Check the "Allow this precompiled site to be updatable" check box in the Publish Web Site options of Visual Studio 05, and deploy.
4. make sure you uploaded all the required assemblies. If anyone is missing upload that manually.

Hope this information will be helpful to my peer community.

Monday, September 15, 2008

General network error. Check your network documentation.

There is a lot of people out there complaining about SQL Server returning a General network error while executing a command form ADO.NET version 1.1 or 1.0. Since it is a General network error, it seems to me that there are as many reasons for this error as there are people having it. one fine day I too experienced the same so I googled it but saveral posts in several blogs leads to various solutions like append max pool size = 7500, to your connection string will solve the issue or setting the command timeout to anything but zero totally fixes it.

I tried all of them but still i experienced the same error intermittently. Finally i found that The calling asp.net page creates an ojbect which opens the connection over and over and relies on the destruct method of the database object to do the closing so I am assuming our problem is related to this but I have not been able to reproduce it reliably so I can't be sure this is the cause of the problem.

then i found this microsoft KB article

it says that In the current design, after an application role is enabled on a client connection to SQL Server, you cannot reset the security context of that connection. Therefore, when the user ends the SQL Server session and disconnects from the server, the session is not reusable. However, OLE DB resource pooling returns the closed connection to the pool, and the error occurs when that connection is reused and the client application tries to reset the connection's security context by calling sp_setapprole again.

WORKAROUND

The only available workaround is to disable OLE DB Resource Pooling, which ADO uses by default. You can do this by adding "OLE DB Services = -2" to the ADO Connection string, as shown here: 'For SQLOLEDB provider
'strConnect = "Provider=SQLOLEDB;server=SQL7Web;OLE DB Services = -2;uid=AppUser;pwd=AppUser;initial catalog=northwind"

' For MSDASQL provider
'strConnect = "DSN=SQLNWind;UID=Test;PWD=Test; OLE DB Services= -2"


Pooling can be disabled for the SQL Server .Net Data Provider by adding "Pooling=False" to the connection string.

although that solves my issue but what if the connection pooling is needed ????

Wednesday, July 2, 2008

What is equivalent for regsvr32 exe in .NET?

Regasm

What are types of compatibility inVB6?

There are three possible project compatibility settings: - No compatibility - Project compatibility - Binary compatibility No Compatibility With this setting, new class ID’s, new interface ID’s and a new type library ID will be generated by VB each time the ActiveX component project is compiled. This will cause any compiled client components to fail(with error 429!) and report a missing reference to the `VB ActiveX Test component’ when a client project is loaded in the VB IDE. Note: Use this setting to compile the initial release of a component to other developers. Project Compatibility With this setting, VB will generate new interface ID’s for classes whose interfaces have changed, but will not change the class ID’s or the type library ID. This will still cause any compiled client components to fail(with error 429!)but will not report a missing reference to the `VB ActiveX Test component’ when a client project is loaded in the VB IDE. Recompilation of client components will restore them to working order again. Note: Use this setting during the initial development and testing of a component within the IDE and before the component is released to other developers. Binary Compatibility VB makes it possible to extend an existing class or interface by adding new methods and properties etc. And yet still retain binary compatibility. It can do this, because it silently creates a new interface ID for the extended interface and adds registration code to register the original interface ID but with a new forward key containing the value of the new interface ID.COM will then substitute calls having the old ID with the new ID and hence applications built against the old interface will continue to work(assuming the inner workings of the component remain backward compatible!). With this settings, VB will not change any of the existing class, interface or type library ID’s, however in order that it can do so, VB requires the project to specify an existing compiled version that it can compare against to ensure that existing interfaces have not been broken.

How do you do object pooling in .NET?

COM+ reduces overhead by creating object from scratch. So in COM+ when object is activated from its pool and when it’s deactivated it’s pushed back to the pool. Objects pooling is configured by using the “ObjectPoolingAttribute” to the class.

How to implement DTC in .NET?

DTC is implemented using COM+. Following are the steps to implement COM+ in .NET: - “EnterpriseService” namespace has all the classes by which we can implement DTC in .NET. You have to add reference “EnterpriseService” namespace. - Your class must derive from “Service Component” object. - Then you have to define your class with the transaction attribute - After the class level transaction type is defined, its time to define at the method level the AutoComplete attribute. AutoComplete attribute says that if no exception is thrown then mark its part of the transaction as being okay. This helps cut down on the amount of code required. If the implementation sets AutoComplete to false, or omits it all together, then we would need to manage the transaction manually. To manually control the transaction you will need to use the ContextUtil class and its static members.

Can you describe IUKNOWN interface in short?

Every COM object supports at least one interface, the IUnknown interface. All interfaces are classes derived from the base class IUnknown. Each interface supports methods access data and performs operations transparently to the programmer. For example, IUnknown supports three methods, AddRef, Release (), and QueryInterface(). Suppose that printerf is a pointer to an IUnknown. Printerf->;AddRef() increments the reference count. Printerf->;Release() decrements the reference count, deleting the object when the reference count reaches zero. Printerf->;QueryInterface(IDesired, pDesired) checks to see if the current interface (IUnknown) supports snother interface, IDesired, creates an instance (via a call to CoCreateInstance()) of the object if the reference count is zero (the object does not yet exist), and then calls pDesired->;AddRef() to increment the reference count (where pDesired is a pointer to IDesired) and returns the pointer to the caller.

How can we use COM Components in .NET? Twist: What is RCW?

Dot NET components communicate with COM using RCW (Runtime Callable Wrapper). Following are the ways with which you can generate RCW: -Adding reference in Visual Studio.net -Using Type library import tool. Tlbimp.exe yourname.dll -Using interopservices.System.runtime. Interopservices namespace contains class TypeLib Converter which provides methods to convert COM classes and interface in to assembly metadata. -Make your custom wrappers. If your COM component does not have type library then the only way to communicate is writing custom wrappers. That means communicating directly with COM components.

What is CODE Access security?

To help protect computer systems from malicious mobile code, to allow code from unknown origins to run with protection, and to help prevent trusted code from intentionally or accidentally compromising security, the .NET Framework provides a security mechanism called code access security. Code access security allows code to be trusted to varying degrees depending on where the code originates and on other aspects of the code's identity. Code access security also enforces the varying levels of trust on code, which minimizes the amount of code that must be fully trusted in order to run. Using code access security can reduce the likelihood that your code can be misused by malicious or error-filled code. It can reduce your liability because you can specify the set of operations your code should be allowed to perform as well as the operations your code should never be allowed to perform. Code access security can also help minimize the damage that can result from security vulnerabilities in your code.

All managed code that targets the common language runtime receives the benefits of code access security, even if that code does not make a single code access security call.

What'is difference between System exceptions and Application exceptions?

From the System.SystemException documentation:

This class is provided as a means to differentiate between exceptions defined by the system versus exceptions defined by applications.

So, consider it the opposite of ApplicationException. All Exceptions that are defined by the .NET Framework inherit from SystemException. All Exceptions that are defined by code that you write should derive from ApplicationException. Exception is the root class of ALL exceptions.

Friday, June 27, 2008

What is the difference between VB.NET and C# ?

Well this is the most debatable issue in .NET community and people treat these languages like religion. It’s a subjective matter which language is best. Some like VB.NET’s natural style and some like professional and terse C# syntaxes. Both use the same framework and speed is also very much equivalents.
But still let’s list down some major differences between them
:-Advantages VB.NET :-Has support for optional parameters which makes COM interoperability much easy. With Option Strict off late binding is supported. Legacy VB functionalities can be used by using Microsoft.VisualBasic namespace. Has the WITH construct which is not in C#. The VB.NET part of Visual Studio .NET compiles your code in the background. While this is considered an advantage for small projects, people creating very large projects have found that the IDE slows down considerably as the project gets larger. Advantages of C# XML documentation is generated from source code but this is now been incorporated in Whidbey. Operator overloading which is not in current VB.NET but is been introduced in Whidbey. Use of this statement makes unmanaged resource disposal simple. Access to Unsafe code. This allows pointer arithmetic etc, and can improve performance in some situations. However, it is not to be used lightly, as a lot of the normal safety of C# is lost (as the name implies).
This is the major difference that you can access unmanaged code in C# and not in VB.NET.

What is concept of Boxing and Unboxing ?

Boxing permits any value type to be implicitly converted to type object or to any interface type implemented by value type. Boxing is a process in which object instances are created and copy values in to that instance. Unboxing is vice versa of boxing operation where the value is copied from the instance in to appropriate storage location. Below is sample code of boxing and unboxing where integer data type is converted in to object and then vice versa.

Dim x As IntegerDim y As Object x = 10‘ boxing process y = x‘ unboxing process x = y

What are Value types and Reference types ?

Value types directly contain their data which are either allocated on the stack or allocated in-line in a structure. Reference types store a reference to the value's memory address, and are allocated on the heap. Reference types can be self-describing types, pointer types, or interface types. Variables that are value types each have their own copy of the data, and therefore operations on one variable do not affect other variables. Variables that are reference types can refer to the same object; therefore, operations on one variable can affect the same object referred to by another variable. All types are derived from the System.Object base type.

What is reflection?

All .NET assemblies have metadata information stored about the types defined in modules. This metadata information can be accessed by mechanism called as “Reflection”. System. Reflection can be used to browse through the metadata information. Using reflection you can also dynamically invoke methods using System.Type.Invokemember.

Can we force garbage collector to run ?

System.GC.Collect() forces garbage collector to run. This is not recommended but can be used if situations arises.

What is garbage collection?

Garbage collection is a CLR feature which automatically manages memory.
Programmers usually forget to release the objects while coding ..... Laziness (Remember in VB6 where one of the good practices is to set object to nothing).
CLR automatically releases objects when they are no longer inuse and refernced.
CLR runs on non-deterministic to see the unused objects and cleans them. One side effect of this non-deterministic feature is that we cannot assume an object is destroyed when it goes out of the scope of a function. we should avoid using destructors because before GCdestroys the object it first executes destructor in that case it will have to wait for code to release the umanaged resource. resultin in additional delays in GC.
So its recommended to implement IDisposable interface and write cleanup code in Dispose method and call GC.SuppressFinalizemethod so instructing GC not to call your constructor.

What is Delay signing ?

During development process you will need strong name keys to be exposed to developer which is not a good practice from security aspect point of view. In such situations you can assign the key later on and during development you can use delay signing
Following is process to delay sign an assembly:

First obtain your string name keys using SN.EXE. Annotate the source code for the assembly with two custom attributes from System.Reflection: AssemblyKeyFileAttribute, which passes the name of the file containing the public key as a parameter to its constructor. AssemblyDelaySignAttribute, which indicates that delay signing, is being used by passing true as a parameter to its constructor. For example as shown below:[Visual Basic] [C#] [assembly:AssemblyKeyFileAttribute("myKey.snk")] [assembly:AssemblyDelaySignAttribute(true)]The compiler inserts the public key into the assembly manifest and reserves space in the PE file forthe full strong name signature. The real public key must be stored while the assembly is built so that other assemblies that reference this assembly can obtain the key to store in their own assemblyreference. Because the assembly does not have a valid strong name signature, the verification ofthat signature must be turned off. You can do this by using the –r option with the Strong Name tool. The following example turns off verification for an assembly called myAssembly.dll.Sn –r myAssembly.dll80vJust before shipping, you submit the assembly to your organization's signing authority for the actual strong name signing using the –R option with the Strong Name tool. The following example signs an assembly called myAssembly.dll with a strong name usingthe sgKey.snk key pair.

Sn -R myAssembly.dll sgKey.snk

What is concept of strong names (Twist :- How do we generate strong names or what is the process of generating strong names , What is use of SN.EXE , How do we apply strong names to assembly ?

Strong name is similar to GUID(It is supposed to be unique in space and time) in COM components. Strong Name is only needed when we need to deploy assembly in GAC. Strong Names helps GAC to differentiate between two versions. Strong names use public key cryptography (PKC) to ensure that no one can spoof it. PKC use public key and private key concept. Following are the step to generate a strong name and sign a assembly :-

Go to “Visual Studio Command Prompt”. See below figure “Visual studio Command Prompt”. Note the samples are compiled in 2005 but 2003 users do not have to worry about it. Same type of command prompt will be seen in2003 also.

After you are in command prompt type sn.exe -k “c:\test.snk”.

After generation of the file you can view the SNK file in a simple notepad.

After the SNK file is generated it’s time to sign the project with this SNK file

Click on project -- properties and the browse the SNK file to the respective folder and compile the project.

Click on Use a key file to sign the assembly with strong name. and that’s it.

What is GAC (Twist :- What are situations when you register .NET assembly in GAC ?) ?

GAC (Global Assembly Cache) is used where shared .NET assembly reside. GAC is used in the following situations :-

· If the application has to be shared among several application.

· If the assembly has some special security requirements like only administrator scan remove the assembly. If the assembly is private then a simple delete of assembly the assembly file will remove the assembly. Note :- Registering .NET assembly in GAC can lead to the old problem of DLL hell, where COM version was stored in central registry. So GAC should be used when absolutely necessary.

what is Manifest? what is strongname?

An assembly manifest contains all the metadata needed to specify the assembly's version requirements and security identity, and all metadata needed to define the scope of the assembly and resolve references to resources and classes. The assembly manifest can be stored in either a PE (Portable Executable) file (an .exe or .dll) with Microsoft intermediate language (MSIL) code or in a standalone PE (Portable Executable) file that contains only assembly manifest information.

The following table shows the information contained in the assembly manifest. The first four items — the assembly name, version number, culture, and strong name information — make up the assembly's identity.

Assembly name: A text string specifying the assembly's name.

Version number: A major and minor version number, and a revision and build number. The common language runtime uses these numbers to enforce version policy.

Culture: Information on the culture or language the assembly supports. This information should be used only to designate an assembly as a satellite assembly containing culture- or language-specific information. (An assembly with culture information is automatically assumed to be a satellite assembly.)

Strong name information: The public key from the publisher if the assembly has been given a strong name.

List of all files in the assembly: A hash of each file contained in the assembly and a file name. Note that all files that make up the assembly must be in the same directory as the file containing the assembly manifest.

Type reference information: Information used by the runtime to map a type reference to the file that contains its declaration and implementation. This is used for types that are exported from the assembly.

Information on referenced assemblies: A list of other assemblies that are statically referenced by the assembly. Each reference includes the dependent assembly's name, assembly metadata (version, culture, operating system, and so on), and public key, if the assembly is strong named.