Aug 282014
 
What’s DEVPATH

Being a .net developer you might have wondered if at all there is a way to tell .net assembly binding and loading mechanism (fusion) to look for your assemblies in your shared assembly folder as well. This will be really helpful if your assembly is used with multiple applications so that if they fail to locate an assembly in the appbase or privatepath’s then they start looking for it in your ‘bin’ folder. This prevents you from frequently installing and uninstalling the assembly to GAC for testing purpose.

This is exactly what DEVPATH environment variable does.

How to set DEVPATH

Following example shows you how to setup just need to set assembly look up path to this variable. For e.g.

set DEVPATH=”c:\sharedassemblies\”

To enable DEVPATH look up you’ll also need to modify machine.config file, in my case its located here: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config

<configuration>

<runtime>
<developmentMode developerInstallation=”true”/>
</runtime>

</configuration>

Verify DEVPATH is used

So next time when application runs and starts looking for your assembly it will for sure look in the above path. If fusion logger is enabled and if you open the log file for your assembly you should see something like this…

===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\myapp.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Found assembly in DEVOVERRIDE path C:\sharedassemblies\Test.DLL

Recently had a customer who asked this question and this looks like to have helped them so thought of sharing this out with you folks as well.

Watch outs
  1. Please be very aware that you’ve set this feature on. You could end up having erratic behavior if somehow DEVPATH has a path containing unsupported path chars like parentheses or if DEVPATH is set to empty.
  2. Please only use this feature in development environments as this feature by passes all normal assembly lookup features as fusion looks up DEVPATH first if enabled.
  3. Please note fusion will look up DEVPATH as if its an AppBase folder so be aware that it will look up subdirectories as well in this DEVPATH. Also all valid assembly name look ups will be done, for e.g. .dll, .exe etc.
Aug 052014
 

Do you run into following error when trying to run a VS2013 .net application on Windows XP?

Error: Not a valid Win32 application!

This happens because the application is targeting .net framework 4.5 which is not supported on Windows XP. Target a lower framework to get your application working on XP.

Aug 052014
 

What are DateTime Custom Formatters?

A date and time format string defines the text representation of a DateTime or DateTimeOffset value that results from a formatting operation . It can also define the representation of a date and time value that is required in a parsing operation in order to successfully convert the string to a date and time. A custom format string consists of one or more custom date and time format specifiers. Any string that is not a standard date and time format string is interpreted as a custom date and time format string.

Custom date and time format strings can be used with both DateTime and DateTimeOffset values.

Issue with DateTime Custom Formatters?

Recently a customer opened a ticket thinking that there is an issue with the DateTime Custom Formatters. They had following piece of code.

namespace DateTimeDefect
{
 class Test
 {
   static void Main(string[] args)
   {
     DateTime dt = DateTime.Now;

     Console.WriteLine(dt.ToString("f"));
     Console.WriteLine(dt.ToString("ff"));
     Console.WriteLine(dt.ToString("fff"));

     Console.ReadLine();
   }
 }
}

Except for dt.ToString(“f”) the other two ToString calls were returning correct results. Here’s the output…

Friday, May 30, 2014 12:53 AM (Here’s the issue, customer expects a numeric value as shown below)
53
534

Here’s what MSDN says about custom formatter ‘f’, ‘ff’, ‘fff’.

“f”: The tenths of a second in a date and time value. More information: The “f” Custom Format Specifier.

Sample:
6/15/2009 13:45:30.617 -> 6
6/15/2009 13:45:30.050 -> 0

“ff”: The hundredths of a second in a date and time value. More information: The “ff” Custom Format Specifier.

Sample:
6/15/2009 13:45:30.617 -> 61
6/15/2009 13:45:30.005 -> 00

“fff”: The milliseconds in a date and time value. More information: The “fff” Custom Format Specifier.

Sample:
6/15/2009 13:45:30.617 -> 617
6/15/2009 13:45:30.0005 –> 000

 So what’s going wrong here with DateTime Custom Formatters

The issue here is that dt.ToString(“f”) is not recognized as a custom format specifier. Please read below documentation from MSDN…

A custom date and time format string consists of two or more characters. Date and time formatting methods interpret any single-character string as a standard date and time format string. If they do not recognize the character as a valid format specifier, they throw a FormatException. For example, a format string that consists only of the specifier “h” is interpreted as a standard date and time format string. However, in this particular case, an exception is thrown because there is no “h” standard date and time format specifier.

To use any of the custom date and time format specifiers as the only specifier in a format string (that is, to use the “d”, “f”, “F”, “g”, “h”, “H”, “K”, “m”, “M”, “s”, “t”, “y”, “z”, “:”, or “/” custom format specifier by itself), include a space before or after the specifier, or include a percent (“%”) format specifier before the single custom date and time specifier.

For example, “%h” is interpreted as a custom date and time format string that displays the hour represented by the current date and time value. You can also use the ” h” or “h ” format string, although this includes a space in the result string along with the hour. The following example illustrates these three format strings.

Resolution

So in this case the date time formatting method is interpreting this single character string as a standard date and time format string. To work around this, following are the options that you have…

1. Use dt.ToString(“%f”)
2. Use dt.ToString(“ f”);// add a space before ‘f’
3. Use dt.ToString(“f ”);// add a space after ‘f’

So if we change above code to…

static void Main(string[] args)
{
  DateTime dt = DateTime.Now;
  Console.WriteLine(dt.ToString("%f"));
  Console.WriteLine(dt.ToString("ff"));
  Console.WriteLine(dt.ToString("fff"));
  Console.ReadLine();
}

Now program output looks as follows…

8
87
873

Based on last value output you can verify the first two. Issue resolved.

