none
Exposing .Net Assembly to VBScript on Windows 7 64-bit RRS feed

  • Question

  • I have been trying to get my .Net Assembly exposed to VBScript by utilizing COMVisible on my Windows 7 64-bit machine with Visual Studio 2010.

    I have done the following:

    1. Created a .Net C# Class Library and set the COMVisible attributes including Guid, ProgId and ClassInterface
    2. Set the project to be compiled as x86
    3. Set the project to "Register for COM Interop"
    4. Registered the assembly in the GAC

    Now, however, when I attempt to use any of the methods for the .Net assembly, I get the error message

    "Exception: Object reference not set to an instance of an object."

    I have been using PrimalScript 2008 to create my VBScript and the Intellisense for the object and the methods displays, however, the instantiation of the object fails at runtime.

    Is there anything else that I can do to further troubleshoot the issue and be able to successfully instantiate my .Net assembly through VBScript on Windows 7 64-bit?

    Thanks.

    Tuesday, December 21, 2010 5:35 PM

Answers

  •  

    Hi vs2010junkie,

     

    I'm working on this issue, and I will let you know if I find anything useful for this issue.

     

    Please free to let us know if you have any concern.

     

    By the way,  the VBDllCOMServer project of All-In-One Code Framework focuses on exposing .NET Framework components to COM, as well as how to use the COM server with VB Script, is it what you're looking for?


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by eryang Monday, December 27, 2010 6:24 AM
    • Marked as answer by eryang Monday, December 27, 2010 12:54 PM
    Thursday, December 23, 2010 10:00 AM

