How to add Assembly reference? - c#

I added using Microsoft.VisualBasic to my code but compiler reports error CS0234:
The type or namespace name 'FileSystem' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)
What is this "assembly reference" and how to add one?
Error also shown in the picture
http://img16.imageshack.us/img16/6517/errorcup.jpg

You've got a using directive for the Microsoft.VisualBasic namespace, but the fact that you're fully-qualifying the name Microsoft.VisualBasic.FileSystem makes that irrelevant.
I suspect you just haven't added a reference to the Microsoft.VisualBasic.dll assembly. (Assemblies and namespaces are very different things.)
Personally I would attempt to avoid VB-specific assemblies in the first place, to be honest.

Related

The type or namespace name 'NUnit' could not be found | Unity

i have next errors:
The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'UnitySetUpAttribute' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'UnitySetUp' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'TestAttribute' could not be found (are you missing a using directive or an assembly reference?)
More under a page:
enter image description here
Code:
https://pastebin.com/5zTjwPZw
How fix it?
I had the same issue in a custom package after updating to 2020.2.3f1.
In the case of packages (or if you are using assemblies), they now seem to enforce that Editor's only assemblies should be marked as such in the Platforms section of the inspector:
Test code needs to be under Editor, so it compiles to the Assembly-CSharp-Editor-*.dll which has references to the nunit dlls.
I find this particularly confusing given a quick inspection of Assembly-CSharp-*.csproj will show the nunit.framework listed as a reference, and the fact that it will also build if you point msbuild at the generated solution within vscode (whilst simultaneously failing a Unity 'refresh').

Jenkins/ .net core 2.0/ ubuntu missing assemblies

