Move code from .vb to .Designer.vb

18. January 2013 16:00 by Mrojas in   //  Tags: , , , , , , , ,   //   Comments (0)

If you still have Visual Studio 2003 projects and you are just in the process of upgrading / modernizing them, then the following addin will be very helpful. Mike Meinz, took a very useful macro and package it as a VS 2012 addin


For us who each day move lots of code from Vb6 and VB.NET to MVVM. ASP.NET MVC, etc, this kind of tools become very handy.





Use Crystal Reports in VS2010

10. October 2012 08:28 by Mrojas in   //  Tags: , , ,   //   Comments (0)

Crystal Reports was a tool very used by VB6 developers.

Sometimes when you are migrating a VB6 applications, you find a lot of reports created with this tool.

What should you do? Should you rewrite them on another technology?

Well that really depends on project requirements, but Crystal Reports has good support for VS2010, both for 32 and 64 bit environments.

So you don't need to throw away your reports you can still use Crystal Reports.

However that hard thing to do is where to find Crystal Reports for VS. Do you need to buy some software for that?

I have found that you can download Crystal Reports for VS2010 is just that the links are a little hidden. My friend Victor send me the following information which has been very useful for this task:



a) For Deployment Environment:
1. Download the Redistributable Package for Visual Studio  according to the platform (32 bits or 64 bits).  And install it. You will find the installer in the following link:
2. Give access to the user executing the IIS process to the path for the Temp Folder (C:\Windows\Temp or the corresponding folder on windows installation).
3. Download the "Microsoft SQL Server 2008 Feature Pack", where you can find the "Microsoft SQL Server 2008 Native Client ". Download the corresponding installer according to the platform of the server (x86, x64 or IA64).
b) For Development environment:
1. Download the "Complete Package" for development on Visual Studio 2010. Please be sure that if you're on a 64 bits machine, you check the "Install 64 bits Runtime" before you click on finish when you complete the installation.
2. Be sure that the current user running on your machine has access to the Temp Folder (C:\Windows\Temp or the corresponding folder on windows installation)
3. If you don't have the Microsoft SQL Server 2008 Native Client Provider (sqlncli10),  download the "Microsoft SQL Server 2008 Feature Pack", where you can find the "Microsoft SQL Server 2008 Native Client ". Download the corresponding installer according to the platform of the server (x86, x64 or IA64).
4. To create a new report please be sure you use a "OLE DB (ADO)" Connection and that you're using the "SQL Server Native Client 10.0" Provider, and use the right login information. If the report was previously created with a different provider, please change it on the "Set Datasource Location", editing the Provider field.

CommandBarControl Click Event is not Working!!!!

2. September 2012 00:15 by Mrojas in   //  Tags: , , , , ,   //   Comments (0)

Today I was doing a VS extention as part of my weekend relaxation activities ;)

Everything was great until succendly something was not happening as I expected.

 I was adding a context menu to the code window with a dynamic list of options.

And each option had a different click delegate, but my click events were

disrespectfully discarted.

 Luckily I found this post:

 And now for a tricky part: since you ge\t your instance of CommandBarEvents inside the scope of a method, when the method ends, the Garbage Collector collects it, leaving all the event handlers orphaned. Unless you keep your instance safe from the jaws of the mighty Garbage Collector, your buttons will not respond to clicks.

