Determine is executable is a console application

30. November 2010 03:36 by Mrojas in General  //  Tags: , ,   //   Comments (0)

 

I you were looking for a way to do that just take a look at this post: http://weblogs.asp.net/whaggard/archive/2004/08/30/223020.aspx

Just notice that for this post you need to add this struct:

[StructLayout(LayoutKind.Sequential)]
public struct SHFILEINFO
{
  public IntPtr hIcon;
  public IntPtr iIcon;
  public uint dwAttributes;
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
  public string szDisplayName;
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
  public string szTypeName;
};

Custom tool warning: Cannot import wsdl:portType

25. November 2010 05:04 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

During a Silverlight migration project from VB6 I was trying to add a WCF reference,
everything seemed to work in the wizard but no code was generated.

After reviewing the Warning messages, i found that some said:

Custom tool warning: Cannot import wsdl:portType

What I did to solve this issue?

1. Right click on your service reference

2. Select Configure Service reference

3. Uncheck the option that says Reuse types in referenced assemblies.

image

4. Press OK

After that VS generated the code and I could use the WCF service.

Lightswitch Experiences: Migrating Access to Microsoft Lightswitch

25. November 2010 03:07 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)

 

 

Microsoft Access was (and is still) very used for simple data entry applications.
But Microsoft Access despite all its good is kind of an old technology and there was
no clear alternative for a simple mortal development environment… until Microsoft Lightswitch.

This series of posts illustrates the experiences of migrating Microsoft Access applications to LigthSwitch.

This post shows the result of migrating all Northwind Access example tables:

The following is Microsoft LightSwitch Solution explorer showing all Tables

image

 

And these are some of the Northwind tables in LIghtswitch

 

image

image

 

image

image

 

image

 

image

 

The migration process is straightforward. Text and Memo fields can be migrated to string, Numbers can be migrated to Int32 or Int64, Currency is map to Money. Yes\No can be mapped to boolean with a Value List.

There is support for specifying a caption (Display ID in Lightswitch), Description, and validation rules.

I will keep posting about Query migration, form migration and also  report migration. Stay tuned.

ORA-12154: TNS:could not resolve the connect identifier specified for asp.net application to oracle

18. November 2010 16:57 by Mrojas in General  //  Tags: , , , , ,   //   Comments (0)

I had a Windows Server 2003 and I was trying to connect to Oracle with the System.Data.OracleClient provider.

I was able to connect from a console application but not from ASP.NET.
From ASP.NET I only got ORA-12154 errors.

I found that on Windows 2003 Server, ASP.NET applications run in the
security context of the “Network Service” user.

So I tried these two  things:

I first started following these steps:
1. Log on to Windows as a user with Administrator privileges.
2. Launch Windows Explorer from the Start Menu and and navigate to the
ORACLE_HOME folder. It is usually under the oracle instalation folder.
In my case that is C:\oracle\product\10.2.0\client_1
3. Right-click on the ORACLE_HOME folder and choose the "Properties" option
from the drop down list. A "Properties" window should appear.
4. Click on the "Security" tab of the "Properties" window.
5. Click on "Authenticated Users" item in the "Name" list (on Windows XP
the "Name" list is called "Group or user names").
6. Uncheck the "Read and Execute" box in the "Permissions" list under the
"Allow" column (on Windows XP the "Permissions" list is called
"Permissions for Authenticated Users").
7. Re-check the "Read and Execute" box under the "Allow" column (this is
the box you just unchecked).
8. Click the "Advanced" button and in the "Permission Entries" list make
sure you see the "Authenticated Users" listed there with:
Permission = Read & Execute
Apply To = This folder, subfolders and files
If this is NOT the case, edit that line and make sure the "Apply onto"
drop-down box is set to "This folder, subfolders and files". This
should already be set properly but it is important that you verify this.
9. Click the "Ok" button until you close out all of the security properties
windows. The cursor may present the hour glass for a few seconds as it
applies the permissions you just changed to all subfolders and files.
10. Reboot your computer to assure that these changes have taken effect.
(I thought that rebooting was not that important but it seems that you have to reboot to make changes effective)

It sometimes happens that it is not enough, because it seems that some oracle installations need the
the ASP.NET process to run with an account with sufficient privileges.

The second thing you can do in that case is.

1. First open the machine.config file. That will be usually in %windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config

2. Look for something like:

<system.web>
    <processModel autoConfig="true" />

3. Add the userName=”System” attribute. For example

<processModel autoConfig="true" userName="System" />

4. Restart the IIS.

IIS 6 Metabase and IIS 6 Configuration Compatibility

11. November 2010 04:38 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)

 

I have a silverlight application that I was trying to publish from Visual Studio to my local IIS and I got this problem:

For the record I have Windows 7.

image

 

So you can write on the Search program and Files “ Turn Windows Features on or off”

 

image

 

And then select

 

image

Set Fixed port for ASP.NET project. Good for Silverlight and Azure projects

11. November 2010 02:57 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)

If you are doing Silverlight development, one thing that can be cumbersome is keeping in sync
your development and production settings. Specially if you are using WCF services because you have
to make sure that your ServiceClient.config file has the right values.

What I usually do is this.

1. First set fixed ports for my application. See http://blogs.msdn.com/b/webdevelopertips/archive/2008/11/07/tip-21-did-you-know-how-to-set-a-fixed-port-for-the-developer-web-server.aspx

2. Modify my hosts file in C:\Windows\System32\drivers\etc adding an entry like:

#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
 127.0.0.1       localhost
 127.0.0.1       productionserver.cloudapp.net  

 In this way all you have to change is your hosts file and you keep the same settings for development and for production

Handling Orientation in Silverlight for Symbian

2. November 2010 05:10 by Mrojas in General  //  Tags: , ,   //   Comments (0)

 

One obvious thing in modern symbian mobiles, is how to detect orientation.
I am currently porting some Silverlight 1.0 samples like GrandPiano to Silverlight for Symbian and I was wondering
how can I detect the phone orientation. Well I just analysed the Bing demo and find out that is kind of simple.

What you need is something like this:

