'ExcelLibrary' is a 'namespace' but is used like a 'type'

Class library usage, coding and language questions.
User avatar
krupaluk
Posts: 5
Joined: Mon Apr 18, 2016 7:24 pm

'ExcelLibrary' is a 'namespace' but is used like a 'type'

Post by krupaluk » Tue Apr 19, 2016 4:48 am

Hello,

I want to use ExcelLibrary.dll in Ranorex in order to build own methods for dealing with reading and writing from/to xlsx file.

But I am unable to deal with following error:
"'ExcelLibrary' is a 'namespace' but is used like a 'type' (CS0118) - D:\ranorexTutorial\lab\lab\xls.cs:50,38"

I am sure I have not created any namespace called ExcelLibrary. In fact I created brand new C# solution in Ranorex and just added ExcelLibrary reference, add it to "using" and tried to create new instance of it. This is whole code:

Code: Select all

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;
using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;
using ExcelLibrary;

namespace lab
{
    /// <summary>
    /// Description of Xls.
    /// </summary>
    [TestModule("247F2086-AAA0-4354-868C-B51FDD00A276", ModuleType.UserCode, 1)]
    public class XlsTest : ITestModule
    {
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        public XlsTest()
        {
            // Do not delete - a parameterless constructor is required!
        }

        void ITestModule.Run()
        {
            Mouse.DefaultMoveTime = 300;
            Keyboard.DefaultKeyPressTime = 100;
            Delay.SpeedFactor = 1.0;            
            ExcelLibrary xlLib = new ExcelLibrary();
        }
    }
}
So as you see, this is brand new generated code module where I just added reference +
"using ExcelLibrary;" to the top and
"ExcelLibrary xlLib = new ExcelLibrary();" to the ITestModule.Run() method.

Could you pls help why I have this error?
thank you!

alan722
Posts: 25
Joined: Mon Jan 12, 2015 1:34 pm

Re: 'ExcelLibrary' is a 'namespace' but is used like a 'type'

Post by alan722 » Tue Apr 19, 2016 9:04 am

Hi there,

I am not sure which excel framework you are using but it seems like the class name is the same as the namespace?

Maybe try ExcelLibrary.ExcelLibrary xlLib = new ExclLibrary.ExcelLibrary();

User avatar
krupaluk
Posts: 5
Joined: Mon Apr 18, 2016 7:24 pm

Re: 'ExcelLibrary' is a 'namespace' but is used like a 'type'

Post by krupaluk » Tue Apr 19, 2016 10:58 am

Thanks Alan.

I probably found the cause...
ExcelLibrary.dll I found yesterday is not as I expected and I am still new to C# :(

However I was able to make it work by this:

Code: Select all

            String dtPath = "d:\\ranorexTutorial\\dtLab.xlsx";
            ExcelLibrary.SpreadSheet.Workbook workBook = ExcelLibrary.SpreadSheet.Workbook.Load(dtPath);