locked
Ambiguity between 'MSScriptControl.IScriptControl.Error' and 'MSScriptControl.DScriptControlSource_Event.Error' RRS feed

  • Question

  • Hello,

    I am trying to use MSScriptControl to execute VBScripts within my .NET Application.  I am currently using Visual Studio 2010 with .NET Framework 4.0.  The code is illustrated below:

    ScriptControl script = new ScriptControl();
    script.Language = "VBScript";
    
    try
    {
      script.AddCode(scriptCode);
    }
    catch
    {
      MessageBox.Show(script.Error.Description + " (line " + script.Error.Line + ")");
    }
    
    
    

    Whenever I try to compile that code, I get the following compilation error:

    Ambiguity between 'MSScriptControl.IScriptControl.Error' and 'MSScriptControl.DScriptControlSource_Event.Error'

    I know that I can get the error message from the exception object in my cathc statement, but the Error Object in MSScriptControl contains more properties (i.e. error line number in the script).

    Any help would be greatly appreciated. 

    Thursday, June 16, 2011 10:17 PM

Answers

  • .NET 4.0 allows primary interop assemblies (or rather, the bits of it that you need) to be embedded into your assembly so that you don't need to deploy them alongside your application.
    Just open the Properties tab for the assembly in Visual Studio 2010 and set "Embed Interop Types" to "False".


    Leo Liu [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.

    • Marked as answer by cmsadmin Friday, June 17, 2011 2:50 PM
    Friday, June 17, 2011 1:54 PM
  • Thank you that helped me find the answer.

    The tricky part was to find the "Embed Interop Types".  To find it, I had to right click on MSScriptControl under references, selected properties, and then found "Embed Interop Types".  I set it to false, and I was able to run the code using an instance of ScriptControlClass.

     

    Thanks again.

    • Marked as answer by cmsadmin Friday, June 17, 2011 2:50 PM
    Friday, June 17, 2011 2:50 PM
  • Hi cmsadmin,

    As stated in this thread:
    http://www.cetix.de/DotNetNews/Thread23191-MSScriptControl_problem_in_-net_2-0.aspx.
    "myScriptingEngine" was of type "ScriptControl", which is as interface that is also implemented by ScriptControlClass. In .net 1.1, this was not a problem; however, in .net 2.0 it is. It was solved by defining "myScriptingEngine" as "ScriptControlClass".

    So just change your declaration line to this will fix it, I've tested with it:
    MSScriptControl.ScriptControlClass script = new ScriptControlClass();
    Leo Liu [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.


    -------------------------------------------------
    This response contains links reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.
    Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
    Friday, June 17, 2011 8:56 AM

All replies

  • Hi cmsadmin,

    As stated in this thread:
    http://www.cetix.de/DotNetNews/Thread23191-MSScriptControl_problem_in_-net_2-0.aspx.
    "myScriptingEngine" was of type "ScriptControl", which is as interface that is also implemented by ScriptControlClass. In .net 1.1, this was not a problem; however, in .net 2.0 it is. It was solved by defining "myScriptingEngine" as "ScriptControlClass".

    So just change your declaration line to this will fix it, I've tested with it:
    MSScriptControl.ScriptControlClass script = new ScriptControlClass();
    Leo Liu [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.


    -------------------------------------------------
    This response contains links reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.
    Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
    Friday, June 17, 2011 8:56 AM
  • Hi Leo,

    Thank you very much for you quick reply.  When I try to use ScriptControlClass instead of ScriptControl, I get the following 2 errors during compilation:

    Interop type 'MSScriptControl.ScriptControlClass' cannot be embedded. Use the applicable interface instead.
    The type 'MSScriptControl.ScriptControlClass' has no constructors defined

    This does work on .NET Framework 3.5, but I am using .NET Framework 4.0.

    Any idea why I am getting this error?

    Friday, June 17, 2011 12:19 PM
  • .NET 4.0 allows primary interop assemblies (or rather, the bits of it that you need) to be embedded into your assembly so that you don't need to deploy them alongside your application.
    Just open the Properties tab for the assembly in Visual Studio 2010 and set "Embed Interop Types" to "False".


    Leo Liu [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.

    • Marked as answer by cmsadmin Friday, June 17, 2011 2:50 PM
    Friday, June 17, 2011 1:54 PM
  • Thank you that helped me find the answer.

    The tricky part was to find the "Embed Interop Types".  To find it, I had to right click on MSScriptControl under references, selected properties, and then found "Embed Interop Types".  I set it to false, and I was able to run the code using an instance of ScriptControlClass.

     

    Thanks again.

    • Marked as answer by cmsadmin Friday, June 17, 2011 2:50 PM
    Friday, June 17, 2011 2:50 PM