Feb 242014
 

Recently had a customer who faced this issue when his application is run from a network share. The exception information is as follows …

************** Exception Text **************

System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for dataConfiguration: That assembly does not allow partially trusted callers. (G:\System\Backoffice\Citrix2008\MediaExplorer\Rev2008\Prod\Mfm.MediaExplorer.exe.Config line 28) ---> System.Security.SecurityException: That assembly does not allow partially trusted callers.

   at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(RuntimeAssembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed)
   at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags)
   at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, IRuntimeMethodInfo method, RuntimeType parent, UInt32 invocationFlags)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture
   at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
   at System.Configuration.TypeUtil.InvokeCtorWithReflectionPermission(ConstructorInfo ctor)
   at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
   at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
   at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
   at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)
   --- End of inner exception stack trace ---

   at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
   at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)

Collected dumps of the application at the point when the JIT dialog appeared…

Checked out the threads…

0:000> !threads
ThreadCount:      5
UnstartedThread:  0
BackgroundThread: 4
PendingThread:    0
DeadThread:       0
Hosted Runtime:   no
                                   PreEmptive   GC Alloc                Lock
       ID  OSID ThreadOBJ    State GC           Context       Domain   Count APT Exception
   0    1 11b08 007e2c38      6020 Enabled  03093658:03093fe8 007dc9f8     0 STA System.Configuration.ConfigurationErrorsException (02fcce20)
   2    2 11b10 007ee008      b220 Enabled  00000000:00000000 007dc9f8     0 MTA (Finalizer)
   5    3 11b24 0085a600   8009220 Enabled  00000000:00000000 007dc9f8     0 MTA (Threadpool Completion Port)
   6    4 10e78 00860b00   100a220 Enabled  00000000:00000000 007dc9f8     0 MTA (Threadpool Worker)
   8    5 11944 0087a1a8   200b220 Enabled  030911ac:03091fe8 007dc9f8     0 MTA

Yes there is a System.Configuration.ConfigurationErrorsException.

Callstack is as follows…

0:000> !pe 02fcce20
Exception object: 02fcce20
Exception type:   System.Configuration.ConfigurationErrorsException
Message:          An error occurred creating the configuration section handler for dataConfiguration: That assembly does not allow partially trusted callers.
InnerException:   System.Security.SecurityException, Use !PrintException 02fc55d0 to see more.
StackTrace (generated):
    SP       IP       Function
    0045E2EC 69D2E834 System_Configuration_ni!System.Configuration.BaseConfigurationRecord.EvaluateOne(System.String[], System.Configuration.SectionInput, Boolean, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object)+0xc8
    0045E3C8 69D2E655 System_Configuration_ni!System.Configuration.BaseConfigurationRecord.Evaluate(System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object, Boolean, Boolean, System.Object ByRef, System.Object ByRef)+0x481
    0045E488 69D26F5D System_Configuration_ni!System.Configuration.BaseConfigurationRecord.GetSectionRecursive(System.String, Boolean, Boolean, Boolean, Boolean, System.Object ByRef, System.Object ByRef)+0x5bd
    0045E510 69D26F5D System_Configuration_ni!System.Configuration.BaseConfigurationRecord.GetSectionRecursive(System.String, Boolean, Boolean, Boolean, Boolean, System.Object ByRef, System.Object ByRef)+0x5bd
    0045E598 69D26F5D System_Configuration_ni!System.Configuration.BaseConfigurationRecord.GetSectionRecursive(System.String, Boolean, Boolean, Boolean, Boolean, System.Object ByRef, System.Object ByRef)+0x5bd
    0045E620 69D2698A System_Configuration_ni!System.Configuration.BaseConfigurationRecord.GetSection(System.String)+0x2a
    0045E630 69D2A5A9 System_Configuration_ni!System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(System.String)+0x55
    0045E644 69D210BF System_Configuration_ni!System.Configuration.ConfigurationManager.GetSection(System.String)+0x4f

There is an inner exception as well…

0:000> !PrintException 02fc55d0
Exception object: 02fc55d0
Exception type:   System.Security.SecurityException
Message:          That assembly does not allow partially trusted callers.
InnerException:   
StackTrace (generated):
    SP       IP       Function
    0045DC8C 6BD56349 mscorlib_ni!System.Security.CodeAccessSecurityEngine.ThrowSecurityException(System.Reflection.RuntimeAssembly, System.Security.PermissionSet, System.Security.PermissionSet, System.RuntimeMethodHandleInternal, System.Security.Permissions.SecurityAction, System.Object, System.Security.IPermission)+0xa9
    0045E1EC 6B7E9EF2 mscorlib_ni!System.RuntimeMethodHandle.PerformSecurityCheck(System.Object, System.IRuntimeMethodInfo, System.RuntimeType, UInt32)+0x22
    0045E208 6B772242 mscorlib_ni!System.Reflection.RuntimeConstructorInfo.Invoke(System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)+0x82
    0045E298 6B7E9EBA mscorlib_ni!System.Reflection.ConstructorInfo.Invoke(System.Object[])+0x12
    0045E2A0 69D277C8 System_Configuration_ni!System.Configuration.TypeUtil.InvokeCtorWithReflectionPermission(System.Reflection.ConstructorInfo)+0x24
    0045E2B0 69D276AC System_Configuration_ni!System.Configuration.RuntimeConfigurationRecord+RuntimeConfigurationFactory.CreateSectionImpl(System.Configuration.RuntimeConfigurationRecord, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object, System.Configuration.ConfigXmlReader)+0x2c
    0045E2D8 69D312DB System_Configuration_ni!System.Configuration.RuntimeConfigurationRecord+RuntimeConfigurationFactory.CreateSectionWithRestrictedPermissions(System.Configuration.RuntimeConfigurationRecord, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object, System.Configuration.ConfigXmlReader)+0x57
    0045E31C 69D2762A System_Configuration_ni!System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object, System.Configuration.ConfigXmlReader)+0x5e
    0045E344 69D274E4 System_Configuration_ni!System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object, System.Configuration.ConfigXmlReader, System.String, Int32)+0x4c

