I am using Visual Studio 2013 and have written a trivial console application in which I wish to use the class HttpError which is present in the assembly System.Web.Http. This assembly comes from NuGet. Installing the assembly does not add it to the project References which I find confusing. I then found others who indicated that the correct assembly comes with the NuGet package "Microsoft ASP.NET Web API 2.2 Core Libraries" so I installed that instead. This package downloads 3 libraries and the required assembly is present but no Reference is added to the project. I can hand edit the csproj and manually add the reference but I am thinking that doing so should not be necessary. What am I doing wrong?
To reproduce:
Create a new C# Console application (latest framework is fine)
Add the above NuGet package
Is there a reference to System.Web.Http? If not then this is my problem.
Thanks for the responses in the comments which indicated that this worked.
I cannot explain it but it was not working yesterday but it is working now. I tested it many times before posting the question.
Related
I have a .net framework project with framework as 4.8. Recently I integrated docuSign 5.12 using a class library and nuget packages. Everything worked fine in development. When I published the exe in server, I am getting could not load file or assembly error. I cleared the references, reinstalled docusign, changed copy to output property to true for all and published again. But same result.
What I noticed is, when installing .net framework in server, it didn’t create a folder called .Netframework in ‘c:\Program Files(x86)\Reference Assemblies\Microsoft’. As the required dependencies missing are system dependencies, they are not copied to published folder.
So, I have another server where .net 4.8 SDK is present and everything worked fine there. My questions are
Why didn’t installation in server didn’t create assemblies?
Do we need to install .net 4.8 SDK for this to work?
How to publish dependencies for these kind of Nuget packages?
I have not added code samples as it is working already. Dependencies are https://www.nuget.org/packages/DocuSign.eSign.dll/5.12.0#dependencies-body-tab.
You can use the publish functionality of VS. It will package your app, including all NuGet dlls and their dependencies and send it to server. If you use Azure - it's integrated into the process. You can even include it in a CI/CD process. But your specific problem can be addressed by just having VS publish the app to your server instead of you manually copying files over there.
As per the comment from Ralf, I checked the references. Found an interesting thing. I already had a binding redirect in the project but, it was added to the class library config file but not the startup project config file. Because of that, my API was referring to old Newtonsoft version. I copied redirect from class library config to my main project config and it started working.
I have a C# class library project called Helpers which uses the nuget called HtmlSanitizer.
In my web application (which is located inside the same solution), I'm referencing the Helpers project. When I call one of the helper methods that instantiates a HtmlSanitizer, I get the following error:
Method not found: 'Void Ganss.XSS.HtmlSanitizer..ctor(…)'
The error disappears if I add the HtmlSanitizer nuget to the web application.
Since my Helpers project is used in many other projects and web applications (and even referenced in other solutions), it is not viable for me to add the nuget to all of them (imagine the maintenance cost if I have to upgrade the version or use a different nuget…). What's the solution?
This occurs because there are older version of the HtmlSanitizer DLL still present on disk. You need to clean the solution before building, and if not enough, manually delete the older DLLs from disk.
There might be a problem with the HtmlSanitizer nuget. It seems to add references to HtmlSanitizer version 3.0.0.0 to the project, which does not match the version of the DLL and which does not change either when you update the nuget. See bug References to HtmlSanitizer have wrong version number when using the nuget.
I have a solution with two projects - a primary project, and a unit test project. When opening in Visual Studio 2015 all references are found and project builds successfully. When opening in Visual Studio 2017 several but not all NuGet package references are not found and compile fails. Some of the failed references are...
System.Data.Common
System.Net.Http
System.Net.Http.WebRequest
System.Security.Cryptography.Algorithms
System.Security.Cryptography.Encoding
System.Security.Cryptography.Primitives
System.Security.Cryptography.X509Certificates
... but other NuGet references are found with no problem. This solution was created with VS2015. When viewing the .csproj file nothing out of the ordinary is jumping out.
I am thinking of rebuilding it from scratch in VS2017 to try to identify the problem.
Has anyone else experienced this problem, and/or has anyone any suggestions on why this is occurring and what should be done to facilitate a fix?
Update:
I created a brand new VS2017 WebApi project referencing .NET 4.7.1, and compiled successfully. I then added NuGet package System.Data.Common 4.3.0. The NuGet install process appears to have completed with no errors, but still I am left with an invalid reference. That was pretty easy to replicate.
OK, answering my own question.
I found what I believe is the answer. This particular project was originally developed in VS2015 using .NET 4.6.2. When changing to VS2017 we elected to upgrade .NET to 4.7.1. The problem is with the .NET version, not the VS version.
The newer version of .NET has many of these NuGet assemblies added to standard libraries. The NuGet packages were in conflict with the native .NET 4.7.1 namespaces. For example, in .NET 4.7.1, the namespace System.Data.Common is found in the assembly System.Data.dll. No longer is it required to add a NuGet assembly System.Data.Common.dll. In fact, if I do add System.Data.Common NuGet package assembly, I now have two assemblies having the namespace System.Data.Common - one in System.Data.dll and another in System.Data.Common.dll - hence the reference problem.
The solution is to use the .NET 4.7.1 version and remove the extra NuGet assembly. This was also true for System.Security conflicts. The conflict with System.Net.Http was actually moved into a NuGet assembly called Microsoft.AspNet.WebApi.Client.
I hope all of this helps someone else...(uhhhgggg)....
BTW - it appears that when using VS2015 with .NET 4.7.1, these conflicts are suppressed and never display. This feels like a shortcoming of VS2015. Glad VS2017 shows them to reveal the true problem...
Check your packages.config file to make sure the Nuget packages are actually listed as dependencies for your project.
Also, open the solution in VS 2015 and double check the file path for the references in question. Make sure the DLLs are not referenced from a file path unique to Visual Studio 2015.
I had to create a new project and transfer all the necessary files from the old project to new project to fix this.
I have a problem on referencing my Exceptionless package. Has anyone ever tried referencing Exceptionless to a Xamarin project? I am having errors when referencing it.
Questions:
What Exceptionless project type do I use? Is it Console and Service Applications?
What package do I reference? Exceptionless or Exceptionless.Portable?
Error Message:
Could not install package 'System.Security.Principal.Windows 4.0.0'. You are trying to install this package into a project that targets 'Xamarin.iOS,Version=v1.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
I have implemented several solutions and none worked for me right now. I tried referencing the package to a portable class library project and the same error occurs. Hope someone has tried this before and can help me with a solution. Thanks.
This was answered by one of the Exceptionless members, Blake Niemyjski. Thanks!
Question Answers:
You'd need to install the Exceptionless package (Console and Service Applications).
Just the latest Exceptionless package.
Referencing Error Solution:
I'm on version 6.1.0 but the way I installed it to was the portable project they generate and I changed the profile to:
Then I was able to reference exceptionless. I know they added support for .net standard but I've yet to get that to work in any of my samples. Can you please try this and let me know.
Full issue link here.
I've got a Solution with lots of projects and all but one of them is behaving. The one that is not working is a ConsoleApplication, and it relies on C# Class Library project. I've added a reference to the library project, and add the namespace (which I've checked is correct), but everywhere I reference the classes in my library, I get:
The type or namespace 'MyClass' could not be found (are you missing a using directive or an assembly reference?).
The library project is building successfully (I can see the DLLs appear in the bin folder) and I've tried a project reference, and also a reference to the DLL itself. Neither works.
Also, all projects are set to build with a platform target of 'Any CPU'.
I've tried pretty much every suggestion I've come across on forums with no success. Can anyone shed some light on what's going wrong?
Thanks
This solved the problem:
The console application had a Target framework of .NET Framework 4 Client Profile, whereas the library just had .NET Framework 4. I set the console app to .NET Framework 4 and it all builds perfectly.
My bet is on a framework mismatch between your library and you app...
Check if your library is not building with a superior version than you app, or if your app is building with a Client profile flavor
It is probably that one of your DLLs references some part of the .net framework that is not referenced in your console application. For example if one of your class library projects has asp.net server controls in and references System.Web, but your console application does not reference System.Web it will not build and you will get that error. But it is not obvious because the DLLs referenced are stored in the GAC so they would never appear in your bin folder.
I had to simply restart visual studio for reference to work but make sure you have reference added in .csproj file.
If you still experience the issue, make sure the class you're referencing is public and that Asp.net core Framework version match.
Sounds weird,
Have you tried to remove the reference of the project and add it again? Check if your console app has got all the right references.
You could also inspect the .csproj file and see if everything is correct in there.
Just Check that you "Class Library" project has classes in it or if it is a data access layer project which include only a .edmx Model check the Model designer is found and it generates fine.
Good Luck
I worked with syncing the framework, but still, it was giving issue.
So I tried another way.
Right-click on the dependency, and select Add project reference. I added the required project then the error was gone.