public static readonly DependencyProperty OrientationProperty = 
DependencyProperty.Register("Orientation", typeof(Orientation), typeof(Page),
new PropertyMetadata((Orientation)0, new PropertyChangedCallback(OrientationPropertyChanged))); private static void OrientationPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { (sender as GrandPiano).UpdateOrientation(); } private void UpdateOrientation() { base.Width = (this.Orientation == Orientation.Vertical) ? DeviceVerticalSize.Width : DeviceVerticalSize.Height; base.Height = (this.Orientation == Orientation.Vertical) ? DeviceVerticalSize.Height : DeviceVerticalSize.Width; base.Clip = new RectangleGeometry { Rect = new Rect(new Point(), new Size(base.Width, base.Height)) }; } // Properties public Orientation Orientation { get { return (Orientation)base.GetValue(OrientationProperty); } set { base.SetValue(OrientationProperty, value); } }

Silverlight Symbian: Silverlight Content on this website cannot be displayed on this device

1. November 2010 06:10 by Mrojas in General  //  Tags: , ,   //   Comments (0)

When I wrote my first application for Silverlight on Symbian, I kept getting this annoying
message I really didnt get why was it.

Finally I downloaded the Bing Xap file and looked at it. And it seams it was just something simple.

<?xml version="1.0" encoding="utf-8"?>
<Deployment 
xmlns=http://schemas.microsoft.com/client/2007/deployment
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
ExternalCallersFromCrossDomain="ScriptableOnly"
EntryPointAssembly="BingNokia"
EntryPointType="BingNokia.App"

RuntimeVersion="2.0.31005.0"

>
  <Deployment.Parts>
    <AssemblyPart x:Name="BingNokia" Source="BingNokia.dll" />
    <AssemblyPart x:Name="Microsoft.Windows.Controls.WatermarkedTextBox" Source="Microsoft.Windows.Controls.WatermarkedTextBox.dll" />
    <AssemblyPart x:Name="Mvc" Source="Mvc.dll" />
    <AssemblyPart x:Name="System.Xml.Linq" Source="System.Xml.Linq.dll" />
  </Deployment.Parts>
</Deployment>

My runtime version was wrong.

<Deployment 
xmlns=http://schemas.microsoft.com/client/2007/deployment
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
EntryPointAssembly="NokiaTest1"
EntryPointType="NokiaTest1.App"
RuntimeVersion="3.0.40818.0"> <Deployment.Parts> <AssemblyPart x:Name="NokiaTest1" Source="NokiaTest1.dll" /> </Deployment.Parts> </Deployment>

I still dont how to customize my AppManifest file
I suppose that behaviour is due to the fact that I have Silverlight 3 installed in my machine.
So what I did is that I compiled my application. Then renamed my .xap for .zip. Extracted my AppManifest.xml and modified it
changing the runtime version and copied it back to my .xap file. And voila!

Starting a Project for the Cloud

27. October 2010 08:43 by Mrojas in General  //  Tags: , , , , ,   //   Comments (0)

 

If you dont have Windows Azure Tools installed

1. Open Visual Studio 2010

2. On the File Menu, Click new, and then click Project. This opens the New Project dialog

3. In the New Project dialog under Installed Templates, expand the Visual C# node

4. In project type click Cloud. A project that says Enable Windows Azure Tools appears

5. In Name type for example EnableTools and click OK

6. A project with a web page will appear. Click the Download Windows Azure Tools button. Close Visual Studio. Download and installed them.

image

Once you have Windows Azure Toolsl installed

 

1. Open Visual Studio 2010

2. On the File Menu, Click new, and then click Project. This opens the New Project dialog

3. In the New Project dialog under Installed Templates, expand the Visual C# node

4. In project type click Cloud. A project that says Windows Azure Cloud Service appears

image

5. In Name Type for example Phonebook  and click ok. The New Cloud Service Project is shown

 

If you are developing a Silverlight application with some services select the WCF Service Web Role. Rename it to something appropriate. In this example will be Phonebook.Web and Press OK

image

Your solution explorer will look like this:

image

Now you can developing your application. We already have an Silverlight application (that was migrated from VB6 to Silverlight) and some existing Silverlight Class libraries and Server Class Libraries (Class Libraries compiled with the full 4.0 Framework that will be used in the Server Project Phonebook.Web).

To add your Silverlight app. Right Click your server project (Phonebook.Web), then Properties and in Properties go to Silverlight Application and add Phonebook_Silverlight

When everything compiles Go to the Visual Studio Menu Bar, then Debug and then Start Without Debugging. That starts the local development environment on your computer.

image

You can now start testing and finish development of your application.

There is something you myst notice. Everytime you start the Cloud Service, the Azure test environment starts. By default it will start in http:\\localhost:81 but there was a previous Development Fabric it will start in http:\\localhost:81. This is important for Silverlight applications because you must configure your service end point to a particular port. Make sure that your ServiceReferences.ClientConfig file is in sync with the port that your DevelopmentFabric is using

Notes for Azure development:

Sometimes during development it might happen that you get more than one instance of the Development Fabric. This will affect your silverlight apps that rely on WFC services because each new instance starts on a new port. You can use the CSRun tool to stop all instances.

If you have installed the Windows® Azure™ SDK to the default location, the CSRun tool can be found at C:\Program Files\Windows Azure SDK\v1.0\bin\csrun.exe.Then run C:\Program Files\Windows Azure SDK\v1.2\bin\csrun.exe /devfabric:shutdown

 

Publishing your Application

1. Navigate to Azure : https://windows.azure.com/Cloud/Provisioning/Default.aspx

2. On the page that says My Projects. When you are starting you will only see one project line. Click on it

image

3. Click on New Service

image

4. Click on Hosted Services

image

5. In the Create Service page, specify the service properties. In this example we will use Phonebook.Web for service label and a short description and press next.

image

6. Now your hosted service needs a public url. You must check availability. In this example we will use phonebook. Hosted Affinity tries to group your services and storages in the same area. We have a SQL Azure database that is hosted in North Central US, so we will create a new AffinityGroup and call it PhonebookGroup. Press Create

image

7. After Creation your Service is ready, and you can start the deployment.

image

 

8. In Visual Studio 2010 Right click your Cloud Service. And Select Publish…

image

 

9. The Publish Cloud Service Dialog appears. From the Credentials drop down list select <Add>

image

10. From the Create or select an existing certificate select <Create>.
10.1 In our example we will enter a FriendlyName for the new certificate of PhoneBook.

image