StackTraceString: 
HResult: 8013150a
SecurityException Message: 
The action that failed was:
LinkDemand
The assembly or AppDomain that failed was:
System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
The Zone of the assembly that failed was:
MyComputer
The Url of the assembly that failed was:
file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll

Hmm weird that the assembly having this issue is System.Configuration! CLR version is 4.0. Caspol shouldn’t kick in if that’s the case. Eventually this turned out to be a bug.

This is fixed via a hotfix: http://support.microsoft.com/kb/2580188
FIX: System.Security.SecurityException occurs when a .NET Framework 4-based application that calls a static method in the System.Configuration.ConfigurationManager class runs on a network share.

The KB article says the following…
The application calls a static method in the System.Configuration.ConfigurationManager class. For example, the application calls the ConfigurationManager.GetSection method.

For this case this was true and the application was indeed calling ConfigurationManager.GetSection.

Disclaimer:
————–
Please read through the hotfix to be very sure that this hotfix applies to you. A classic symptom would be .net 4.0 + ConfigurationManager.GetSection call.

Feb 032014
 

DataRepeater is great control to display data from a table/view, as the name says repeats bunch of fields from a dataset on every row. Follow these simple steps to get started working with this control…

Step 1:

Add a reference to the PowerPack library as shown here: http://ntcoder.com/bab/2013/12/20/visualbasic-powerpack-missing-from-visual-studio-2013/

Step 2:

Make sure you’ve got the datasets in place: Press Shift + Alt + D or View –> Other Windows –> Data Sources. See below screenshots of my Northwind dataset…

image

Step 3:

Drag and drop an instance of data repeater onto your win forms or a container control. Resultant form will look as follows…

image

Please note you’ve got to have the right version of DataRepeater in order for it to get displayed on the form designer surface.

Step 4:

Drag and drop fields from your data set onto this data repeater’s surface. Note that every field dropped on to data repeater will be a pair of control (Label followed by text field or any other control if the option is provided, in my case picture control). I’ve got the following fields dropped on to the control…

image

The size of the control at runtime will be the same as the one you’ve given on the designer, unless you’ve docked the control. Scrollbar’s will be provided by the control to scroll through the rows of data.

Step 5:

Now if I run the form this is what I see. You can scroll through as well. Quick way to display data on a form.

image

Step 6:

DataRepeater supports some other features as well, please go through the documentation to know more. Enjoy!

Jan 252014
 

Taken from MSDN: http://msdn.microsoft.com/en-us/library/system.reflection.emit.opcodes_fields(v=vs.120).aspx 

Public field Static member
Add
Adds two values and pushes the result onto the evaluation stack.

Public field Static member
Add_Ovf
Adds two integers, performs an overflow check, and pushes the result onto the evaluation stack.

Public field Static member
Add_Ovf_Un
Adds two unsigned integer values, performs an overflow check, and pushes the result onto the evaluation stack.

Public field Static member
And
Computes the bitwise AND of two values and pushes the result onto the evaluation stack.

Public field Static member
Arglist
Returns an unmanaged pointer to the argument list of the current method.

Public field Static member
Beq
Transfers control to a target instruction if two values are equal.

Public field Static member
Beq_S
Transfers control to a target instruction (short form) if two values are equal.

Public field Static member
Bge
Transfers control to a target instruction if the first value is greater than or equal to the second value.

Public field Static member
Bge_S
Transfers control to a target instruction (short form) if the first value is greater than or equal to the second value.

Public field Static member
Bge_Un
Transfers control to a target instruction if the first value is greater than the second value, when comparing unsigned integer values or unordered float values.

Public field Static member
Bge_Un_S
Transfers control to a target instruction (short form) if the first value is greater than the second value, when comparing unsigned integer values or unordered float values.

Public field Static member
Bgt
Transfers control to a target instruction if the first value is greater than the second value.

Public field Static member
Bgt_S
Transfers control to a target instruction (short form) if the first value is greater than the second value.

Public field Static member
Bgt_Un
Transfers control to a target instruction if the first value is greater than the second value, when comparing unsigned integer values or unordered float values.

Public field Static member
Bgt_Un_S
Transfers control to a target instruction (short form) if the first value is greater than the second value, when comparing unsigned integer values or unordered float values.

Public field Static member
Ble
Transfers control to a target instruction if the first value is less than or equal to the second value.

Public field Static member
Ble_S
Transfers control to a target instruction (short form) if the first value is less than or equal to the second value.

Public field Static member
Ble_Un
Transfers control to a target instruction if the first value is less than or equal to the second value, when comparing unsigned integer values or unordered float values.

Public field Static member
Ble_Un_S
Transfers control to a target instruction (short form) if the first value is less than or equal to the second value, when comparing unsigned integer values or unordered float values.

Public field Static member
Blt
Transfers control to a target instruction if the first value is less than the second value.

Public field Static member
Blt_S
Transfers control to a target instruction (short form) if the first value is less than the second value.

Public field Static member
Blt_Un
Transfers control to a target instruction if the first value is less than the second value, when comparing unsigned integer values or unordered float values.

Public field Static member
Blt_Un_S
Transfers control to a target instruction (short form) if the first value is less than the second value, when comparing unsigned integer values or unordered float values.

