Thursday, August 20, 2009

WSP Builder Extension Error (System.Workflow.ComponentModel.Compiler.ITypeProvider)

Solving the error :The service 'System.Workflow.ComponentModel.Compiler.ITypeProvider' must be installed for this operation to succeed. Please ensure that this service is available.
To fix this issue you have to edit your project file :
Goto <project> <propertygroup> :
<projecttypeguids>{F8810EC1-6754-47FC-A15F-DFABD2E3FA90};{D59BE175-2ED0-4C54-BE3D-CDAA9F3214C8};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</projecttypeguids>
For VB Project <Project :
<import project="$(MSBuildExtensionsPath)\Microsoft\Windows Workflow Foundation\v3.5\Workflow.VisualBasic.Targets">

Wednesday, August 19, 2009

How to Load an assembly from a file and call the metods of a class

  • Step 1: Add the reflection namspace
    using System.Reflection;

    Step 2: Load the assembly from the file
    Assembly testAsm = Assembly.LoadFrom(@"C:\AddList.dll");


  • Creates the assembly object by calling LoadFrom method in the assembly class and pass the path of the assembly as a parameter.

    Step 3 :Create the type object
    Type testType = testAsm.GetType("Blog.Sample.ListCreator");

    Call the GetType function of the assembly class to create the Type.In above example there is a namspace called Blog.Sample and class called ListCreator.

    Step 4:Create the instance of the Class
    object testObj = Activator.CreateInstance(testType);

    Use Activator.CreateInstance method to create the instance of the required class by passing the Type object which we created in the above step.

    Step 5: Call the method
    testType.InvokeMember("CreatList", BindingFlags.Default BindingFlags.InvokeMethod, null, testObj, new object[] { "BlogSample", "AssemblyBlog" });

    Use the Type.InvokeMember to call the method in the class of loaded assembly.

    Parameter Details:
    1, Name of the Method (Ex: "CreateList")
    2, Binding Flag(We are invoking a method so it will be BindingFlags.InvokeMethod)
    3, Binding object - you can pass null
    4, Target Object - which class's method need to be called (Object which is created by Activator.Creatinstance method - instance of the class)
    5, Object Array of parameters for method (Above passed two string parameters)
  • Cheers
  • Shyju Mohan