10.2 Click the “Copy the full path” link in the dialog. Then Open your browser and navigate to https://windows.azure.com/cloud/provisioning/ and click on your project

 

image

10.3 Now click on account.And in the Account page click on Manage My API Certificates

image

10.4 Click the Choose file and paste the full path you had copied before and then click upload

image

the installed certificate will be shown below.

image

10.5 Now navigate to AppFabric by clicking AppFabric on the left hand side. This will show your subscription ID. Select it and copy it. You have to pasted on the dialog box in Visual Studio on the textbox that says above it “Copy the subscription ID”

image

and name those Credentials PhonebookAccount and press  OK

 

 

 

 

 

 

 

 

 

11 You need a storage account. If you have not created one. Then you have to follow these steps:

11.1 Open your browser and navigate to https://windows.azure.com/cloud/provisioning/ and click on your project.

 

image

11.2 Now click on New Service

image

11.3 Now click on Storage Account

image

11.4 The Create Service Page is show. Enter a Service label and Description and Click Next

image

 

 

 

11.5 Select a name for the public URL, check its availability. And select Affinity.And press Create

image

12. Press OK on the Publish Cloud Service Dialog

 

image

13. Visual studio will upload your application to the cloud

image

While your application is in staging the only problem might be that the published URL changed and that might be conflictive for your ServiceReferences.ClientConfig.

Once your application is on Staging you can switch it to Production and your are ready for business.

Create a Database in SQL Azure

26. October 2010 06:28 by Mrojas in General  //  Tags: , , , , , ,   //   Comments (0)

One of the first steps to put your database in Windows Azure is to put your data on the cloud.

1. The first step is to log in to Azure

1.a) Go to https://windows.azure.com/Cloud/Provisioning/Default.aspx 

1.b)Type your user name and password.

1.c) When your are logged in go to SQL Azure option on the left hand menu.

1.d) You will see a list of your projects. Click on the project.

image

2. You must accept Azure Terms of Use

image

3. Now create a server. You must indicate an administrator username and password. Azure will set the server name.
Press the Create Server button and continue.

image 

4. Now let’s create a new database.Press the Create Database Button

image

5. Just type your database name, edition and size. Editions can be Web or Business.
At this moment Size for Web Edition is 1GB or 5GB and for Business is 10GB, 20GB, 30GB, 40GB and 50GB.
Prices varies according to the options that you select.
For my purposes I will select a Web Edition of 1GB

image

6. You should be able to see your new database in the Databases list.

image

7. Configure Firewall settings so you can connect to the new database.

image

7.1 Press the Allow Microsoft Services access to this server checkbox.
That will add a Rule Name that allows access from 0.0.0.0 to 0.0.0.0.
Select the rule and press Edit. You must can type something like 0.0.0.0 to 255.255.255.255 to allow access to all IP Address.

Moving your data to SQL Azure

The easiest way to upload a SQL Server database to SQL Azure is to use
the SQL Azure Migration Wizard this is a great tool that you can download from
CodePlex http://sqlazuremw.codeplex.com/

1. Download the tool. In my case I installed it in D:\SQLAzureTools. Run SQLAzureMW.exe

image

2. Select SQL Database and press Next

image

3. Select your database and press connect. That will add your database to a list. Click on your database name and press Next

image

4. Select the tables and other object that you will move to your SQL Azure database

image

5. Press Next a Summary is presented with all options

image

 

 

 

6. The wizard will generate a BCP file and a script for your tables.

image

You can connect to run your scripts with the following command:

> sqlcmd -S tcp:<servername>.database.windows.net -U <username>@<servername> -P <password> –d <database>

Depending on your configuration you might have problems with BCP. In general you need something like:

To export data:

bcp PhoneBook out c:\temp\Phonebook-c.dat –S <Server> –T –c

-T  means a trusted connection and native format

To import data

bcp Phonebook.dbo.Phonebook in c:\temp\Phonebook-c.dat -c -U <username>@<servername> -P <Password> -S tcp:<servername>.database.windows.net -c

 

 

 

 

 

 

After importing your data, you are set to keep on developing your applications on Azure

NOTE:

If you dont know the schema name connect to your database and run something like:

SELECT '['+SCHEMA_NAME(schema_id)+'].['+name+']' AS SchemaTable FROM sys.tables

Silverlight for Nokia!! WOW! Just about time

25. October 2010 03:45 by Mrojas in General  //  Tags: , ,   //   Comments (0)

I am a big fan of mobile applications and recently due to our migration activities
(we now offer migrations from VB6 and WinForms to Silverlight)
have been involved with Silverlight programming.

I have done some mobile application development activities
in J2EE and flash and I am now very happy with Silverlight.

What makes me even happier is that I am a Symbian fan and I can now
start developing applications for my Nokia phone with silverlight.

Dont miss it!: http://www.silverlight.net/getstarted/devices/symbian/

 

 

How to restore SQLSERVER .bak file to .mdf

22. October 2010 06:51 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

If you have a .bak file, and all you want is to restore that file to a mdf. Then this is what you can do.

First you need an empty .mdf and .ldf files. The easier way to do that is to create a WebProject in Visual Studio and then In the App_Data folder right click and add new database. That will create an mdf and a .ldf.

Now copy those files to the data directory of your SQLSERVER Express. If it usually under the C:\Program Files\Microsoft SQL Server. In my case it is in C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\

So if your database is PhoneBook just copy:

copy PhoneBook.mdf “C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\PhoneBook.mdf”
copy PhoneBook_log.ldf “C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\PhoneBook_log.ldf”

Now attach your database:

open a Visual Studio 2008 Command Prompt or other prompt (Remember to right click the Run as Administrator, specially if it is Vista)

in the command prompt run:

sqlcmd –S ./SQLEXPRESS

and run the following commands:

CREATE DATABASE Phonebook ON
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Phonebook.mdf' ),
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Phonebook_log.ldf' )
FOR ATTACH ;
GO

copy your .BAK file to the data directory.

copy PhoneBook.bak “C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\PhoneBook.bak”

NOTE: Why the data directory: It seams that in some installation you can have permitions issues

RESTORE DATABASE PhoneBook
FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\PhoneBook2.BAK'
WITH MOVE 'Phonebook' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Phonebook.mdf',
MOVE 'Phonebook_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Phonebook_log.ldf',
REPLACE

After that if everything runs ok then you can detach your database:

1> exec sp_detach_db 'Phonebook'

Now you can copy your mdf files back to where you wanted them

NOTE: If you dont know the name you have to put for Data and Log then Run commands like

RESTORE HEADERONLY FROM DISK ='C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\PhoneBook2.BAK'

RESTORE FILELISTONLY FROM DISK ='C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\PhoneBook2.BAK'

In my case it gives something like:

LogicalName
---------------------------------------------------------------------------------
Phonebook
Phonebook_log

How to create an adding that add context menu for certain files types in Visual Studio

21. October 2010 03:29 by Mrojas in   //  Tags: , , , , , , , , ,   //   Comments (0)

Recently I was looking for a way to create an Adding that will add a Context Menu only when I Right Click on .xaml files.

I know there a many ways now, but I still love using VS studio addins for some simple tasks.

In case you are wondering how to do that 

I found this great article: http://davedewinter.com/2008/03/22/dynamic-menu-commands-in-visual-studio-packages-part-2/

Localization of ASP.NET Login Control

21. October 2010 01:55 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

ASP.NET comes with very nice controls for Login, Password recovery and user creation.

 I have VS 2008 and VS 2010 in English, but I want my application to be available in Spanish and French as well.
If you add your Login control you will see that by default it only shows English captions.
How can you change them?
Well it is very easy.
Just do this:
1. Open your form, the one with the Login Controls.

2. Switch to Design mode

3. Go to the Visual Studio Menus and Select Tools\Generate Local Resource

4. That will generate a new file. That file will be in a directory called App_LocalResources and if your login webform was login.aspx
then the file will be Login.aspx.rexx. Add new pages for you languages like: Login.aspx.es.resx for spanish or Login.aspx.fr.resx for
French.
Behind the scenes, Visual Studio added in the page header a UICulture="auto" attribute.
This tells ASP.net to automatically detect the visitors' prefered language (it's sent in the HTTP headers) and provide them with the
most adequate translation of my page.

In others post I'll give instructions on how to add a languages drop down list to let the user change the displayed language.

Backspace Away!

20. October 2010 03:38 by rencarnacao in General  //  Tags:   //   Comments (0)
Backspace Away!

It’s no wonder why the urge to comment out code that isn’t migrating well and anything outside of the initial automation results - is so strong. It’s like trying to close a suitcase that’s clearly over-stuffed. You want to close it up with everything you originally envisioned packing into it but some stuff just doesn’t seem to fit. In cases like these, it can be difficult to decide what to keep and what to toss out. And like most, traveling light and simple, is preferred. If life’s problems where only a backspace away from being resolved. Don't like your electric bill? Delete it. Neighbor's dog barks too loud at night... well, you get the point.

And so the options that I’ve found myself debating lately have been whether to comment out these lines of code and possibly throw a custom exception or to create a precompiler warning. While both postpone the time at which the possible underlying issues are addressed, they present the developer with completely different opportunities. And only one of them gets you closer to lift off quicker.

Throwing an error at runtime is highly effective at ensuring that possible migration issues are not ignored or missed entirely - especially after your QA team begins testing. The test cases might not produce the necessary conditions for those lines to run and thus give Visual Studio a reason to throw your exception. While they, run-time exceptions, are no longer compile-time errors, they could make their way to the final product - surprising users with potentially bizarre comments and buggy functionality, - like the one below.

   1:  if (confirmPaymentDialogResult == DialogResult.Ok)
   2:      {  
   3:           //CheckoutCart Object is still using the Interop version. 
   4:           //PaymentsFullfillmentObject.ChargeAmout(AxCheckoutCartObject.TotalAmount());
   5:           PaymentsFullfillmentObject.ChargeAndShip();
   6:           throw new Exception("Don't forget to fix this issue!");
   7:       }

However, I think its important that when making modifications to the code like this, it’s critical to look at the context of the user experience and what exactly you’re commenting out. If you’re going to comment out the use of the AxCheckoutCartObject above than it’s probably best to also comment out the ChargeAndShip() method.

One of the problems with this though is that it’s possible to forget about this issue until someone from your QA team throws a hissy fit and demands to know how the module was ever tested. But wait... aren't developers are notoriously awesome testers!?

I’ve noticed since I’ve been working with Artinsoft, that one of the many neat benefits of using the VB Companion is some of the migration code that’s placed in the source code to assist with the migration.

   1:  //UPGRADE_TODO: (1065) Error handling statement (On Error Resume Next) could not be converted.     
   2:  //More Information: http://www.vbtonet.com/ewis/ewi1065.aspx
   3:  Artinsoft.VB6.Utils.NotUpgradedHelper.NotifyNotUpgradedElement("On Error Resume Next");

The example above is taken from an instance where VB Companion actually created and inserted this NotifyNotUpgradedElement() method. What this means is that while you are debugging, you’ll be notified about the conversion issue whenever the application hits that line of code. This offers considerable benefits especially since it allows you to ignore all of those NotifyNotUpgradesElement calls and get back to them later.

So I feel like I’ve talk myself out of using the throw exception and to replace it with the NotifyNotUpgraded() method approach. But I think we can still do more to ensure that issues aren’t missed entirely or caught post-development by your QA team.

I’d like to be notified of these issues regardless of whether the lines are ever executed. So what I’ve discovered recently is the use of the warning directive.

   1:  #warning Artinsoft: Connection mode should be set to 'ModeRead'.

This will show up between the error list and the information list tabs. We just need to remember to check these warnings.

 

So now, if we incorporate the warning directive and the NotifyNotUpgradedElement() call then the “throw Exception” really isn’t needed any longer and we’ll increase the likelihood of remembering to go back addresses issues that were tabled for whatever reason.

So the previous code example might end up looking like this:

   1:  if (confirmPaymentDialogResult == DialogResult.Ok)
   2:      {  
   3:           //CheckoutCart Object is still using the Interop version. 
   4:           //PaymentsFullfillmentObject.ChargeAmout(AxCheckoutCartObject.TotalAmount());
   5:           Artinsoft.VB6.Utils.NotUpgradedHelper
      .NotifyNotUpgradedElement("AxCheckoutCartObject.TotalAmount()");
   6:  #warning Artinsoft: PaymentsFullfillmentObject.ChargeAndShip()
            needs to be replaced with .Net equivalent.
   7:           PaymentsFullfillmentObject.ChargeAndShip();
   8:       }