Public field Static member
Bne_Un
Transfers control to a target instruction when two unsigned integer values or unordered float values are not equal.

Public field Static member
Bne_Un_S
Transfers control to a target instruction (short form) when two unsigned integer values or unordered float values are not equal.

Public field Static member
Box
Converts a value type to an object reference (type O).

Public field Static member
Br
Unconditionally transfers control to a target instruction.

Public field Static member
Br_S
Unconditionally transfers control to a target instruction (short form).

Public field Static member
Break
Signals the Common Language Infrastructure (CLI) to inform the debugger that a break point has been tripped.

Public field Static member
Brfalse
Transfers control to a target instruction if value is false, a null reference (Nothing in Visual Basic), or zero.

Public field Static member
Brfalse_S
Transfers control to a target instruction if value is false, a null reference, or zero.

Public field Static member
Brtrue
Transfers control to a target instruction if value is true, not null, or non-zero.

Public field Static member
Brtrue_S
Transfers control to a target instruction (short form) if value is true, not null, or non-zero.

Public field Static member
Call
Calls the method indicated by the passed method descriptor.

Public field Static member
Calli
Calls the method indicated on the evaluation stack (as a pointer to an entry point) with arguments described by a calling convention.

Public field Static member
Callvirt
Calls a late-bound method on an object, pushing the return value onto the evaluation stack.

Public field Static member
Castclass
Attempts to cast an object passed by reference to the specified class.

Public field Static member
Ceq
Compares two values. If they are equal, the integer value 1 (int32) is pushed onto the evaluation stack; otherwise 0 (int32) is pushed onto the evaluation stack.

Public field Static member
Cgt
Compares two values. If the first value is greater than the second, the integer value 1 (int32) is pushed onto the evaluation stack; otherwise 0 (int32) is pushed onto the evaluation stack.

Public field Static member
Cgt_Un
Compares two unsigned or unordered values. If the first value is greater than the second, the integer value 1 (int32) is pushed onto the evaluation stack; otherwise 0 (int32) is pushed onto the evaluation stack.

Public field Static member
Ckfinite
Throws ArithmeticException if value is not a finite number.

Public field Static member
Clt
Compares two values. If the first value is less than the second, the integer value 1 (int32) is pushed onto the evaluation stack; otherwise 0 (int32) is pushed onto the evaluation stack.

Public field Static member
Clt_Un
Compares the unsigned or unordered values value1 and value2. If value1 is less than value2, then the integer value 1 (int32) is pushed onto the evaluation stack; otherwise 0 (int32) is pushed onto the evaluation stack.

Public field Static member
Constrained
Constrains the type on which a virtual method call is made.

Public field Static member
Conv_I
Converts the value on top of the evaluation stack to native int.

Public field Static member
Conv_I1
Converts the value on top of the evaluation stack to int8, then extends (pads) it to int32.

Public field Static member
Conv_I2
Converts the value on top of the evaluation stack to int16, then extends (pads) it to int32.

Public field Static member
Conv_I4
Converts the value on top of the evaluation stack to int32.

Public field Static member
Conv_I8
Converts the value on top of the evaluation stack to int64.

Public field Static member
Conv_Ovf_I
Converts the signed value on top of the evaluation stack to signed native int, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_I_Un
Converts the unsigned value on top of the evaluation stack to signed native int, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_I1
Converts the signed value on top of the evaluation stack to signed int8 and extends it to int32, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_I1_Un
Converts the unsigned value on top of the evaluation stack to signed int8 and extends it to int32, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_I2
Converts the signed value on top of the evaluation stack to signed int16 and extending it to int32, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_I2_Un
Converts the unsigned value on top of the evaluation stack to signed int16 and extends it to int32, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_I4
Converts the signed value on top of the evaluation stack to signed int32, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_I4_Un
Converts the unsigned value on top of the evaluation stack to signed int32, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_I8
Converts the signed value on top of the evaluation stack to signed int64, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_I8_Un
Converts the unsigned value on top of the evaluation stack to signed int64, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_U
Converts the signed value on top of the evaluation stack to unsigned native int, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_U_Un
Converts the unsigned value on top of the evaluation stack to unsigned native int, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_U1
Converts the signed value on top of the evaluation stack to unsigned int8 and extends it to int32, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_U1_Un
Converts the unsigned value on top of the evaluation stack to unsigned int8 and extends it to int32, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_U2
Converts the signed value on top of the evaluation stack to unsigned int16 and extends it to int32, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_U2_Un
Converts the unsigned value on top of the evaluation stack to unsigned int16 and extends it to int32, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_U4
Converts the signed value on top of the evaluation stack to unsigned int32, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_U4_Un
Converts the unsigned value on top of the evaluation stack to unsigned int32, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_U8
Converts the signed value on top of the evaluation stack to unsigned int64, throwing OverflowException on overflow.

Public field Static member
Conv_Ovf_U8_Un
Converts the unsigned value on top of the evaluation stack to unsigned int64, throwing OverflowException on overflow.

Public field Static member
Conv_R_Un
Converts the unsigned integer value on top of the evaluation stack to float32.

Public field Static member
Conv_R4
Converts the value on top of the evaluation stack to float32.

Public field Static member
Conv_R8
Converts the value on top of the evaluation stack to float64.

Public field Static member
Conv_U
Converts the value on top of the evaluation stack to unsigned native int, and extends it to native int.

Public field Static member
Conv_U1
Converts the value on top of the evaluation stack to unsigned int8, and extends it to int32.

Public field Static member
Conv_U2
Converts the value on top of the evaluation stack to unsigned int16, and extends it to int32.

