I have to add a system.web.http assembly reference because I added the HttpConfiguration class to my unit test class library project.
When I browse the Add reference dialog I can not find the system.web.http assembly.
The class library project has the .Net 4.5.1 framework targeted.
in order to get the system.web.http you will need to install a nuget package
in the nuget command line:
Install-Package Microsoft.AspNet.WebApi.Core
https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Core/
I've had multiple errors regarding missing references such as "system.web.http" or "system.web.razor" in my project. Even though I do have all the references installed through nuget.
What worked for me was to install a standalone version of AspNetMVC4, even though Visual Studio 2014 installed that as well. Apparently it was missing some references in Windows. I've installed this from the Microsoft website, and all went well afterwards.
Hope this helps someone. It drove me crazy for like 2 days, nothing regarding nuget worked for me, I've deleted and reinstalled the references a couple times, did everything I've found in multiple posts on stackoverflow, nothing worked.
Url for mvc4 standalone setup from microsoft: https://www.microsoft.com/en-us/download/confirmation.aspx?id=30683
For every one haveing this problem. Remember that you might have a downgraded version of based on your framework. Try look on your packagde folder what version you have. Then upade that version. Dont use Update-Package it will update all version with no respect to the framework your running at all.
It was solved by commenting out the "bindingRedirect" part.
bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/
Related
I've got a cross platform (iOS and Android) Xamarin solution using .NET Standard 2.0. The solution is being built by Visual Studio 2017 (I've tried both the current and preview versions). The Forms and Android projects build fine. However, the iOS fails to build, with the following error:
1>CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'C:\Users\newuser.nuget\packages\system.reflection.emit\4.3.0\ref\netstandard1.1\System.Reflection.Emit.dll' and 'C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Reflection.Emit.dll'. Remove one of the duplicate references.
I've tried many work arounds as described here:
oren.codes
www.hanselman.com
github.com/NuGet
Unfortunately none of these suggestions work. I have also tried to add the System.Reflection.Emit nuget package directly to the Forms and/or to the iOS projects directly. This doesn't work either. Note that originally, the The System.Reflection.Emit package wasn't referenced directly by anything in the solution. It is being pulled in by the following nuget packages which are being explicitly referenced:
Acr.DeviceInfo (5.0.5)
akavache (6.0.0-alpha0038)
AutoMapper (6.2.2)
Microsoft.Identity.Client (1.1.1-preview0040)
Newtonsoft.Json (10.0.3)
Finally, I have tried the update-package -reinstall command in the package console to reinstall all packages for the iOS project. This doesn't work either.
-- update
Just to make this clear, neither the Xamarin Forms or the Xamarin iOS project directly reference System.Reflection.Emit. That package is being pulled in as a dependency of other nuget packages, just from packages that are installed into the Xamarin Forms project. I have confirmed all of the dependencies that are referenced by Nuget, are using the same version. See these screenshots:
It seems to me that the problem (as the error says) is that there is an old version of System.Reflection.Emit that was installed by Visual Studio. However, I can't find a way of ignoring it and using the version of System.Reflection.Emit instead. As I've said above, I have tried to use a project.json file in the Xamarin.iOS project, and manually ignoring, but this doesn't work.
Does anyone else have any ideas?
As an aside, I notice that this bug is still open for Xamarin.
Xamarin Bugs
Managed to get this resolved thanks to an answer by #DirkWilhem on Xamarin Forums site.
Basically, add this to your Xamarin iOS project's .csproj file, with the other PackageReference nodes:
<PackageReference Include="System.Reflection.Emit">
<Version>4.3.0</Version>
<ExcludeAssets>all</ExcludeAssets>
</PackageReference>
Of course you need to make sure the nuget package has been added to the iOS package first.
Xamarin Forums discussion
After spending hours trying to resolve this myself I may have found a solution. Although it does feel wrong, it has got me past the issue.
Moving/Deleting the Xamarin.iOS version of System.Reflection.Emit.dll has solved the build problem for me and enabled me to deploy and run my app on a device. I don’t know what side effects it might have so will need more testing but I thought I’d share what’s worked for me so you can test it as well.
I was running on macOS Visual Studio 2017 but switched over to Windows to try and fix and first fixed on there then tried same approach on macOS and it worked as well.
On windows, go into the following directory and move the System.Reflection.Emit.dll somewhere else (you could just straight up delete it but I wanted to keep a copy I case this has some undesired effects down the track):
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades
On mac the following directory has it:
/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades
Like I say, it feels wrong but for now it’s got me past an issue that’s had me blocked for a couple of days so willing to just move on and hope there’s no side effects. I’d be interested to know your experience with it and if you come across anything else for the future too.
I’ll post this same comment on the Xamarin forums post (https://forums.xamarin.com/discussion/120814/xamarin-ios-project-cs1703-multiple-assemblies-with-equivalent-identity-have-been-imported) as well for future reference.
I had the same issue around a custom Nuget packages that we created and consumed in a separate project. We got around this issue by removing the automatic Nuget building checkbox in the "options" for the project. This does add the extra step of "Create Nuget Package" but one we pushed it to our Nuget repo and consumed it in our project, the errors vanished.
The problem showed up when we updated the sub-projects from PCLs to .netstandards (2.0).
About: I have a ASP.NET website (not Web project) with 3 class library projects in the solution. Earlier I was using SVN but now Git is used source management. I have installed the git locally on a computer (used as server) and using it for merging the source code from other developers. Also, I am using Visual studio 2015 community edition which provides the tools to work with git.
Problem: After cloning the project from the master repository, I build the project to run it. Building the project shows a dialog box saying "Package Restore is in progress". This process creates a folder named "Packages" and that folder includes every package listed in the packages.config file. But after restoration completes, the project throws the following exception:
This exception shows for each package (Autofac here).
The type or namespace name 'Autofac' could not be found (are you missing a using directive or an assembly reference?)
Work around To Solve this problem, I need to uninstall each package and installed it again and problem is solved. This thing I need to do again and again for each developer machine, which is frustrating and time consuming too.
Does anyone has faced the same problem working with Nuget, git and website in ASP.NET.
I faced a problem like this before. In my case, the reason was that I changed the project path (moved the project to another directory), and the path of the packages directory (that contains the NuGet packages) was stored in the csproj file for the old path, that is VS cannot restore NuGet packages. The solution for this was to edit the csproj manually and make it referring to the correct new packages path.
If this doesn't work for you, you can still use your workaround, but using the following PowerShell command (in NuGet Console) for simplicity:
Update-Package -reinstall -Project Your.Project.Name
Note: project name doesn't contain csproj extension, just the project name
It is good practice to not put third party packages into source control. It bloats your repository (even on a large web application, the size of the external packages will massively out weigh your code).
If NuGet package restore is slow, you could look at using a local cache (this can be as simple as a shared folder) or a better internet connection.
That said, you should only have this problem once per machine. While the packages are downloading you could be giving the new team member an overview of the design…
Make sure that all of your projects are using the same target framework, when this isn't done you can often get the
type or namespace [name] could not be found
warning.
To do this, right click each of the projects in the solution explorer > Properties > Application tab > Target Framework. They should all be the same or there will be incompatibilities between the references in your projects. Here's a question regarding this, hopefully this helps.
The main reason is there no Autofac reference in packages.config file.
When you see on the screen Restore packages message box this mean that nuget package manager is trying to install all the packages which are missing in the package folder.
Try to do this step:
In Visual Studio Solution Explorer pick the project and via context menu pick Unload project
After project was unloaded via context menu pick Edit your project
Go to section group and find you Autofac Reference section
If HintPath doesnt looks like ..\packages\Autofac.4.1.1\lib\net45\Autofac.dll (Actual for 4.1.1 version) remove the Autofac reference Item
Save csproj file and reload project
Install Autofac via NuGet Package manager
Commit and push changes to git repository
Had the same problem with VS 2019. In ASP.NET, packages are updated via the .refresh files that appear in your bin folders. If these aren't checked into Git, they wouldn't be copied down to your cloned repro.
I added the .refresh files for all of my package dlls, made sure the versions and paths in the .refresh files were correct, and now everything updates as expected.
My custom class library (targeting .NET 4.5.1) references Newtonsoft.Json 8.0.2 (the latest version to date). I've added this class library as a reference to a new ASP.NET 5 Web API project.
From the Error List output:
Error NU1002 The dependency Newtonsoft.Json 1.0.0 in project MyProject does not support framework DNXCore,Version=v5.0.
That part seems somewhat self-explanatory, however, I couldn't understand why it was changing my referenced version to 1.0.0.
From the References --> DNX 4.5.1 --> MyClassLibrary Node:
NU1007 Dependency specified was Newtonsoft.Json >= 8.0.2 but ended up with Newtonsoft.Json 1.0.0.
I've tried removing/re-adding the references several times, all to no avail. I did notice that several of the ASP.NET libraries use Newtonsoft.Json 6.0.6 -- I'm not sure if this has anything to do with it.
If I navigate to the wrap folder --> Newtonsoft.Json --> json file, and replace "Newtonsoft.Json 1.0.0-*" with "Newtonsoft.Json 8.0.2-*", it fixes the references for the DNX 4.5.1 node.
However, errors still show afterwards saying that Newtonsoft.Json 8.0.2 referenced in my class library does not support DNXCore 50.
I'm at a loss as to what to do. Any help would be greatly appreciated.
Answer to my issue:
Thanks to Oleg's response I was able to make it work -- however there were two hurdles. One was the "wrap" folder that was created for Newtonsoft.Json. In the root of my solution was a "wrap" folder that contained a folder called Newtonsoft.Json. Apparently(?) that folder shouldn't have been created (how it was created I have no idea). Once removing that, I was able to add a reference to my custom class library without any errors referencing Newtonsoft.Json.
However when I began trying to use my custom assembly as in code, I would get an error about DNX50 not being supported -- which sort've makes sense because my custom referenced assembly was a .NET 4.5.1 class library.
This GitHub link has many people experiencing a similar issue
However, I managed to get everything to build and errors to go away by removing targeting for DNXCore50. This worked for me because I was just wanting to share some POCO data models between a Web API and WPF project. I'm not interested in targeting DNXCore at the moment.
I'm looking forward to the future of ASP.NET, but the newness is a bit challenging, at least for me.
I feel guilty asking a question like this around here, but I'm at a loss and would appreciate some help.
A proof-of-concept like web application was built on one PC and put up on a repo to download on another PC at a different location. There was originally an auto-build feature set up where Azure would build and publish automatically on check-in, but that was removed. Things were working on both ends until one side included a bulk of excluded changes. Now I'm seeing the following error:
The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be
loaded from the assembly
...\packages\Microsoft.Net.Compilers.1.0.0\build..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll.
Could not load file or assembly
'file:///...\packages\Microsoft.Net.Compilers.1.0.0\tools\Microsoft.Build.Tasks.CodeAnalysis.dll'
or one of its dependencies. The system cannot find the file specified.
Confirm that the declaration is correct, that the assembly
and all its dependencies are available, and that the task contains a
public class that implements Microsoft.Build.Framework.ITask.
Does anyone have any suggestions on where to begin looking for the issue?
It turns out that NuGet packages were committed to the repository and breaking everything. Deleting the project\project\packages directory from the repo solved all build problems since NuGet fetches the packages automatically on build.
I got this error when I created a new branch for my project.
It drove me crazy for an hour. I tried most of the suggestions over the internet including the accepted answer to this question.
I then closed the project, opened it again, cleaned it and the error is gone. So this means this could be cache issue.
Anyways, just wanted to share.
I too tried the top answer with no luck so deleted the contents of my bin and packages dir, closed and re-opened VS and everything fine now.
I have tried all solutions described before, but none worked.
What solved it for me, was to update the Microsoft.Net.Compilers from the NuGet Package Manager
Right-click on your solution.
Go to Manage Nuget Packages.
Search for Microsoft.Net.Compilers.
Install or update on dependent projects as necessary.
Re-build, clean solution and restart Visual Studio worked for me.
Deleting the package and cleaning the solution solved it for me.
Deleting these three directories solves the problem.
/packages
/bin
/obj
NOTE: delete both /bin and /obj from all projects included in the solution (including Test projects).
Problem hides on TFS, you need to remove folder TestProject...\packages from TFS, check in, delete it from your local dir and build again. Worked!
Use the below step:
1) Delete the package folder.
2) close the visual studio.
3) open the project and rebuild the project.
I delete all from packages folder and rebuild solution. It's worked for me.
In my case: this works for me.
It turns out my teammate had already started looking into Windows 10 development and had Microsoft Build Tools 2015 installed on his machine.
I installed the software from https://www.microsoft.com/en-us/download/details.aspx?id=48159 and the problem was solved.
In my case, the solution was:
Use Windows Explorer and navigate to the offending path:
C:\MyApplication\Code\Main\ABCProject\ABCProject.UI\Bin
Right click on bin folder > select properties > Uncheck ReadOnly.
In my case, the solution was:
Right Click on Solution.
Go to Manage Nuget Packages for this Solution.
Search for Microsoft.CodeDom.Providers.DotNetCompilerPlatform.
Uninstall the searched Package.
Restart the Visual Studio.
I just tried this on a clean install of a Windows 10 machine and the issue for me ended up being that I didn't have the .NET 3.5 framework installed. This stackoverflow question helps explain why.
Cannot build WIX project on windows 10
Right Click on Solution.
Go to Manage Nuget Packages for this Solution.
Search forMicrosoft.Net.Compilers on Browse Section.
Deleting the bin folder worked for me
In vs2017 community there appeared a new item in the "build" menu. It disappeared after I used it and was called something like "Optimise project build packages". I clicked it and it fixed everything, just restart etc. I did it on two machines.
What it did was removed Microsoft.net.compilers 2.10.0 and replaced with Microsoft.CodeDom.Providers.DotNetCompilerPlatform 2.0.1
So there you go - more automagic...
My project was built with .Net Core 2.2 but I had .Net core 3.0 preview installed. I uninstalled .Net Core 3.0 from my system and went through all my class libraries, removing Microsoft.Net.Compilers 3.0, then rebuilt and it worked.
I moved my solution from one drive to another, and one of the files could not be copied because "in used", for which I click ignored, producing the error described in this post. Copying the missing file manually fixed it.
file: Microsoft.Build.Tasks.CodeAnalysis.dll
Destination directory: packages\Microsoft.Net.Compilers.2.1.0\tools
For me I was trying to open a MVC5 project in VS 2013 and I was getting this error, Opened it in VS 2017 and up it worked just fine.
I've downloaded a website and in VS express open it through file => open website. When I press F5 to debug I get build errors:
The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft'
I guess I'm missing a reference but how come it works on the server? References for these projects can be found in the bin directory right?
Under website => start options => build I've set the following: "Build web site" and target framework ".net framework 4" this is the same as the server.
I guess it's looking for a dll that contains Microsoft.aspNet which probably is in totallyUnrelatedName.dll in the folder scratchYourHeadAndLookSomeMore
Could someone help me out and give me a clue as to why Microsoft.aspNet would be missing from my computer?
I'm tempted to quit this job since all projects are web projects without any documentation that won't run locally but do need major changes. Client has no problem to implement changes on the live site but I do.
Go to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution.
Click on the Online Tab.
Search for Microsoft ASP.NET Identity Framework.
Install this package.
Rebuild Solution.
I guess I'm missing a reference but how come it works on the server? References for these projects can be found in the bin directory right?
Not if the used libraries are installed on the server. You might want to install them on your workstation too, or add the proper references (for example via NuGet) and do a bin-deploy.
On how to find out which libraries you're missing: find class names, not namespace names.
I had this error message too so I reinstalled all of my nuget packages again via the package manager console. Unfortunately this did not sort my issue and after loading up a completely separate project within a different solution to the one in which I was experencing: The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft' error, I noticed that it was occurring there too. This meant that there was an issue with my Visual Studio rather than a problem with individual packages or projects.
It turns out that my MEF Component Cache was corrupted - to fix this I deleted my Visual Studio's component model cache folder which can be found here:
%LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache
Mads Kristensen has created a Clear MEF Component Cache Visual Studio extention which you may find useful:
Clear MEF Component Cache
i have the same issue, on mac vs 2019,
reinstall all Associated nuget of the error you get,
you caמ find them on simpale search on google "nuget + " for example "nuget AddNewtonsoftJson",
then go to "project > manage nuget packages" ...
I try all above solution but It did not resolve my issue.
If still you cannot resolve this following solution might help you
https://www.nuget.org/packages/DotNetOpenAuth.AspNet/
NuGet Installation:
Go to Tools -> NuGet Package Manager -> Package Manager Console
PM> Install-Package DotNetOpenAuth.AspNet