I set up an ubuntu 16.04 machine with Jenkins, nodejs, and .net core 2.0, and then tried to have it build my .net core 2.0 web application. It failed with the following message(s):
16:32:26
/usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1987,5):
warning MSB3245: Could not resolve this reference. Could not locate
the assembly "Microsoft.AspNetCore.Authorization". Check to make sure
the assembly exists on disk. If this reference is required by your
code, you may get compilation errors.
[/var/lib/jenkins/workspace/MySolution Main
App/MySolution.Common/MySolution.Common.csproj] 16:32:26
/usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1987,5):
warning MSB3245: Could not resolve this reference. Could not locate
the assembly "Microsoft.AspNetCore.Mvc.Abstractions". Check to make
sure the assembly exists on disk. If this reference is required by
your code, you may get compilation errors.
[/var/lib/jenkins/workspace/MySolution Main
App/MySolution.Common/MySolution.Common.csproj] 16:32:26
/usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1987,5):
warning MSB3245: Could not resolve this reference. Could not locate
the assembly "Microsoft.IdentityModel.Tokens". Check to make sure the
assembly exists on disk. If this reference is required by your code,
you may get compilation errors. [/var/lib/jenkins/workspace/MySolution
Main App/MySolution.Common/MySolution.Common.csproj] 16:32:26
/usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1987,5):
warning MSB3245: Could not resolve this reference. Could not locate
the assembly "System.IdentityModel.Tokens.Jwt". Check to make sure the
assembly exists on disk. If this reference is required by your code,
you may get compilation errors. [/var/lib/jenkins/workspace/MySolution
Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27
Security/Decorators/ForbiddenResult.cs(5,28): error CS0234: The type
or namespace name 'Mvc' does not exist in the namespace
'Microsoft.AspNetCore' (are you missing an assembly reference?)
[/var/lib/jenkins/workspace/MySolution Main
App/MySolution.Common/MySolution.Common.csproj] 16:32:27
Security/Decorators/GroupMemberAttribute.cs(3,28): error CS0234: The
type or namespace name 'Mvc' does not exist in the namespace
'Microsoft.AspNetCore' (are you missing an assembly reference?)
[/var/lib/jenkins/workspace/MySolution Main
App/MySolution.Common/MySolution.Common.csproj] 16:32:27
Services/Impl/TokenManagementService.cs(10,14): error CS0234: The type
or namespace name 'IdentityModel' does not exist in the namespace
'System' (are you missing an assembly reference?)
[/var/lib/jenkins/workspace/MySolution Main
App/MySolution.Common/MySolution.Common.csproj] 16:32:27
Services/Impl/TokenManagementService.cs(12,17): error CS0234: The type
or namespace name 'IdentityModel' does not exist in the namespace
'Microsoft' (are you missing an assembly reference?)
[/var/lib/jenkins/workspace/MySolution Main
App/MySolution.Common/MySolution.Common.csproj] 16:32:27
Security/Decorators/ForbiddenResult.cs(9,33): error CS0246: The type
or namespace name 'IActionResult' could not be found (are you missing
a using directive or an assembly reference?)
[/var/lib/jenkins/workspace/MySolution Main
App/MySolution.Common/MySolution.Common.csproj] 16:32:27
Security/Decorators/ForbiddenResult.cs(18,40): error CS0246: The type
or namespace name 'ActionContext' could not be found (are you missing
a using directive or an assembly reference?)
[/var/lib/jenkins/workspace/MySolution Main
App/MySolution.Common/MySolution.Common.csproj] 16:32:27
Security/Decorators/GroupMemberAttribute.cs(8,51): error CS0246: The
type or namespace name 'IActionFilter' could not be found (are you
missing a using directive or an assembly reference?)
[/var/lib/jenkins/workspace/MySolution Main
App/MySolution.Common/MySolution.Common.csproj] 16:32:27
Security/Decorators/GroupMemberAttribute.cs(33,33): error CS0246: The
type or namespace name 'ActionExecutingContext' could not be found
(are you missing a using directive or an assembly reference?)
[/var/lib/jenkins/workspace/MySolution Main
App/MySolution.Common/MySolution.Common.csproj] 16:32:27
Security/Decorators/GroupMemberAttribute.cs(53,32): error CS0246: The
type or namespace name 'ActionExecutedContext' could not be found (are
you missing a using directive or an assembly reference?)
[/var/lib/jenkins/workspace/MySolution Main
App/MySolution.Common/MySolution.Common.csproj] 16:32:27
Security/Decorators/GroupMemberAttribute.cs(58,24): error CS0246: The
type or namespace name 'ActionExecutingContext' could not be found
(are you missing a using directive or an assembly reference?)
[/var/lib/jenkins/workspace/MySolution Main
App/MySolution.Common/MySolution.Common.csproj]
On my dev machine, I looked around and couldn't find those assemblies, but I'm definitely referencing them, so I'm guessing they're stashed in a common location somewhere.
What do I need to do to get all the referenced assemblies to be found by Jenkins and successfully build my project? All the documentation I've seen online seems to reference .net core 1.0 or 1.1 and it seems a lot of this stuff is different now.
My build steps are very simple (there's one). A script to do:
dotnet clean
dotnet restore
dotnet build
SO IT TURNS OUT that this is a bug (perhaps of ReSharper) where if you reference a library in your solution in a project for the first time, and automagically update the reference, the reference isn't added completely correctly; IOW, the MySolution.Common project did not explicitly add the dependent assemblies to the project file, even though they were part of the solution and available.
On my development machine, that didn't matter so much; Visual Studio was able to find the dependencies just fine. On my build server, however, this was a critical piece of information that was missing.
HOW TO CORRECT
If we take a look at the first error:
16:32:26 /usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1987,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.AspNetCore.Authorization". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj]
...we can see that the problem occurred when building the MySolution.Common project, and the missing assembly was Microsoft.AspNetCore.Authorization.
There are two ways to make this work. One is to manually edit the .csproj file. If you add the line in the PackageReference ItemGroup like so:
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="2.0.1" />
... the problem (for that missing reference) will go away. This is what I originally did, and it worked, but then I found out that I could do this without messing with that file by simply going to my Package Management Console and doing something like this:
cd MySolution.Common
dotnet add reference Microsoft.AspNetCore.Authorization
...this would add it to the project file properly, along with the proper version and everything, so I think this is a better method.
I hope this saves someone the hours it cost me.

The type or namespace name 'DataSetExtensions' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)

I know this is a common error but I have the correct reference to the System.Data.DataSetExtensions.dll added to the project and my project is a SQL CLR project built for .net 4.5 and I'm getting the error at the following line:
using System.Data.DataSetExtensions;
I also checked the properties for the dll and it is referencing the correct version for the 4.5 dll so what else could possibly be causing this issue? Is this an issue with SQL CLR projects?
System.Data.DataSetExtensions is an assembly, not a namespace. You just need to add a reference to System.Data.DataSetExtensions.dll (as you say you already have) and then a using directive for the System.Data namespace:
using System.Data;
That will pull in all the extension methods in the classes in that namespace, e.g. DataRowExtensions.
When you're looking in documentation, always be careful about the difference between namespaces and assembly names - they're often the same, but they're logically independent.

The type or namespace name 'Data' does not exist in the namespace 'Gilbane.SRP' (are you missing an assembly reference?)

I have a solution with two projects in it, both class libraries built with .NET Framework 4. The first is an EF model assembly called Gilbane.SRP.Data. I added that reference to the 2nd project Gilbane.SP.Logging. I keep getting the error:
The type or namespace name 'Data' does not exist in the namespace 'Gilbane.SRP' (are you missing an assembly reference?)
on the line in the Logger:
using Gilbane.SRP.Data;
This is even though it is required and finds it ok, Resharper shows that using as being necessary, and completion in the code editor allows me to add Gilbane.SRP.Data.
What else could it be?

UserCollection? Cant locate dll

Ive added the using Microsoft.SharePoint.Client;
But still getting errors, is it some dll i need to download?
This is the error:
The type or namespace name 'SharePoint' does not exist in the
namespace 'Microsoft' (are you missing an assembly reference?)
(are you missing an assembly reference?)
That's the important part. You say you have added a using statement for the namespace, but have you added an assembly reference?
First, you need the DLL. Next, right click your project's "References" section (Solution Explorer window), click "Add Reference" and then browse to the DLL. Add it and you should be set to go.

Categories

Resources