Public field Static member
Conv_U4
Converts the value on top of the evaluation stack to unsigned int32, and extends it to int32.

Public field Static member
Conv_U8
Converts the value on top of the evaluation stack to unsigned int64, and extends it to int64.

Public field Static member
Cpblk
Copies a specified number bytes from a source address to a destination address.

Public field Static member
Cpobj
Copies the value type located at the address of an object (type &, * or native int) to the address of the destination object (type &, * or native int).

Public field Static member
Div
Divides two values and pushes the result as a floating-point (type F) or quotient (type int32) onto the evaluation stack.

Public field Static member
Div_Un
Divides two unsigned integer values and pushes the result (int32) onto the evaluation stack.

Public field Static member
Dup
Copies the current topmost value on the evaluation stack, and then pushes the copy onto the evaluation stack.

Public field Static member
Endfilter
Transfers control from the filter clause of an exception back to the Common Language Infrastructure (CLI) exception handler.

Public field Static member
Endfinally
Transfers control from the fault or finally clause of an exception block back to the Common Language Infrastructure (CLI) exception handler.

Public field Static member
Initblk
Initializes a specified block of memory at a specific address to a given size and initial value.

Public field Static member
Initobj
Initializes each field of the value type at a specified address to a null reference or a 0 of the appropriate primitive type.

Public field Static member
Isinst
Tests whether an object reference (type O) is an instance of a particular class.

Public field Static member
Jmp
Exits current method and jumps to specified method.

Public field Static member
Ldarg
Loads an argument (referenced by a specified index value) onto the stack.

Public field Static member
Ldarg_0
Loads the argument at index 0 onto the evaluation stack.

Public field Static member
Ldarg_1
Loads the argument at index 1 onto the evaluation stack.

Public field Static member
Ldarg_2
Loads the argument at index 2 onto the evaluation stack.

Public field Static member
Ldarg_3
Loads the argument at index 3 onto the evaluation stack.

Public field Static member
Ldarg_S
Loads the argument (referenced by a specified short form index) onto the evaluation stack.

Public field Static member
Ldarga
Load an argument address onto the evaluation stack.

Public field Static member
Ldarga_S
Load an argument address, in short form, onto the evaluation stack.

Public field Static member
Ldc_I4
Pushes a supplied value of type int32 onto the evaluation stack as an int32.

Public field Static member
Ldc_I4_0
Pushes the integer value of 0 onto the evaluation stack as an int32.

Public field Static member
Ldc_I4_1
Pushes the integer value of 1 onto the evaluation stack as an int32.

Public field Static member
Ldc_I4_2
Pushes the integer value of 2 onto the evaluation stack as an int32.

Public field Static member
Ldc_I4_3
Pushes the integer value of 3 onto the evaluation stack as an int32.

Public field Static member
Ldc_I4_4
Pushes the integer value of 4 onto the evaluation stack as an int32.

Public field Static member
Ldc_I4_5
Pushes the integer value of 5 onto the evaluation stack as an int32.

Public field Static member
Ldc_I4_6
Pushes the integer value of 6 onto the evaluation stack as an int32.

Public field Static member
Ldc_I4_7
Pushes the integer value of 7 onto the evaluation stack as an int32.

Public field Static member
Ldc_I4_8
Pushes the integer value of 8 onto the evaluation stack as an int32.

Public field Static member
Ldc_I4_M1
Pushes the integer value of -1 onto the evaluation stack as an int32.

Public field Static member
Ldc_I4_S
Pushes the supplied int8 value onto the evaluation stack as an int32, short form.

Public field Static member
Ldc_I8
Pushes a supplied value of type int64 onto the evaluation stack as an int64.

Public field Static member
Ldc_R4
Pushes a supplied value of type float32 onto the evaluation stack as type F (float).

Public field Static member
Ldc_R8
Pushes a supplied value of type float64 onto the evaluation stack as type F (float).

Public field Static member
Ldelem
Loads the element at a specified array index onto the top of the evaluation stack as the type specified in the instruction.

Public field Static member
Ldelem_I
Loads the element with type native int at a specified array index onto the top of the evaluation stack as a native int.

Public field Static member
Ldelem_I1
Loads the element with type int8 at a specified array index onto the top of the evaluation stack as an int32.

Public field Static member
Ldelem_I2
Loads the element with type int16 at a specified array index onto the top of the evaluation stack as an int32.

Public field Static member
Ldelem_I4
Loads the element with type int32 at a specified array index onto the top of the evaluation stack as an int32.

Public field Static member
Ldelem_I8
Loads the element with type int64 at a specified array index onto the top of the evaluation stack as an int64.

Public field Static member
Ldelem_R4
Loads the element with type float32 at a specified array index onto the top of the evaluation stack as type F (float).

Public field Static member
Ldelem_R8
Loads the element with type float64 at a specified array index onto the top of the evaluation stack as type F (float).

Public field Static member
Ldelem_Ref
Loads the element containing an object reference at a specified array index onto the top of the evaluation stack as type O (object reference).

Public field Static member
Ldelem_U1
Loads the element with type unsigned int8 at a specified array index onto the top of the evaluation stack as an int32.

Public field Static member
Ldelem_U2
Loads the element with type unsigned int16 at a specified array index onto the top of the evaluation stack as an int32.

Public field Static member
Ldelem_U4
Loads the element with type unsigned int32 at a specified array index onto the top of the evaluation stack as an int32.

Public field Static member
Ldelema
Loads the address of the array element at a specified array index onto the top of the evaluation stack as type & (managed pointer).

Public field Static member
Ldfld
Finds the value of a field in the object whose reference is currently on the evaluation stack.

