Dependent DLLs of referenced ClassLibrary not added to BIN of application - c#

There are so many questions posted about this issue. I believe i have read them all and still not having much luck. I have a VS2015 project where i can do all that i have described below without issue. Also note that the process i went through to move the applications and class libraries from 2015 to 2017 was to fully rebuild them in 2017. In any case, i created a new solution in 2017 with new application and class library to prove my issue.
I created a new library call ClassLibrary and a new asp.net web app called WebApplication.
In ClassLibrary i then added a nuget for testing (i have also tested this with a file reference to a 3rd party DLL). In this case i added the AjaxControlToolkit 18.1.0 for testing.
Then in WebApplication project i reference ClassLibrary
I would expect this simple solution and project referencing to copy the dependent DLLS of ClassLibrary to WebApplication project bin. It does not. Prior to moving to VS 2017 this would (and still does in VS 2015) copy the dependency DLL of ClassLibrary in WebApplication's BIN. In the VS2017 project i described above the AjaxControlToolkit is not copied to the BIN, i only see a ClassLibrary.dll but none of its dependencies.
I have tried to "use" the AjaxControlToolkit in the WebApplication project code as some of the posts suggest. This does not work as the assembly is not available in the project and i get build errors. I've modified the .csproj files in so many different ways based on suggestions i have found on Stack, nothing works.
Whats even more strange is that i see the DLL in the bin but not listed in the project References. Even though the DLL is in the bin i am unable to work with it.
What is going on? This is such a simple exercise of referencing and after spending two days on Google searching on this it seems crazy that so many have this issue. Why are these DLLs not flowing all the way to the parent application BIN???
Thanks

In my post i mentioned that these projects originally in VS2015 were then recreated in VS2017. This process converted the original Web Site projects to Web Application projects.
As mentioned here, in a Web Site project when a ClassLibrary is referenced as a project reference "Copies of dependent assemblies, XML document files, license files, resource files, and so on." (this includes installed Nugets in the ClassLibrary) are copied to the project BIN. This is not the case with Web Applications. See here for the differences. Installing the NuGet wherever it is needed is required, it will not be inherited from child references as it is with Web Site projects.

Related

Weird Could not load file or assembly error using docusign

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.

Type exists in both error sharing project references and giving each project it's own DLL build of a library when building

I have multiple projects and everything was working ok prior, but I had to download a UI framework package + change the source. I decided to include the DLL's in each project, reference them per project, and now trying to build a solution that references multiple projects blows up saying "type is in both" but I don't understand the problem. Using DLL's, shared projects, why is Visual Studio and the build so confused and can't figure out how to handle this?
The reason I used shared project references too is so I can use code & classes from one project in another and we have class libraries too.
Is there an easy way to fix this? It worked fine as a nuget package so why does using built DLL's isolated per project present a problem, it's the exact same thing.
Seemed to be related to Visual studio caching and how packages are managed so I reverted by source code to start over again. I uninstalled/re-installed nuget packages, manually added my own DLL's, re-built everything from scratch, and it finally worked.

Embed NHibernate assemblies in ASP.NET website

A friend and I are working on a ASP.NET website and that friend decided he wants to employ the NHibernate framework for ORM. I have zero experience with using non-standard frameworks, he has more experience though not in .NET but in Java.
The problem is he committed his changes to the project to a subversion repository after he got it all working locally, but when I update, VS gives 7 errors and a warning about not finding the NHibernate assembly references. He just added the references to the project. There is a bin folder in which some dll.refresh resides (this file causes the warning) that points to a full path name on my friends computer (bad thing in other words).
He and I would like to know, what is he doing wrong? How can we embed the DLLs in the project?
He needs to commit the original assemblies to subversion from wherever he referenced them in the project. For example he could create a lib subfolder to the project in which to put all third-party assemblies. Then reference from this lib folder and commit it to subversion. Then when you checkout you will get this lib folder and the application will compile locally because all the necessary dependencies are part of the source control.
You can put the dlls you need in ~\bin and check them in
You can put the dlls on the level above, say in External Assemblies folder, and edit .redresh files to use relative path
But I recommend you, first, convert your project from Web Site Project to Web Application Project, what brings a lot of benefits, including compiling web site in a single assembly, and second, use NuGet (VS package management extension) to reference, control and maintenance any 3rd party libraries and other dependencies via it.

Project reference not working in VisualStudio2010

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.

C# dll not found at compile time

I'm writing an application in .Net 3.5.
I have 3 projects in the solution so far. When adding the references to the other projects from my main project, the intellisense manages to find the classes from the other project's dlls but at compile time it seems to be "loosing" the reference.
This might be because I initially created the project with target framework .Net 4.0. However since I needed to use the ASP.NET web services I had to downgrade to 3.5.
Any help will be greatly appreciated.
The referrenced projects must be Copy Local : True
Referrence -> Properites ->Copy Local : True
Batch clean all projects in your solution, make sure all the projects in your dependency graph target the .NET 3.5 framework. Check the reference's HintPath in your .csproj file (open with text editor) for references to external DLLs and make sure they're all <=3.5.
However since I needed to use the ASP.NET web services I had to downgrade to 3.5.
There are also several different web service projects in .NET 4. I don't quite understand this move.
You have project references, intellisense sees your referenced classes but when compiling, the compiler seems not to find the referenced assemblies.
I see two possible reasons for this behaviour:
Your main project references a lower version of the .NET framework than your library projects (this is the most likely cause).
Your library projects won't get built at all / or in the wrong order (check the settings in the configuration manager. Open it with a right click on your solution in the solition explorer).

Categories

Resources