This approach provides three benefits. It allows the developer to comment out lines of code that are throwing exceptions during compilation or debugging without worry about forgetting about them. This in turn will get the migrated application up and running quicker. Additionally, during each debugging session, it optionally allows the developer to see each issue as the application encounters them or skip over all of them completely. And finally, while compiling, it provides a list of these issues as warnings in the error list tab.

This approach is proving to be quite useful.

What is the ClientBin folder?

16. October 2010 16:25 by Mrojas in General  //  Tags: ,   //   Comments (0)
Silverlight applications are packaged as .xap files. Those files must be keep in your web application. The default directory that is used for that is the ClientBin folder. So if you have silverlight applications associated to your web project their .xap files should go there.

Of Object Model Mutation Taxonomies

12. October 2010 01:32 by rencarnacao in General  //  Tags:   //   Comments (0)

I don’t have many months worth of experience with software migrations as a dedicated profession, per se, but I have been doing them on and off for well over a decade in some technical capacity - mostly as a software developer or architect. The one thing that has struck me as, perhaps, the most perplexing aspect of migration, at least at the micro level, is when you come across 3rd-party components that have a solid .Net version available but their interface has changed in a destructive fashion from their latest COM version.

Typically, I think of interface changes as being either destructive or non-destructive. Newly 'dot-net-ized' components that merely have namespace changes or changes to the names of their methods or properties as being 'linear' - essentially one-to-one. While at the same time, the component may offer additional method signatures, new methods or functionality entirely. I consider this to be 'expansive' or 'progressive'. The newly release versions may indicate that certain members are being deprecated but that support still exists for the time being. In all cases, these are non-destructive.

On the other hand, destructive mutations are ones where support for particular functionality is dropped entirely, either by a non-backwards-compatible offering of method signatures and/or the removal methods or properties entirely. Perhaps a term like 'abandonment' or 'orphaned' works well. Or worse yet, destructive mutations can encompass changes where the re-architecting of an application becomes necessary because objects in the application’s architecture are shifted around in the models hierarchy or object responsibility. I refer to this as 'mutinous' or 'violent'. Some of the ADODB examples are destructive in this way. I like to think of this type of destructive.

I often think back to my initiation in object model programming and I have never been able to forget the expression, 'commitment'. The idea was that the public interface of component was a sort of commitment to the applications that consume them and especially a commitment to the developers that implant them into their applications. The publishers of these components were never ever supposed to falter on this commitment. At least, that’s what I thought while this couldn’t be further from reality.

In the past few weeks, I’ve seen lots of destructive component evolutions. The examples that I’ve come across include Crystal Reports and Microsoft’s ADODB. And while I say a lot, I am referring to more than one or two, - where there’s a lot of pondering and little evidence in so far as what to do with certain VB6 calls when porting over to C#. What surprises me the most though is how really lacking migration assistance is from COM to .Net versions of these components! While I can appreciate the need to deprecate features and methods from time to time as a way to 'evolve' the application but why not at least provide some backward compatibility or hints as to what to do with the deprecated members.

While it's wonderful that developers have considerably more control and ease in handling binary data in .Net, it is frustrating when a method with one argument, like AppendChunk() from ADODB, mutates into a half-dozen lines. It just doesn’t feel like evolution.

VB6, simple:

   1:  recordsetObject1("binaryData").AppendChunk recordsetObject2("binaryData") 

C#, not so simple:

   1:  byte[] chunk1 = (byte[])recordsetObject1["binaryData"];
   2:  byte[] chunk2 = (byte[])recordsetObject2["binaryData"];
   3:  byte[] chunkFinal = new byte[chunk1.Length + chunk2.Length];
   4:  System.Buffer.BlockCopy(chunk1, 0, chunkFinal, 0, chunk1.Length);
   5:  System.Buffer.BlockCopy(chunk2, 0, chunkFinal, chunk1.Length+1, chunk2.Length);
   6:  recordsetObject1["binaryData"] = chunkFinal;

Certainly, I could have reduced the migration solution by 2 lines. Yuck!

   1:  byte[] chunkFinal = new byte[((byte[])recordsetObject1["binaryData"]).Length +  
     ((byte[])recordsetObject2["binaryData"]).Length];
   2:  System.Buffer.BlockCopy(((byte[])recordsetObject1["binaryData"]), 0, chunkFinal, 0, 
     ((byte[])recordsetObject1["binaryData"]).Length); 
   3:  System.Buffer.BlockCopy(((byte[])recordsetObject2["binaryData"]), 0, chunkFinal,
     ((byte[])recordsetObject1["binaryData"]).Length+1, ((byte[])recordsetObject2["binaryData"]).Length); 
   4:  recordsetObject1["binaryData"] = chunkFinal;

As it turns out, Microsoft did a twisted thing with this AppendChunk() function. According to the MSDN website, the first AppendChunk call on a Field object writes data to the field, overwriting any existing data and subsequent AppendChunk calls add to existing data. Ugh!

Other ADODB examples include the property ADODBRecordSet.CursorType and method ADODBRecordSet.Open( ) - where they dropped the signature with CursorTypeEnum, property ADODBConnection.IsolationLevel( ) and property ADODBConnection.Mode( ).

Changes like these last three are particularly manageable because the developer can perform the same tasks just fine. While I don’t like to have to type more than necessary (when it comes to coding, I’m quite lazy!) , this type of destructive migration challenge I can live. It’s solvable and we get past them quickly. What drives me nuts are the violent changes to 3rd party components!

So Crystal Reports has had quite an impressive following since the early 90’s. With the marriage of IT and Enterprise Reporting, the demand grew and grew. Let’s see - Crystal Services is acquired by Holistic Systems is bought by Seagate Software which is quickly rebranded to Crystal Decisions bought by Business Objects and folded into SAP, alas - in 2007. Is it any wonder that the component(s) has undergone mutinous changes?

The latest COM version of Crystal Decisions supports a number of Report Viewer events, such as DownloadFinished( ). Where did it go in the latest .Net version? Who knows! Oh, the funny thing here is that the .Net Crystal Decisions report still uses the COM-based AxWebBrowser component. We’ll just let that go. To be fair to SAP, even Microsoft has been slow to replace that component. Anyhow, I don’t blame SAP for tossing a bunch of that component out. It’s quite bloated. In fact, it’s kind of funny. In my experiences, predominantly in the Web arena, I’ve never had a need for Crystal Reports. After having worked with it - well, let’s just say I’m surprised it doesn’t offer a different licensing model.