Public field Static member
Ldflda
Finds the address of a field in the object whose reference is currently on the evaluation stack.

Public field Static member
Ldftn
Pushes an unmanaged pointer (type native int) to the native code implementing a specific method onto the evaluation stack.

Public field Static member
Ldind_I
Loads a value of type native int as a native int onto the evaluation stack indirectly.

Public field Static member
Ldind_I1
Loads a value of type int8 as an int32 onto the evaluation stack indirectly.

Public field Static member
Ldind_I2
Loads a value of type int16 as an int32 onto the evaluation stack indirectly.

Public field Static member
Ldind_I4
Loads a value of type int32 as an int32 onto the evaluation stack indirectly.

Public field Static member
Ldind_I8
Loads a value of type int64 as an int64 onto the evaluation stack indirectly.

Public field Static member
Ldind_R4
Loads a value of type float32 as a type F (float) onto the evaluation stack indirectly.

Public field Static member
Ldind_R8
Loads a value of type float64 as a type F (float) onto the evaluation stack indirectly.

Public field Static member
Ldind_Ref
Loads an object reference as a type O (object reference) onto the evaluation stack indirectly.

Public field Static member
Ldind_U1
Loads a value of type unsigned int8 as an int32 onto the evaluation stack indirectly.

Public field Static member
Ldind_U2
Loads a value of type unsigned int16 as an int32 onto the evaluation stack indirectly.

Public field Static member
Ldind_U4
Loads a value of type unsigned int32 as an int32 onto the evaluation stack indirectly.

Public field Static member
Ldlen
Pushes the number of elements of a zero-based, one-dimensional array onto the evaluation stack.

Public field Static member
Ldloc
Loads the local variable at a specific index onto the evaluation stack.

Public field Static member
Ldloc_0
Loads the local variable at index 0 onto the evaluation stack.

Public field Static member
Ldloc_1
Loads the local variable at index 1 onto the evaluation stack.

Public field Static member
Ldloc_2
Loads the local variable at index 2 onto the evaluation stack.

Public field Static member
Ldloc_3
Loads the local variable at index 3 onto the evaluation stack.

Public field Static member
Ldloc_S
Loads the local variable at a specific index onto the evaluation stack, short form.

Public field Static member
Ldloca
Loads the address of the local variable at a specific index onto the evaluation stack.

Public field Static member
Ldloca_S
Loads the address of the local variable at a specific index onto the evaluation stack, short form.

Public field Static member
Ldnull
Pushes a null reference (type O) onto the evaluation stack.

Public field Static member
Ldobj
Copies the value type object pointed to by an address to the top of the evaluation stack.

Public field Static member
Ldsfld
Pushes the value of a static field onto the evaluation stack.

Public field Static member
Ldsflda
Pushes the address of a static field onto the evaluation stack.

Public field Static member
Ldstr
Pushes a new object reference to a string literal stored in the metadata.

Public field Static member
Ldtoken
Converts a metadata token to its runtime representation, pushing it onto the evaluation stack.

Public field Static member
Ldvirtftn
Pushes an unmanaged pointer (type native int) to the native code implementing a particular virtual method associated with a specified object onto the evaluation stack.

Public field Static member
Leave
Exits a protected region of code, unconditionally transferring control to a specific target instruction.

Public field Static member
Leave_S
Exits a protected region of code, unconditionally transferring control to a target instruction (short form).

Public field Static member
Localloc
Allocates a certain number of bytes from the local dynamic memory pool and pushes the address (a transient pointer, type *) of the first allocated byte onto the evaluation stack.

Public field Static member
Mkrefany
Pushes a typed reference to an instance of a specific type onto the evaluation stack.

Public field Static member
Mul
Multiplies two values and pushes the result on the evaluation stack.

Public field Static member
Mul_Ovf
Multiplies two integer values, performs an overflow check, and pushes the result onto the evaluation stack.

Public field Static member
Mul_Ovf_Un
Multiplies two unsigned integer values, performs an overflow check, and pushes the result onto the evaluation stack.

Public field Static member
Neg
Negates a value and pushes the result onto the evaluation stack.

Public field Static member
Newarr
Pushes an object reference to a new zero-based, one-dimensional array whose elements are of a specific type onto the evaluation stack.

Public field Static member
Newobj
Creates a new object or a new instance of a value type, pushing an object reference (type O) onto the evaluation stack.

Public field Static member
Nop
Fills space if opcodes are patched. No meaningful operation is performed although a processing cycle can be consumed.

Public field Static member
Not
Computes the bitwise complement of the integer value on top of the stack and pushes the result onto the evaluation stack as the same type.

Public field Static member
Or
Compute the bitwise complement of the two integer values on top of the stack and pushes the result onto the evaluation stack.

Public field Static member
Pop
Removes the value currently on top of the evaluation stack.

Public field Static member
Prefix1
Infrastructure. This is a reserved instruction.

Public field Static member
Prefix2
Infrastructure. This is a reserved instruction.

Public field Static member
Prefix3
Infrastructure. This is a reserved instruction.

Public field Static member
Prefix4
Infrastructure. This is a reserved instruction.

Public field Static member
Prefix5
Infrastructure. This is a reserved instruction.

Public field Static member
Prefix6
Infrastructure. This is a reserved instruction.

Public field Static member
Prefix7
Infrastructure. This is a reserved instruction.

Public field Static member
Prefixref
Infrastructure. This is a reserved instruction.

Public field Static member
Readonly
Specifies that the subsequent array address operation performs no type check at run time, and that it returns a managed pointer whose mutability is restricted.

Public field Static member
Refanytype
Retrieves the type token embedded in a typed reference.