All replies

  • Post a simple example of minimal VB.NET code and  minimal VBScript code that fails.  You should show a .vbs file and VB2010 project.  Not sure what your question has to do with the CLR.
    Tuesday, December 21, 2010 6:29 PM
  • VBScript
    
    Call Main()
    
    Sub Main
    	Dim obj
    	Dim strAppSetting
    
    	Set obj = CreateObject("Configuration.COMConfigurationManager")
    	
    	strAppSetting = obj.GetNameValue("FilePaths", "ImportDirectory")
    
    	WScript.Echo "I am here"
    	
    	WScript.Echo strAppSetting
    End Sub
    
    C# code
    
    <pre lang="x-c#">/// <summary>
      /// Exposes .Net Configuration classes to COM objects
      /// </summary>
      [ComVisible(true), Guid("93102E1C-56AD-4FAE-A397-E411B6588E11")]
      [ProgId("Configuration.COMConfigurationManager")]
      [ClassInterface(ClassInterfaceType.AutoDual)]
      public class COMConfigurationManager
      {
        private System.Configuration.Configuration objConfig = null;
        const string EXE_NAME = "Custom.Interop.Configuration.dll";
        const string UNIT_TEST_EXE_NAME = "Custom.Interop.Configuration.UnitTest.dll";
    
        /// <summary>
        /// Class constructor
        /// </summary>
        public COMConfigurationManager()
        {
          //OpenExeConfiguration();
          OpenWebConfiguration();
        }
    
        /// <summary>
        /// Gets the value from a custom NameValue configuration section
        /// </summary>
        /// <param name="strSectionName">string containing the name of the custom configuration section</param>
        /// <param name="strNameValueKey">string containing the name of the NameValue keypair</param>
        /// <returns>string containing the value from the NameValue keypair</returns>
        public string GetNameValue(string strSectionName, string strNameValueKey)
        {
          NameValueCollection nvColl = GetNameValueSection(strSectionName);
    
          return nvColl[strNameValueKey];
        }//method: GetNameValue
    
        internal void OpenWebConfiguration()
        {
          objConfig = WebConfigurationManager.OpenWebConfiguration(null);
          
        }
    
        internal void OpenExeConfiguration()
        {
          string strExePath = Assembly.GetExecutingAssembly().Location;
          string strCurrentExePath = strExePath.Replace(EXE_NAME, UNIT_TEST_EXE_NAME);
          objConfig = ConfigurationManager.OpenExeConfiguration(strCurrentExePath);
        }
    
        /// <summary>
        /// Gets the value from a custom Dictionary configuration section
        /// </summary>
        /// <param name="strSectionName">string containing the name of the custom configuration section</param>
        /// <param name="strDictKey">string containing the name of the Dictionary KeyValue pair</param>
        /// <returns>string containing the value from the Dictionary KeyValue pair</returns>
        public string GetHashtableValue(string strSectionName, string strDictKey)
        {
          Hashtable htblColl = GetDictionarySection(strSectionName);
    
          return htblColl[strDictKey] as string;
        }//method: GetHashtableValue
    
        /// <summary>
        /// Gets the value from the connectionStrings configuration section
        /// </summary>
        /// <param name="strConnStringName">string containing the name of the connection string</param>
        /// <returns></returns>
        public string GetConnectionString(string strConnStringName)
        {
          ConnectionStringsSection connSection = objConfig.ConnectionStrings;
          return connSection.ConnectionStrings[strConnStringName].ConnectionString;
        }//method: GetConnectionString()
    
        /// <summary>
        /// Gets the value from the appSettings configuration section
        /// </summary>
        /// <param name="strAppSettingName">string containing the name of the app setting</param>
        /// <returns></returns>
        public string GetAppSetting(string strAppSettingName)
        {
          AppSettingsSection appSection = objConfig.AppSettings;
          return appSection.Settings[strAppSettingName].Value;
        }//method: GetAppSetting()
    
        internal object GetSection(int intConfigSectionType, string strSectionName)
        {
          object objConfigColl = null;
    
          switch (intConfigSectionType)
          {
            case 0:
              objConfigColl = GetDictionarySection(strSectionName);
              break;
            case 1:
              objConfigColl = GetDictionarySection(strSectionName);
              break;
            case 2:
              objConfigColl = GetNameValueSection(strSectionName);
              break;
            default:
              objConfigColl = GetDictionarySection(strSectionName);
              break;
          }//switch
    
          return objConfigColl;
        }//
    
        internal NameValueCollection GetNameValueSection(string strSectionName)
        {
          NameValueCollection nvColl = null;
    
          nvColl = GetDefaultNameValueSection(strSectionName);
    
          return nvColl;
        }//method: GetNameValueSection()
    
        internal Hashtable GetDictionarySection(string strSectionName)
        {
          Hashtable htblColl = null;
    
          htblColl = GetDefaultDictionarySection(strSectionName);
    
          return htblColl;
        }//method: GetDictionarySection()
    
    
        public Hashtable GetDefaultDictionarySection(string strSectionName)
        {
          DefaultSection defaultSect = objConfig.GetSection(strSectionName) as DefaultSection;
    
          //Get the raw XML
          string readableSectionRawXml = defaultSect.SectionInformation.GetRawXml();
    
          ConfigXmlDocument readableSectionRawXmlDocument = new ConfigXmlDocument();
    
          readableSectionRawXmlDocument.Load(new StringReader(readableSectionRawXml));
    
          DictionarySectionHandler readableSectionHandler = new DictionarySectionHandler();
    
          var result = readableSectionHandler.Create(null, null, readableSectionRawXmlDocument.DocumentElement) as Hashtable;
    
          return result;
    
    
        }
    
        public NameValueCollection GetDefaultNameValueSection(string strSectionName)
        {
          
          DefaultSection defaultSect = objConfig.GetSection(strSectionName) as DefaultSection;
    
          //Get the raw XML
          string readableSectionRawXml = defaultSect.SectionInformation.GetRawXml();
    
          ConfigXmlDocument readableSectionRawXmlDocument = new ConfigXmlDocument();
          
          readableSectionRawXmlDocument.Load(new StringReader(readableSectionRawXml));
    
          NameValueSectionHandler readableSectionHandler = new NameValueSectionHandler();
    
          var result = readableSectionHandler.Create(null, null, readableSectionRawXmlDocument.DocumentElement) as NameValueCollection;
    
          return result;
          
        }
    
      }
    
      internal enum ConfigurationSectionTypes
      {
        DictionarySection,
        SingleTagSection,
        NameValueSection
      }
    
    Please advise.
    
    Tuesday, December 21, 2010 7:58 PM
  •  

    Hi vs2010junkie,

     

    I'm working on this issue, and I will let you know if I find anything useful for this issue.

     

    Please free to let us know if you have any concern.

     

    By the way,  the VBDllCOMServer project of All-In-One Code Framework focuses on exposing .NET Framework components to COM, as well as how to use the COM server with VB Script, is it what you're looking for?


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by eryang Monday, December 27, 2010 6:24 AM
    • Marked as answer by eryang Monday, December 27, 2010 12:54 PM
    Thursday, December 23, 2010 10:00 AM