That’s a topic for another time.

20 questions your Code Conversion partner better have a good answer for: If they don't, you need to find another partner

23. July 2010 13:16 by Fzoufaly in General  //  Tags: , , ,   //   Comments (0)

I recently found this interesting list of questions on the Datatek Inc. website. I enjoyed answering them and I want to share ArtinSoft’s answers.

Go ahead and judge for yourself if ArtinSoft is the right partner for your VB6 migration projects.

Q1: If you are manually converting the code, how many different programmers will be converting the code and how are you ensuring consistency and accuracy?

A1: ArtinSoft does not execute manual migration projects. However, there is always a percentage of code that requires manual adjustments. All the team members in a migration project follow the same coding standards to ensure a high level of consistency in the manual changes. If a certain issue is detected multiple times in the source code, its fixing will be implemented in the automatic migration process.

Q2: If this is a manual conversion, how do you minimize the issue of bugs being introduced by each and every programmer, which will have to be found individually during testing?

A2: Most of the work is performed by an automatic migration tool. People working in a migration project share a Knowledge Base where they record every manual change they perform. This knowledge sharing process minimizes the number of bugs introduced by programmers.

Q3: If you are automatically converting the code, what percentage is automated and what percentage is manual?

A3: The percentage of automatic code migration changes depending on the source/target platform. For example, in the case of Visual Basic 6 to .NET automation reaches 95% of the actual lines of code. This level of automation ensures consistency in the quality of the generated code.

Q4: Our programmers still need to make modifications to our code in order to support ongoing business requirements. Is there a “code freeze” and how long is it?

A4: ArtinSoft understands that software applications are ever evolving creatures. We have developed a mechanism where it is easy to incorporate changes during a migration process, we call it continuous migration. This process minimizes the code freeze period to the last acceptance testing phase of a project.

Q5: When we receive the converted code back from you, are we required to make any changes in order for it to be functional?

A5: When ArtinSoft bids on a functional equivalence migration project, the code that is delivered is ready for deployment.

Q6: Is the converted code guaranteed to compile?

A6: In a functional equivalence project, the code not only compiles, it runs!

Q7: Once the code compiles, do you just hand responsibility over to us or are you responsible for problems found during testing?

A7: NO! (See answer 6!)

Q8: What are we, the customer, specifically responsible for during the conversion project?

A8: The customer is mainly responsible for the testing of the project. This responsibility starts with the creation and delivery of test cases to ArtinSoft and ends with final project acceptance. The testing workflow is the main path of communication between the teams. This process ensures that project expectations are clearly set up front and is key to the success rate of the project.

Q9: Can our coding standards be applied to the converted code?

A9: Our migration tool can be customized to include the application of your coding standards. Coding standards are identified and agreed upon during the initial phase of the project.

Q10: What kinds of customizations can we make to the converted code?

A10: ArtinSoft delivers code that is completely standard to the target platform. There are no dependencies on ArtinSoft or any strange “programming behavior”. Any programmer that is fluent in the target platform is able to understand and evolve the generated code. This ensures that your application really gets a new life under the new platform.

Q11: How maintainable is the converted code? How long have other customers stayed on code you have converted for them?

A11: The generated code is fully maintainable. Our customers continue to use and modify it long after it has been converted.

Q12: What happens if we don’t like how certain pieces of the code got converted?

A12: This can be approached at to different moments: before the migration stats or during the evolution phase of the application. Before the migration start, the conversion tool or the migration process can be customized to change its behavior according to your coding preferences. During the evolution phase, since the application is written in standard maintainable source code, it can be evolved using your normal software development process.

Q13: What happens if our code inadvertently makes use of undocumented features? Will you support that functionality?

A13: Yes! ArtinSoft guarantees functional equivalence. If it worked before, it should work after the conversion.

Q14: What happens if we have existing bugs in our code that run fine on our current platform (such as uninitialized variables). Are you responsible for making sure that everything works like it did on the old platform?

A14: Yes! ArtinSoft guarantees functional equivalence.

Q15: Can we get a fixed price contract for the conversion?

A15: Absolutely. The great majority of ArtinSoft projects are executed on a fixed price & fixed time basis. Our Ready™ assessment methodology together with our experience allows us to minimize the risk for our clients.

Q16: Are there any runtime charges for any support code and/or libraries you supply? Do we have ownership rights to this code?

A16: An important element in our philosophy is to minimize the amount of necessary support code. Code should be converted to its “native” counterpart as much as possible. In case a support class is needed, the client will have full access to the source code and absolute independence from ArtinSoft moving forward.

Q17: How are we charged if we miss giving you a file after you have already started the conversion?

A18: ArtinSoft always include a price per line of code that can be used for adding/subtracting code from a migration project during its execution. Clients will always know beforehand how much additional work is going to cost.

Q18: How long does the conversion take?

A18: Each project is different. Typically, project length is a function of the size of the source code. ArtinSoft always insists on performing an assessment before the start of the project that will clearly state the required effort to successfully complete the migration.

Q19: What type of guarantees do you provide?

A19: ArtinSoft guarantees functional equivalence between the source and converted code. We typically include a guarantee period when clients can report bugs after project acceptance and ArtinSoft is responsible to fix them.

Q20: How long have you been doing code conversions?

A20: ArtinSoft has been doing automated code conversions since 1993 (we’re about to reach legal age!). In fact, ArtinSoft was founded on the premise that source code should be freed from its platform dependencies. Since day one, we’ve been applying our Artificial Intelligence research to providing cost-effective and low risk solution to code migrations. Companies choose ArtinSoft for our proven experience and comprehensive methodology.

Webcast: Visual Studio 2010 Ecosystem Series: Upgrading Applications from Visual Basic 6 to Visual Studio 2010

5. July 2010 05:26 by Jaguilar in General  //  Tags: , ,   //   Comments (0)

A quick post to let you all know that Paul Yuknewicz, Senior Program Manager on the VB Team, and myself will be presenting a webcast on upgrading VB6.0 applications to Visual Studio 2010, this Thursday at 9am PST. Here are some details on the event:


Title: MSDN Webcast: Visual Studio 2010 Ecosystem Series: Upgrading Applications from Visual Basic 6 to Visual Studio 2010 (Level 200)


Summary: Attend this webcast to discover how to use the latest version of ArtinSoft's Visual Basic Upgrade Companion (VBUC) to easily migrate applications developed in Microsoft Visual Basic 6 to both Microsoft Visual Basic .NET and C# using the Microsoft Visual Studio 2010 development system. Now that the Upgrade Wizard no longer ships with Visual Studio, the VBUC provides a more powerful and flexible alternative to cost-effectively upgrade your applications to .NET, take advantage of the latest technology, and streamline your development process.


Event link


 

Interop: BinaryCompatibilty for VB6 Migrations

In VB6 when you have an ActiveX Library it was very important to use
the BinaryCompatibility setting to make sure that your applications did not break after a change.

So let’s first introduce what is binary compatibility and how to accomplish that in .NET.

Binary Compatibility allows to make changes to your components or COM classes without recompiling
every application you've made that uses the component.
And why do you need it. Why compatibility breaks.
On lets see.

An ActiveX Control or DLL expose Public interfaces.
Those interfaces have all of the properties, methods, events, etc. that you've marked as Public.
In other words, everything you've added that shows in Intellisense while working outside of your component.

Now let's say you have create a class, with two Methods Method1 and Method2

When you compile, VB generates all the COM infraestructure you need for your component.
It defines a CoClass and an interface and an entry for each method.

For a vb class with two methods:

Sub Method1()

End Sub

Sub Method2()

End Sub

It will produce a typelib like:

// Generated .IDL file (by the OLE/COM Object Viewer)
// 
// typelib filename: <could not determine filename>
[
  uuid(8ABA2C0C-7CCA-40CD-A944-56707566634A),
  version(1.0)
]
library Project1
{
    // TLib :     // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
    importlib("stdole2.tlb");

    // Forward declare all types defined in this typelib
    interface _Class1;

    [
      odl,
      uuid(6B86684C-B3DD-4680-BF95-8DEE2C17AF5B),
      version(1.0),
      hidden,
      dual,
      nonextensible,
      oleautomation
    ]
    interface _Class1 : IDispatch {
        [id(0x60030000)]
        HRESULT Method1();
        [id(0x60030001)]
        HRESULT Method2();
    };

    [
      uuid(C71C7AB0-552A-4D5D-A9FB-AF33830A697E),
      version(1.0)
    ]
    coclass Class1 {
        [default] interface _Class1;
    };
};

As you can see in the typelib there are IDs associated to each coclass, interface and
methods. Those IDs are the ones use when you generate the .exe file for your application.
Now if you modify your Class to:

 

Sub Method3()

End Sub

Sub Method4()

End Sub

Sub Method1()

End Sub

Sub Method2()

End Sub

and you use No Compatibility the typelib after your changes will be:

// Generated .IDL file (by the OLE/COM Object Viewer)
// 
// typelib filename: <could not determine filename>

[
  uuid(FE5C56C2-E03A-4DC0-994D-B68543C72A46),
  version(1.0)
]
library Project1
{
    // TLib :     // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
    importlib("stdole2.tlb");

    // Forward declare all types defined in this typelib
    interface _Class1;

    [
      odl,
      uuid(A3032E1E-52FE-42E0-98FF-84A9DD4FD8C3),
      version(1.0),
      hidden,
      dual,
      nonextensible,
      oleautomation
    ]
    interface _Class1 : IDispatch {
        [id(0x60030000)]
        HRESULT Method3();
        [id(0x60030001)]
        HRESULT Method4();
        [id(0x60030002)]
        HRESULT Method1();
        [id(0x60030003)]
        HRESULT Method2();
    };

    [
      uuid(72721504-CC56-4BB9-9447-C7193FE8C02D),
      version(1.0)
    ]
    coclass Class1 {
        [default] interface _Class1;
    };
};