To do so, just keep your CommandBarEvents instance(s) as member fields of your class. Once your class is disposed, they will be disposed as well.

 Thanks Rauchy you saved my day! (And my wife is happy because I'm finally getting out of the bathroom :P)

Share Code between Silverlight, Winforms and even Metro: Portable Library Tools

26. April 2012 09:33 by Mrojas in   //  Tags: , , , , , , , ,   //   Comments (0)

Maybe you faced the situation where you had code that was to be used on your server side services and also on your silverlight clients. 
Having this situation required some tricks because Silverlight Class libraries could not be used on .NET projects and viceversa.
Common workarounds were to share files and use precompilation directive iack!!

Well VS 2011 has a concept called Portable Class Libraries which allow you to create class libraries that can be use in Windows Phone, Silverlight, .NET framework, etc.

And if you have VS 2010 you don't have to suffer. Just use the Portable Library Tools from from the VS Extensions and start sharing code (see this image form the VS Extensions site)



For more details about Portable Libraries check the MSDN documentation page:


Can I Install Roslyn in Windows XP?

4. January 2012 14:26 by Mrojas in   //  Tags: ,   //   Comments (0)

Yes, you can.

The only thing that you will need is to copy the sqmapi.dll file that you can find in either: C:\Program Files\Microsoft Visual Studio 10.0\Microsoft Visual Studio 2010 Ultimate - ENU or C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE. as quoted in:

Also make sure to have installed Visual Studio 2010 SP1 ans VS SDK SP1


Web Standards Update not working after install

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

If you were looking for HTML5 and CSS3 support, web standards update is a great choice.

However this install tool does not work if you installation is not in the defualt Visual Studio directory:
C:\Program Files\Microsoft Visual Studio 10.0\Common7

One way to fix it is to run the Web Standard update and after the update look for the default dir:

C:\Program Files\Microsoft Visual Studio 10.0\Common7

and copy and merge its contents in your current instalation directory

Profiling Silverlight Applications with Visual Studio 2010

5. October 2011 11:11 by Mrojas in   //  Tags: , , , , ,   //   Comments (0)

The VS Profiler Team has an excellent post teaching how to use the VS2010 profiler with Silverlight Applications.

The steps are simple.

Run the A Visual Studio Command Prompt

And follow these steps:

  1. VSPerfClrEnv /sampleon
  2. "c:\Program Files (x86)\Internet Explorer\iexplore.exe" C:\Breakout\Breakout\Bin\Release\TestPage.html
  3. VSPerfCmd /start:sample /output:MyFile /attach:<PID of iexplore.exe process>
  4. Run your scenario
  5. VSPerfCmd /detach
  6. VSPerfCmd /shutdown
  7. VSPerfClrEnv /off

NOTE: information reposted from

When the finish you will have a file called MyFile.vsp and just open that with VS2010.

Setting the Default Printer in .NET

The following C# code shows how to use WMI to query printers information, set and get default printer.
public bool SetDefaultPrinter()
    System.Management.ManagementObjectSearcher search = 
default(System.Management.ManagementObjectSearcher); System.Management.ManagementObjectCollection results =
default(System.Management.ManagementObjectCollection); System.Management.ManagementObject printer =
default(System.Management.ManagementObject); search =
new System.Management.ManagementObjectSearcher("select * from win32_printer"); results = search.Get(); //Get Default Printer System.Management.ManagementObject defaultPrinter = null; foreach (System.Management.ManagementObject foundPrinter in results) { System.Management.PropertyDataCollection
propertyDataCollection = foundPrinter.Properties; if ((bool)foundPrinter["Default"]) // DEFAULT PRINTER { System.Diagnostics.Debug.WriteLine(foundPrinter["Name"]); System.Diagnostics.Debug.WriteLine(foundPrinter["Location"]); } } //Sets new default Printer foreach (System.Management.ManagementObject foundPrinter in results) { System.Diagnostics.Debug.Print(foundPrinter["Name"].ToString()); if (foundPrinter["Name"].Equals("PDFCreator")) { System.Management.ManagementBaseObject outParams =
foundPrinter.InvokeMethod("SetDefaultPrinter", null, null); if (outParams == null) System.Diagnostics.Debug.WriteLine("Unable to set default printer"); Int32 retVal = (int)(uint)outParams.Properties["ReturnValue"].Value; if (retVal == 0) return true; else return false; } } return false; }

Program database manager mismatch

21. June 2011 08:58 by Mrojas in General  //  Tags: , , , , , , ,   //   Comments (0)

I was playing around with dumpbin trying to figure out some problems with a 32-bit dll and in order to make
dumpbin run from the command line I just copied the mspdb100.dll file to
C:\Program Files\Microsoft Visual Studio 10.0\VC\bin>

Something simple right! No harm can be gotten from something like that? WRONG!!!

After that some of my C++ project stop compiling with the annoying message: Program database manager mismatch!!.

Luckily I remembered copying that file, so I just gave it a try, and guest what? Everything works fine now.

Well I’m posting it just a reminder that for VS C++ you must put attention on all the details Smile

Interop Structures to UnManaged Dlls

For VB6 applications it is common to rely on OS or Kernel API Calls. Some of those APIs might
need you to send data back and for the native API.

Marshalling in .NET can be complicated and bothersome. I have published several posts about
interop. But it usually depends on adding several marshalling attributes and even tricks specially for
fixed strings.

So I decided to provide a more a simpler approach for conversion. In this approach you just need to things:

1. Your VB6 types or structs will be mapped to .NET classes
2. All VB6 type or struct fields will be mapped to public fields
3. An attribute must be used on those fields to indicate the field length, for arrays or strings.
4. Extension methods .AsString() .SetFromString and .GetClassLength will handle all the complexities of setting the struct fields.

Let’s see an example:

Type EmployeeRecord
    FirstName As String * 5
    LastName As String * 5
End Type

That vb6 type will be mapped in .NET following this approach to:

    public class EmployeeRecord 
        public string FirstName = "Mau";
        public string LastName = "Rojas";


You can then simple use that class in .NET

var emp = new EmployeeRecord {FirstName="Mauricio",LastName="Rojas"} ;
var str = emp.AsString();
//This str value will be "MauriRojas" the helper extension methods
// .AsString and .SetFromString will handle setting the internal class fields

All that is very good but how is this used in Marshalling?? Well very simple. Let’s say you have a Dll called foo.dll
with a function foo that receives an EmployeeRecord:

        public static extern int foo(IntPtr Struct);

Then if you want to call that function you will do something like:

            var emp = new EmployeeRecord { FirstName="Ann",LastName="Smith"};
            string str = emp.AsString();
            var ptr = IntPtr.Zero;
            ptr = Marshal.StringToBSTR(str);
            ptr = Marshal.StringToHGlobalAnsi(str);
            ptr = Marshal.StringToHGlobalAuto(str);
            ptr = Marshal.StringToHGlobalUni(str);

            //And call the native function