Public field Static member
Refanyval
Retrieves the address (type &) embedded in a typed reference.

Public field Static member
Rem
Divides two values and pushes the remainder onto the evaluation stack.

Public field Static member
Rem_Un
Divides two unsigned values and pushes the remainder onto the evaluation stack.

Public field Static member
Ret
Returns from the current method, pushing a return value (if present) from the callee’s evaluation stack onto the caller’s evaluation stack.

Public field Static member
Rethrow
Rethrows the current exception.

Public field Static member
Shl
Shifts an integer value to the left (in zeroes) by a specified number of bits, pushing the result onto the evaluation stack.

Public field Static member
Shr
Shifts an integer value (in sign) to the right by a specified number of bits, pushing the result onto the evaluation stack.

Public field Static member
Shr_Un
Shifts an unsigned integer value (in zeroes) to the right by a specified number of bits, pushing the result onto the evaluation stack.

Public field Static member
Sizeof
Pushes the size, in bytes, of a supplied value type onto the evaluation stack.

Public field Static member
Starg
Stores the value on top of the evaluation stack in the argument slot at a specified index.

Public field Static member
Starg_S
Stores the value on top of the evaluation stack in the argument slot at a specified index, short form.

Public field Static member
Stelem
Replaces the array element at a given index with the value on the evaluation stack, whose type is specified in the instruction.

Public field Static member
Stelem_I
Replaces the array element at a given index with the native int value on the evaluation stack.

Public field Static member
Stelem_I1
Replaces the array element at a given index with the int8 value on the evaluation stack.

Public field Static member
Stelem_I2
Replaces the array element at a given index with the int16 value on the evaluation stack.

Public field Static member
Stelem_I4
Replaces the array element at a given index with the int32 value on the evaluation stack.

Public field Static member
Stelem_I8
Replaces the array element at a given index with the int64 value on the evaluation stack.

Public field Static member
Stelem_R4
Replaces the array element at a given index with the float32 value on the evaluation stack.

Public field Static member
Stelem_R8
Replaces the array element at a given index with the float64 value on the evaluation stack.

Public field Static member
Stelem_Ref
Replaces the array element at a given index with the object ref value (type O) on the evaluation stack.

Public field Static member
Stfld
Replaces the value stored in the field of an object reference or pointer with a new value.

Public field Static member
Stind_I
Stores a value of type native int at a supplied address.

Public field Static member
Stind_I1
Stores a value of type int8 at a supplied address.

Public field Static member
Stind_I2
Stores a value of type int16 at a supplied address.

Public field Static member
Stind_I4
Stores a value of type int32 at a supplied address.

Public field Static member
Stind_I8
Stores a value of type int64 at a supplied address.

Public field Static member
Stind_R4
Stores a value of type float32 at a supplied address.

Public field Static member
Stind_R8
Stores a value of type float64 at a supplied address.

Public field Static member
Stind_Ref
Stores a object reference value at a supplied address.

Public field Static member
Stloc
Pops the current value from the top of the evaluation stack and stores it in a the local variable list at a specified index.

Public field Static member
Stloc_0
Pops the current value from the top of the evaluation stack and stores it in a the local variable list at index 0.

Public field Static member
Stloc_1
Pops the current value from the top of the evaluation stack and stores it in a the local variable list at index 1.

Public field Static member
Stloc_2
Pops the current value from the top of the evaluation stack and stores it in a the local variable list at index 2.

Public field Static member
Stloc_3
Pops the current value from the top of the evaluation stack and stores it in a the local variable list at index 3.

Public field Static member
Stloc_S
Pops the current value from the top of the evaluation stack and stores it in a the local variable list at index (short form).

Public field Static member
Stobj
Copies a value of a specified type from the evaluation stack into a supplied memory address.

Public field Static member
Stsfld
Replaces the value of a static field with a value from the evaluation stack.

Public field Static member
Sub
Subtracts one value from another and pushes the result onto the evaluation stack.

Public field Static member
Sub_Ovf
Subtracts one integer value from another, performs an overflow check, and pushes the result onto the evaluation stack.

Public field Static member
Sub_Ovf_Un
Subtracts one unsigned integer value from another, performs an overflow check, and pushes the result onto the evaluation stack.

Public field Static member
Switch
Implements a jump table.

Public field Static member
Tailcall
Performs a postfixed method call instruction such that the current method’s stack frame is removed before the actual call instruction is executed.

Public field Static member
Throw
Throws the exception object currently on the evaluation stack.

Public field Static member
Unaligned
Indicates that an address currently atop the evaluation stack might not be aligned to the natural size of the immediately following ldind, stind, ldfld, stfld, ldobj, stobj, initblk, or cpblk instruction.

Public field Static member
Unbox
Converts the boxed representation of a value type to its unboxed form.

Public field Static member
Unbox_Any
Converts the boxed representation of a type specified in the instruction to its unboxed form.

Public field Static member
Volatile
Specifies that an address currently atop the evaluation stack might be volatile, and the results of reading that location cannot be cached or that multiple stores to that location cannot be suppressed.

Public field Static member
Xor
Computes the bitwise XOR of the top two values on the evaluation stack, pushing the result onto the evaluation stack.

Oct 082013
 

Why use gcAllowVeryLargeObjects ?

Please note that this post is only applicable for .net 4.5 and above.

Having trouble with .net array size limit, i.e. 2GB on a 64 bit target. Use gcAllowVeryLargeObjects tag in application config file to work around this issue. A sample config file will look as follows…

<configuration>
  <runtime>
    <gcallowverylargeobjects enabled="true" />
  </runtime>
</configuration></pre>

Please read the docs very carefully, there are some caveats that you should be aware off… (from MSDN)