As you can see, now the ids for the methods, CoClass are different, so your applications will return errors like: Error 430 (Automation error, the component dies horribly) or Error 429 (can't create the object at all)

But if you instead used BinaryCompatibility then the typelib for your class will be:

// Generated .IDL file (by the OLE/COM Object Viewer)
// 
// typelib filename: <could not determine filename>
[
  uuid(8ABA2C0C-7CCA-40CD-A944-56707566634A),
  version(1.1)
]
library Project1
{
    // TLib :     // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
    importlib("stdole2.tlb");

    // Forward declare all types defined in this typelib
    interface _Class1;
    [
      odl,
      uuid(6E9C59C3-82D7-444C-92FB-01B49D91A2FF),
      version(1.1),
      hidden,
      dual,
      nonextensible,
      oleautomation
    ]
    interface _Class1 : IDispatch {
        [id(0x60030002)]
        HRESULT Method3();
        [id(0x60030003)]
        HRESULT Method4();
        [id(0x60030000)]
        HRESULT Method1();
        [id(0x60030001)]
        HRESULT Method2();
    };

    [
      uuid(C71C7AB0-552A-4D5D-A9FB-AF33830A697E),
      version(1.1)
    ]
    coclass Class1 {
        [default] interface _Class1;
    };

    typedef [uuid(6B86684C-B3DD-4680-BF95-8DEE2C17AF5B), version(1.0), public]
    _Class1 Class1___v0;
};

If you compare now the two typelibs you can see the Method1 and Method2 keep the same ids.

For each version a typedef is generated that will point to the last version. For example adding a Method5 will add new entry like:


    typedef [uuid(6B86684C-B3DD-4680-BF95-8DEE2C17AF5B), version(1.0), public]
    _Class1 Class1___v0;

    typedef [uuid(6E9C59C3-82D7-444C-92FB-01B49D91A2FF), version(1.1), public]
    _Class1 Class1___v1;

Well that is what binary compatibility does. Now how to achieve binary compatibility in .NET

Binary Compatibility in .NET

Achieving binary compatibility in .NET is really easy. You just need to give more information to
make explicit how your typelib information will be. I will follow an approach as the one I already explained in this post:
http://blogs.artinsoft.net/mrojas/archive/2010/06/23/exposing-c-classes-thru-interop.aspx

Lets take our previous example:

using System;
using System.Runtime.InteropServices;

namespace InteropExamples
{
    public class Class1
    {
        public void Method3()
        {
        }
        public void Method4()
        {
        }
        public void Method1()
        {
        }
        public void Method2()
        {
        }
        public void Method5()
        {
        }
    }
}

In previous posts I had recommended using partial classes and using interfaces to explicitly specify what you what to be seen in COM. This means you start up with something like:

  public partial class Class1
    {
        public void Method3()
        {
        }
        public void Method4()
        {
        }
        public void Method1()
        {
        }
        public void Method2()
        {
        }
    }

    [ComVisible(true)]
    public interface _Class1
    {
        void Method3();
        void Method4();
        void Method1();
        void Method2();

    }
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    [ComDefaultInterface(typeof(_Class1))]
    partial class Class1 : _Class1
    {
        #region _Class1 Members

        void _Class1.Method3()
        {
            Method3();
        }

        void _Class1.Method4()
        {
            Method4();
        }

        void _Class1.Method1()
        {
            Method1();
        }

        void _Class1.Method2()
        {
            Method2();
        }

        #endregion
    }

Now to make this code binary compatible then you have to make sure that the tlb file generated for your class is almost identical to that generated before. To acomplish that we must make sure that we your methods, interfaces and classes have the same guids and ids. Lets see how:

using System;
using System.Runtime.InteropServices;

namespace InteropExamples
{
    public partial class Class1
    {

        public void Method3()
        {
            System.Windows.Forms.MessageBox.Show("3 N");
        }

        public void Method4()
        {
            System.Windows.Forms.MessageBox.Show("4 N");
        }

        public void Method5()
        {
            System.Windows.Forms.MessageBox.Show("5 N");
        }


        public void Method1()
        {
            System.Windows.Forms.MessageBox.Show("1 N");
        }

        public void Method2()
        {
            System.Windows.Forms.MessageBox.Show("2 N");
        }
    }

    [ComVisible(true)] //This to make the interface Visible for COM
    [TypeLibType((TypeLibTypeFlags)((short)TypeLibTypeFlags.FHidden |
        (short)TypeLibTypeFlags.FDual |
        (short)TypeLibTypeFlags.FNonExtensible |
        (short)TypeLibTypeFlags.FOleAutomation))] //This to use the same flags as in previous tlb
    [Guid("9BAFD76D-8E6B-439C-8B6D-37260BFA3317")] //This is to make the class have the guid
    public interface _Class1
    {
        [DispId(0x60030000)]
        void Method1();
        [DispId(0x60030001)]
        void Method2();
        [DispId(0x60030002)]
        void Method3();
        [DispId(0x60030003)]
        void Method4();
        [DispId(0x60030004)]
        void Method5();


    }

    [ComVisible(true)] //This to make the class Visible for COM
    [ClassInterface(ClassInterfaceType.None)] //This is to make sure that we have control on interface generation
    [ComDefaultInterface(typeof(_Class1))] //To set default interface
    [ProgId("Project1.Class1")] //To set ProgId 
    [Guid("C71C7AB0-552A-4D5D-A9FB-AF33830A697E")] //Maintain same Guid.
    partial class Class1 : _Class1, Class1___v0, Class1___v1
    {
        #region _Class1 Members

        void _Class1.Method3()
        {
            Method3();
        }

        void _Class1.Method4()
        {
            Method4();
        }

        void _Class1.Method1()
        {
            Method1();
        }

        void _Class1.Method2()
        {
            Method2();
        }

        #endregion


        #region Class1___v0 Members

        void Class1___v0.Method1()
        {
            Method1();
        }

        void Class1___v0.Method2()
        {
            Method2();
        }

        void Class1___v0.Method3()
        {
            Method3();
        }

        void Class1___v0.Method4()
        {
            Method4();
        }

        void Class1___v0.Method5()
        {
            Method5();
        }

        #endregion

        #region Class1___v1 Members

        void Class1___v1.Method1()
        {
            Method1();
        }

        void Class1___v1.Method2()
        {
            Method2();
        }

        void Class1___v1.Method3()
        {
            Method3();
        }

        void Class1___v1.Method4()
        {
            Method4();
        }

        void Class1___v1.Method5()
        {
            Method5();
        }

        #endregion
    }

    //This is to keep compatibility with old versions
    //we cannot generate a typedef so we will need to add all of the versions
    //for BinaryCompatibility
    [ComVisible(true)]
    [Guid("6B86684C-B3DD-4680-BF95-8DEE2C17AF5B")]
    [TypeLibType(TypeLibTypeFlags.FHidden)]
    public interface Class1___v0
    {
        [DispId(0x60030000)]
        void Method1();
        [DispId(0x60030001)]
        void Method2();
        [DispId(0x60030002)]
        void Method3();
        [DispId(0x60030003)]
        void Method4();
        [DispId(0x60030004)]
        void Method5();
    }

    //This is to keep compatibility with old versions
    //we cannot generate a typedef so we will need to add all of the versions
    //for BinaryCompatibility
    [ComVisible(true)]
    [Guid("4A7A3317-BF13-443E-9DB0-2C5EA21F00CA")]
    [TypeLibType(TypeLibTypeFlags.FHidden)]
    public interface Class1___v1
    {
        [DispId(0x60030000)]
        void Method1();
        [DispId(0x60030001)]
        void Method2();
        [DispId(0x60030002)]
        void Method3();
        [DispId(0x60030003)]
        void Method4();
        [DispId(0x60030004)]
        void Method5();
    }

}

Sadly in .NET you cannot use Interface Inheritance in COM. If there is interface inheritance YOU HAVE TO IMPLEMENT each interface. In the case of code that comes from VB6. VB6 just uses typedefs, so you really don’t know which methods belong to each version. So in the end all versions have all methods.

The other alternative to this method, is just to implement last version. And after generating the tlb, decompile it to an .IDL file add the typedefs and recompiled it. I explained something similar in this post:http://blogs.artinsoft.net/mrojas/archive/2010/05/17/interop-remove-prefix-from-c-enums-for-com.aspx

Ok. I hope this helps you to have an more clear idea of what Binary Compatibility is and how to do it in .NET. I am attaching some sample code. It show an ActiveX library that uses BinaryCompatibility and three version on an aplications that uses the different versions. And also a .NET class library that is equivalent to the VB6 one. HERE

Enjoy.

Categories