If someone could clarify the following, with regards to c#, this would be great.
Say I have a web project (webproj1) and a class library (classlib1).
webproj1 has a reference to classlib1.
classlib1 also has a reference to a third party dll (thirdpartydll).
When built, the \bin folder of webproj will obviously contain classlib1.dll, but should it also contain a copy of thirdpartydll.dll(which is referenced from classlib1) or is it somehow 'embedded' in to classlib1.dll?
You need it separately when the assembly cannot be found in for example the GAC.
See http://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.110).aspx
You could embed it using ILMerge (http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx)
Related
I have an app that references a .dll that was built with Costura/Fody i.e The dll has all its references embedded. When I run the console app, the references from the dll are not unpacked so the console app throws an exception saying missing .dll etc. as it needs those resources to run.
i.e. AssemblyA.dll embeds MyAssembly.dll when built with Costura/Fody. ConsoleAppC references and embeds AssemblyA.dll but also needs MyAssembly.dll to run. I do have a reference to MyAssembly.dll in ConsoleAppC so that it will compile (but CopyLocal is set to false). I was thinking that MyAssembly.dll would be made available to ConsoleAppC when AssemblyA.dll's embedded resources are unpacked?
This is not working but is my scenario valid in any way or can you only utilise embedded resources from ConsoleAppC and not the ones that were embedded in AssemblyA.dll?
Thanks in advance for any help
Mike
What you're trying to do isn't possible with Costura.Fody. What Costura does is embed libraries directly into the main assembly. This means that if you embed the built assembly into another project, it can't see the sub assemblies.
For example, consider the following project structure:
AssemblyA
Foo.cs
References:
SubAssembly1.dll
SubAssembly2.dll
SubAssembly3.dll
AssemblyB
Assume that Costura.Fody is used to embed the sub assemblies in AssemblyA, creating a single DLL file, AssemblyA.dll
If you embed AssemblyA.dll in AssemblyB, then you will not be able to access classes in SubAssembly1.dll. You will only be able to see any of the classes that are directly in AssemblyA.dll, such as those contained in Foo.cs - you will not be able to see any of the libraries referenced by/embedded in AssemblyA.dll.
See this answer to a similar question, where the answerer suggests using ILMerge instead.
I am using Visual Studio 10 within a C# MVC appliction.
I have a qustion on a .dll reference. I am using a third party reference called
Ionic.Zip.dll. What I am not sure about is that it currently points to a location on my C: drive.
How and what is the best practice for me to put this .dll so that when I check in the project, others can also see this .dll without it blowing up.
Thanks
I would typically put a Library folder in my application structure, place the 3rd party dll in that folder, and then reference that dll. Then ensure that the library folder is checked into your source control.
Now, anyone that pulls your source will have the required dll.
Even easier...simply add a reference to DotNetZip via NuGet, the Visual Studio Package Manager:
http://nuget.org/packages/DotNetZip
And you shouldn't have to worry about it.
The best way is to use Nuget.
But in some cases Nuget is not available or not getting compative, so as our friend says, its better put a Library folder in application structure, place the 3rd party dll in that folder, and then reference that dll. Then ensure that the library folder is checked into source control. Now, anyone that pulls source will have the required dll.
I have a dll from a class library project AppconClient. I am referring that dll in another class library project p2. I copied that dll from project AppconClient and copied to Bin\Debug folder of the project p2 and I referred the dll by clicking add reference in the project p2.
I was happy to see the namespace of AppconClient when I tried to refer the dll by using keyword at the top of Program.cs in my project p2. And I could see the classes and methods of that dll inside my project p2. But when I tried to build the project p2 I got the error saying,
The type or namespace name 'AppconClient' could not be found (are you missing a using directive or an assembly reference?)
But the same dll can be referenced in any WebApplication and it works fine also.
Can anyone tell me what could be the reason and solution for this?
There is no need to copy it manually into bin\debug. All you supposed to do is to add reference to the library from the original folder, and in the newly added reference properties set CopyLocal value to True.
You are not supposed to copy the file to the bin\Debug folder.
The compiler will add all your referenced assemblies there.
You only need to add the reference to your original dll.
When you rebuild a project, dll files are deleted(this is what Clean does) and a fresh copy is placed there.
Your original dll got deleted. So it was not there later to build the project.
If you cannot reference the original dll directly, make a copy in your project, probably a folder called Lib and put it there.
Dont Copy. If you copy this may happen because when you are publishing your web site the Copied DLL may be missing.
Right way to do is Add Reference and browse. VS will automatically do it for you.
At the moment I have added and referenced another project to my main solution. It works, but then I need the separate dll that is compiled.
How can I reference another project without the need for a separate dll that I have to distribute with my final exe?
A C# class project in a Visual Studio solution always compiles to an assembly, so adding a project reference will inevitably mean that your executable references the assembly built as a result of compiling the other project. If you don't want to distribute the separate assembly with your executable the only thing you can do is to ILMERGE the assembly into your executable as a part of your deployment build process,
You can't. The way .net works is to load an additional assembly and using its meta data the classes inside that. If you are attempting to have a set of classes that you refer to by source similar to the way c++ uses header files you will have to import those files into your project.
This sounds like you're trying to statically compile a library. This is not (easily) offered by .NET without manually creating and merging assemblies.
I have tried all the suggestions below but still no joy.
I'm now trying a console application, and let me explain exactly what I'm doing.
I create a new console project in VS 2010
I add a number of references (dll's) some that aren't mine such as Castle.Winsor and N2 CMS dlls
in the console app I can add using statements indicating I am using name spaces within the referenced DLLs
I start writing code.
As soon as I compile all the code that uses the referenced DLLs immediately complains with "The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?)"
I have tried setting the dlls to copy to local always, I have copied the DLL into the same directory, I have tried added reference by project and adding a reference to the DLL's themselves
I don't get this problem with a web application project or a ASP.net project they always work fine, only something that is compiled to an EXE like a console app or windows service.
there must be something I'm missing or I would have got this working by now.
Change the project Target to a non Client Profile target. Right click the Project and select Properties, you should see a list of Framework versions. As you are using VS2010, the Console project you've created by default targets .NET Framework 4.0 Client Profile, change that to .NET Framework 4.0.
Check if Copy Local is set to true for the referenced assembly.
First, as to your question, its hard to know exactly what you're doing wrong, but from the fact that you're using an underscore in an assembly name (and probably in namespaces and type names), it suggests you're rather new to the .NET world.
This suggests that you're adding references to other projects in your solution by browsing to the compiled assembly, rather than by adding a Project Reference. When adding a reference, you must select the Project tab rather than browsing for the assembly.
Even if you don't believe this is the issue, remove all references and re-add project references to make absolutely sure. Assumption, asses etc.
Once you've done that, I'd strongly suggest remove all the underscores from your types, namespaces and assemblies. You might want to go read the framework design guidelines, too.
Open your .Proj(Windows service project file) file in notepad and check whether your assembly location(data_object) is the same which you are pointing.
When you open .Proj file in notepad you can check for,
Project reference,
<ProjectReference Include="C:\StackOverflow\StackOverflow.csproj">
And if you giving dll or exe refrence then
<Reference Include="StackOverflow, Version=1.0.0.0, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<ExecutableExtension>.exe</ExecutableExtension>
<HintPath>C:\StackOverflow\bin\Debug\StackOverflow.exe</HintPath>
</Reference>
I suggest you to give exact location including drive name like above example.
Other option you may try,
1. Clean and rebuild
2. Add Project reference if you already tried dll reference
3. Check whether the folder (referred assembly location) is Read Only then remove it.
In VS 2019, I had two projects, one C++ and other one C# Console in one solution file. When tried to add a dll reference through "Add reference", I was not able to see Browse button in "Reference Manager" window, to select dll file.
But when I created only C# Console app inside solution then I could add dll reference.