If the function modifies the structure and you want to reflect those changes then you will do something like:

str = Marshal.PtrToStringAnsi(ptr,typeof(EmployeeRecord).GetClassLength())

This solution can also be applied for more complex structures. For example:

    public class EmployeeRecord 
        public string FirstName = "Mau";
        public string LastName = "Rojas";


    public class Record1
        public int field1;
        public string field2 = "";
        public EmployeeRecord rec = new EmployeeRecord();

    public class GeneralInfo
        public int field1;
        public String[] countrycodes = { "cr","es","mx","pa","ni"};
        public EmployeeRecord[] employees;

If you want to try it out this is the link to the CODE

Silverlight: Error HRESULT E_FAIL has been returned from a call to a COM component

23. March 2011 05:05 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)

While developing some user controls in Silverlight I have come with a situation,
for example when dragging a Chart control in the Visual Studio 2010 designer where I get something like:

Error HRESULT E_FAIL has been returned from a call to a COM component

I have been looking for a solution but have not found anything yet.
The only workaround has been:  
a) Close all windows. Do a Clean and a Rebuild or Close Visual Studio and open it again.

Split Config files in several files

6. January 2011 10:25 by Mrojas in General  //  Tags: , ,   //   Comments (0)

In .NET Framework 2.0 the attribute configSource was added to several elements of the .NET config files so you could use external files.

Sadly those attribute are not available for the system.serviceModel.However I found this post that shows a interesting workaround.

You can modify your serviceModel file to look like this:

    <services configSource="Services.config" >
    <bindings configSource="Bindings.config">
    <behaviors configSource="Behaviors.config">

And then you can put your configuration settings in separate files like the following:


    <services configSource="Services.config" >
    <bindings configSource="Bindings.config">
    <behaviors configSource="Behaviors.config">

For more details see the full post by Pablo Cibraro

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.


4. Press OK

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

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.



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




And then select



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:

Code compiles but System.IO.FileNotFound Exception is thrown

2. October 2009 10:04 by Mrojas in General  //  Tags: , , , , , , ,   //   Comments (0)

We have seen a situation that can be a little annoying.
I usually find that situation in ASP.NET projects, but it can also happen in Winforms.

The issue is like this:

  • You have a VStudio Solution
  • You have added all the needed references
  • All your code compiles



When you run the application it terminates at a certain point with a
FileNotFound exception indicating that the assembly blablabla  or one of its
dependencies could not be loaded.


Whats hapenning!!!

Do this:

1) Look at the bin\debug or bin\release and make sure that the assembly is in those directories.

2) If the assembly is not there, then go to the project references in the solution explorer, right click and select properties and set the Copy Local Setting



Where is my DXCore

19. August 2009 05:06 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)

I’m an enthusiastic user of DXCore and I have been working on some extensions of my own. But I could not find the DXCore or DevExpress menu.

Well there is a hack for that.

Please invoke the Registry editor, add the "HideMenu" DWORD value to the following Registry key, and set its Value to 0:
HKEY_LOCAL_MACHINE\SOFTWARE\Developer Express\CodeRush for VS\9.1
This should make the "DevExpress" menu visible.

Look at the post for more details and keep enjoying DXCore.

A Better Visual Studio!

3. June 2009 04:21 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

Recently I discovered in MSDN a great addition, a must to for all C# developers. CodeRush Express.

This product was build by DevExpress and it just make it perfect your experience with Visual Studio.


For example finding symbols or files, tabbing between references, and more than 20 differente refactorings!!!!

Take at look at this new extension! It’s a absolutely a must.

Get path of ASP.NET web application that is running

If you have your ASP.NET application for example in c:\inetpub\wwwroot\WebApplication1 and you want to programmatically get that path just use something like:


string AppPath = Request.PhysicalApplicationPath;

Resizing Forms in C#

In the VB6 world it was very common to use “Resizer” OCXs that you just put on your forms and that they handle all the proportional resizing needed if you changed your form.

It was very simple and easy.

However when I started looking for something like that in .NET it was quite hard to find. So finally I got to ComponentSource and found some alternatives and I evaluated them:


Component Vendor Pricing URL
Component One Sizer For .NET Component ONE I think you have to buy the Component One Studio. That’s $800 ($1000 with more support)
and I think is one license per developer, runtime-free
.NET Forms Resize Softgroup 380$ per developer
from ComponentSource
if you buy directly from them you can get the component for 180$

Each copy is licensed on a per developer basis. A developer may use the license on multiple CPUs as long as they are not used concurrently nor used by another developer. Run-time royalty free.
Resize OCX/.NET Larcom and Young 95$-100$ per license

one license per developer, runtime-free


All of them seem to work. So it really up to your company preferences, budget and the level of support you desire. I haven't made tests like how it behaves if you have thirdparty components or activex ??? maybe I'll review that later.