Error for ExcelDataReader - c#

I am doing a project in C# and I have downloaded ExcelDataReader from codeplex and added it to my project reference. There is an error in namespace 'using Excel;' though I have added Excel, Excel.4.5, Microsoft.Office.Interop.Excel to my project references. I'm getting error where I have written
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
The errors are quoted below:
The type or namespace name 'ExcelDataReader' could not be found (are
you missing a using directive or an assembly reference?) The name
'ExcelReaderFactory does not exist in the current context
How to deal with these errors?
Thank you in advance.
PS:- I have added 'using Excel = Microsoft.Office.Interop.Excel' directive as well.

Go to Project -> Manage NuGet Packages..., in opened window select Browse tab and type Excel Data Reader, install it, at the top of your class add using Excel. Then you will be able to use interface IExcelDataReader.
Here is the source:
https://forums.asp.net/t/1981566.aspx?The+type+or+namespace+name+IExcelDataReader+could+not+be+found

Go to your project-> right click on References and click on Manage NuGet Packages a new tab would opened in your IDE if you are using VS 2015 or higher otherwise a pop window would open. enter package name and install.

In older versions of ExcelDataReader - like 2.1.2.3 - it uses an Excel namespace for itself, I mean that namespace is not related to Microsoft Office Excel, that I can suggest you to use alias for them:
using XlReader = Excel;
using Xl = Microsoft.Office.Interop.Excel;
...
var excelReader = XlReader.ExcelReaderFactory.CreateOpenXmlReader(stream);
But in newer version - like 3.1.0 - its namespace changed to ExcelDataReader;
You can install the package of ExcelDataReader 2.1.2.3 that will remove your compile exception.

Related

Package could not be found

I'm trying-out C# and .NET 5 for the first time, but I'm having trouble importing packages.
First of all I'm using VCode as my IDE and installed C# Extension (and enabled: Omnisharp: Enable Import Completion).
When I write a function using for example List, I don't get a recommendation to import:
using System.Collections.Generic;
It also doesn't recognize other classes in my project. Even when I import manually for example:
using WebApp.Model.Item;
I get an error like this:
The type or namespace name 'Item' could not be found (are you missing a using directive or an assembly reference?) C:\Users\ljhha\Documents\IT\C\WebApp\WebApp\WebApp.csproj
I also trying the same in Visual Code and get the same error.
I Build, Rebuild used Debugging, re-open the IDA. So I'm out of options?
Please check the full code here on github

Mac Visual Studio Xamarin - the type or namespace 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

On Mac Visual Studio - Xamarin Project, I get an error:
the type or namespace 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference)
I have tried to resolve it by using the nuget package manager. Specifically, click 'Packages' folder and click 'Add Packages...' and add Linq. Yet it still does not find Linq when I write 'using System.Linq' yet I can see 'System.linq' in the package folder under the project.
Tried : Refresh, Update, turn off and on
Why can't it find and use the package?
Edit: For similiar error 'HttpStatusCode' where it not found under 'System.Net' yet I have the dll (Version 2.0.5.0) found. I tried to install a new nuget package for it, System.Net.Primitives (Version 3.0.9.0) where 'HttpStatusCode' is stored under this new version. When I reference System.Net.Primitives it does not work.
Example:
'\\ The type or namespace name 'Primitives' does not exist in the namespace 'System.Net'
Using System.Net.Primitives;
Using System.Net;
namespace code {
public class Example
{
\\ the type or namespace 'HttpStatusCode' could not be found
public HttpStatusCode HttpResponse;
}
}`
You need just to add System.Core to your References.
In one of my project I solved it by following way:
Open solution explorer. Right click references, Click on assemblies, select system.xml.linq.
Add the reference assembly to the project. Clean and rebuild.
It should serve the purpose.
Add this .nuget to your Solution. Micosoft.Net.Http.

How to add new namespace in C#

I am creating MVC project behind I am using C# code. I have
`CloudConfigurationManager`
in using read db value . Its showing red Error . I have searched google I need to add namespace.
using Microsoft.Azure;
I have added that also but again Getting Error Like this
type or namespace 'Azure' does not exist in the namespace 'microsoft' (are you missing an assembly reference?) showing like this how to fix this issue how can I add namespace Azure?
i have Fixed issues select Tools Menu select NuGet package Manger console and select package manger console and install Install-Package Microsoft.WindowsAzure.ConfigurationManager after fixed issues
You need reference to the Microsoft.Azure. Follow below steps to add reference.
In Solution Explorer, right click on project and click add reference.
In the Add Reference dialog box, select the tab indicating the type of component you want to reference.
Select the Microsoft.Azure and then click OK.
EDIT :
Also as per J Steen's comment you can add it using nuget package manager. Use below command in Package Manager Console.
Install-Package Microsoft.WindowsAzure.ConfigurationManager

"The type or namespace name 'OfficeOpenXml' could not be found" error

We are using EPPlus to generate Excel documents. Code builds successful in my local system but it is failing when we build through TeamCity and getting below error -
error CS0246: The type or namespace name 'OfficeOpenXml' could not be found (are you missing a using directive or an assembly reference?)
I have tried Google to find the solution but all in vain. My Project target framework is 4.5.2 and I have also added System.Core and WindowsBase. I have also added namespace "using OfficeOpenXml"
EPPlus is added through Nuget Package.
If you have any packages installed using NuGet, then you need to add a NuGet Installer build step in your build configuration before the actual build command, using the solution file which references the NuGet packages you need. This step is what causes TeamCity to download any NuGet packages that are required that it doesn't have installed.
I solved it by removing and add EPPlus reference manually.

'AllowAnonymous' could not be found

Everything worked fine until I installed (Package Manager Console) the postal package, then uninstalled and installed an older version.
Now I get an error where it previously was not.
Error:
The type or namespace name 'AllowAnonymous' could not be found (are you missing a using directive or an assembly reference?)
Who knows how to fix this?
Probably you are missing the reference to System.Web.Http assembly in your project?
So you need to:
Add the reference to System.Web.Http;
Add using System.Web.Http; to your controller;
To add Reference you need to do next steps:
In Solution Explorer, right-click the project node and click Add
Reference.
In the Add Reference dialog box, select the tab Assemblies, and enter System.Web.Http into search on the right side.
Select the component System.Web.Http, and then click OK.
Link:
How to: Add or Remove References By Using the Add Reference Dialog Box
Updated answer for 2021 on .Net 5.0, turns out I was missing this line:
using Microsoft.AspNetCore.Authorization;
I had the same problem. After reinstalling a package, MVC 5 was removed and then MVC 3 was added! The following command fixed the problem:
PM> update-package

Categories

Resources