Using this element in your application configuration file enables arrays that are larger than 2 GB in size, but does not change other limits on object size or array size:

  • The maximum number of elements in an array is UInt32.MaxValue.
  • The maximum index in any single dimension is 2,147,483,591 (0x7FFFFFC7) for byte arrays and arrays of single-byte structures, and 2,146,435,071 (0X7FEFFFFF) for other types.
  • The maximum size for strings and other non-array objects is unchanged.

Read More

Sep 202011
 

Are you having trouble converting VB6 project to VB.net Visual Studio 2010. Well just to be frank you should have long back converted this VB6 project of yours to VB.net. VB6 is ancient and just because your code works doesn’t mean that you won’t migrate it to a newer platform. In my opinion let your customers use the VB6 project of yours while you in the background should have converted a copy of it to VB.net. Now you might say it’s too much work… well how about it now. 😉

Just to be clear Visual Studio 2010 does NOT inherently support converting VB6 project to VB.net 2010. When I force a conversion (via project open dialog) I get the following error dialog…

VB6 to VB.net 2010 - Conversion Error

VB6 to VB.net 2010 – Conversion Error

Recently Mr. X asked me this question so I sent him an email with the steps on converting a VB6 project to VB.net Visual Studio 2010. So here are the steps (straight from the email I sent to the customer…)

  1. Make sure VB 6.0 with SP 6.0 installed on the machine.
  2. Make sure that all the referenced components (ActiveX dll, OCX) for the VB 6.0 application is available on the machine.
  3. Open the VB 6.0 project in VB 6.0 IDE and make sure that it opens fine. Build the project and make sure that the application executes without any errors.
  4. Run the Upgrade assessment tool on the visual basic 6 project:
    (Old one) http://www.microsoft.com/downloads/details.aspx?FamilyId=10C491A2-FC67-4509-BC10-60C5C039A272&displaylang=en
    (New one) http://www.artinsoft.com/visual-basic-upgrade-assessment-tool.aspx
  5. Keep a local copy of the VB 6.0 project
  6. There is no direct wizard conversion in Visual Studio 2010. You have to first use the conversion wizard available in Visual Studio 2005/2008 to convert to VB.net and then convert the same to Visual Studio 2010. As you don’t have Visual Studio 2008, you can download free version from following link.
    http://www.microsoft.com/visualstudio/en-us/products/2008-editions/express
  7. Once you are done with the conversion you can uninstall Visual Studio 2008 express edition.
  8. Also you can download a free guide which contains information about Upgrading Visual Basic 6.0 Applications to Visual Basic .NET and Visual Basic 2005 (Its bit old but it will give useful insights as and when you are migrating source code to .net).
    http://www.microsoft.com/downloads/details.aspx?FamilyId=7C3FE0A9-CBED-485F-BFD5-847FB68F785D&displaylang=en

A general note:

As per the upgrade guide, the effect of the changes and subtle differences in Visual Basic .NET is that, unlike previous versions of Visual Basic, most real-world projects cannot be upgraded 100 percent automatically. To understand why, consider that for a 100 percent upgrade there has to be a one-to-one correlation between every element of Visual Basic 6 and a corresponding element in Visual Basic .NET. Unfortunately, this correlation does not exist. The upgrade process is closer to 95 percent, meaning that the Visual Basic .NET Upgrade Wizard upgrades 95 percent of your application, and you modify 5 percent of the application to get it working. What does 5 percent mean? If it took you 100 days to write the original Visual Basic 6 application, you might expect to take 5 days to upgrade it. This number is not set in stone-some applications are easier to upgrade than others, and the experience of the person doing the upgrade is an important factor. To prepare yourself, make sure you familiarize yourself with Part IV of the upgrade guide. It discusses how to design your Visual Basic 6 applications to make the upgrade process much smoother.

Microsoft Visual Basic 6.0 Migration Resource Center
http://msdn.microsoft.com/hi-in/vbrun/ms788233(en-us).aspx

Sep 062011
 

Enable or Disable Just In Time Debugging

Read the following article in MSDN:

http://msdn.microsoft.com/en-us/library/5hs4b7a6.aspx

The easiest way to disable JIT debugger is via the Tools->Options dialog in Visual Studio. For other options read the article.

Enable/Disable Just in Time Debugger in Visual Studio Options dialog

Enable/Disable Just in Time Debugger in Visual Studio Options dialog

Jun 012008
 

It’s quite easy to work with WMI in .net. Follow these steps to get details of Win32_VideoController.

Namespace to use is System.Management.

1. Create a management class object.

Dim MngClass As New ManagementClass("Win32_VideoController")

2. Create a management object class collection instance and fill out this collection likewise…

Dim MngObjCollection As ManagementObjectCollection = MngClass.GetInstances

' Now we need to iterate through this collection object likewise...
For Each MngObj As ManagementObject In MngObjCollection
    Dim PropCollection As PropertyDataCollection = MngObj.Properties
    For Each PropData As PropertyData In PropCollection
       ' Read in properties of video controller.
    Next PropData
Next MngObj

Well we are done, quite easy isn’t it? Do this in C++ and you will be breaking your head and fingers.

Change the name of the above WMI class to something else and it will work in the same way except for properties of the WMI class object since each class has different properties.

Look up MSDN for more details on the properties of WMI classes. As a homework try fetching properties of “Win32_Processor”.

Download a sample application which extensively uses WMI to fetch details of remote machines. There are two exe’s and one dll. Put them in the same directory and run both exe’s. The one with a blue icon is the client application and the one with a red icon is the server application. You can run these applications locally or as remote ones putting the client application in a remote machine. See the power of WMI in full flow.