I have two projects A is of type webservice and B is of type class library project. Project A refrences B.dll. In A when I right click some method and click Go to defenition,if it is defined in project B,it should open the source of project B.I have B.pdb already added to project A. Any help?
Do you have the source code of B.dll included to your project?
Unless you have the source code of that library, you cannot view the source code. However, you can see the definitions like in the same way as you can view the definitions of FCL.
About PDB: PDB files map an assembly's MSIL to the original source lines. This means that if you put the PDB that was compiled with the assembly in the same directory as the assembly, your exception stack traces will have the names and lines of the positions in the original source files. Without the PDB file, you will only see the name of the class and method for each level of the stack trace.
I took the definition from this SO link. Said by Omer van Kloeten.
Related
As the title says, I want to consume all of PDFSharp's source code into my own project. But let me explain why I came to this scenario, so if there is something else I can do, maybe there are other options.
Goal: Compile my project into a single .exe file to use. No installers.
Problem: It uses PDFSharp.dll which is causing me issues.
What I am trying to do, is use ILMerge to create the .exe. I've used this successfully in the past for other projects.
The issue I think is that ILMerge is requiring references to other assemblies that PDFSharp uses. The first being Microsoft.ApplicationInsights. So to by-pass this, I installed Microsoft.ApplicationInsights into my project via Nuget. Then removed the actual reference from the project, but referenced the library in my ILMerge command as below:
/lib:"C:\<path to assembly>\Microsoft.ApplicationInsights.2.16.0\lib\net46"
This actually worked. Except, now it asked for another library and I get this error:
Unresolved assembly reference not allowed: GdPicture.NET.11.
This looks like a paid library, perhaps downloading the trial may get me past this. I didn't try yet. I switched gears as I felt I may be trying to reference an endless amount of assemblies.
I then tried to get the PDFSharp source code and I found that version 1.32 here:
https://sourceforge.net/projects/pdfsharp/files/pdfsharp/PDFsharp%201.32/
I added a reference to this project within my solution file, so now I have a solution with 2 projects. Great.
I then I tried to link source files into my project. How to do that is here:
https://jeremybytes.blogspot.com/2019/07/linking-files-in-visual-studio.html#:~:text=To%20link%20files%2C%20use%20the,CLICK%20THE%20%22Add%22%20BUTTON.
This seems to work, but every file I add requires another file, which references another file etc. It seemed endless. So that led me to the idea of just consuming the entire source code into my project and I haven't seen a good way to do that yet. I can't add a reference to the project as it just references the compiled dll which again, iLMerge can't combine.
I've also tried updating the tag within the .csproj file of PDFSharp to "module" to create a .netmodule file. This creates the file in the obj directory but throws an error:
\PDFsharp\code\PdfSharp\obj\Release\PdfSharp.netmodule' is not an assembly
Any help is appreciated. thanks.
UPDATE: I reversed everything and added the PdfSharp reference - back to where I was and changed my project to module and built which created a .netmodule file. Then used the assembly linker to create a .exe from that file. That worked using this command from VS Dev prompt.
al MyModule.netmodule /target:exe /out:MyProgram.exe /main:MyNamespace.MyClass.Main
This created the .exe, but when run without any other supporting files produces a file not found error:
System.IO.FileNotFoundException: Could not load file or assembly 'MyModule.netmodule' or one of its dependencies. The system cannot find the file specified.
Which is interesting since the module should be inside the exe right?
I have this working now, so I just wanted to place my results here since it is already posted.
My initial problem was that I mistakenly thought the PDFSharp.dll was causing the issue, but it was actually another group of 3rd Party dlls I was referencing.
I tried for hours to get iLMerge to work with the only success being it would kick out a single .exe file but it would have runtime errors.
Errors that I encountered:
Error: Unresolved assembly reference not allowed: Custom.Assembly.
Solution: Reference the assembly if possible. If you have many, you can reference a folder with the /lib:"C:\folderpath" switch.
Error: Unresolved assembly reference not allowed: ADotNetFramework.dll.
Solution: You can reference the desired .Net Framework path where iLMerge will search for missing references. Example: /targetplatform:"v4,C:<Path To Framework>.NETFramework\v4.8"
Error: The assembly 'xyz.dll' was not merged in correctly. It is still listed as an external reference in the target assembly.
Solution: You can get past this error with the /closed switch. However, I don't think I should even have gotten this error because 'xyz.dll' was a referenced dll to be combined.
Also - use the /log switch, it is extremely helpful in seeing exactly what iLMerge is doing and figuring out your issue. Example: /log:mylog.txt
This allowed me to see that iLMerge was finding duplicate namespaces, in the 3rd Party assemblies and automatically renaming them. Here is an example from my log:
Merging assembly 'My.Assembly.Name' into target assembly.
Duplicate type name: modifying name of the type '<>f__AnonymousType02' (from assembly 'My.Assembly.Name') to 'My.Assembly.Name.<>f__AnonymousType02'
Duplicate type name: modifying name of the type '<>f__AnonymousType12' (from assembly 'My.Assembly.Name') to 'My.Assembly.Name.<>f__AnonymousType12'
Duplicate type name: modifying name of the type '' (from assembly 'My.Assembly.Name') to 'My.Assembly.Name.
Finally - the solution that I found was not to use iLMerge. I found this Answer: https://stackoverflow.com/a/40786196/2596309
which used Costura.Fody
I installed the nuget package with:
Install-Package Costura.Fody -Version 4.1.0
Cleaned and built my solution and it created a single .exe file that I tested and it worked. Literally, I put 3 days of work into this and the solution took 3 minutes...
I've noticed in Visual Studio some classes have an option that if you look at their definition, you don't actually see the definition only the class's declaration and some documentation, for example:
Does anyone know how to make my classes lead to a similar file?
Thanks
I think some basic has to be explained here.
Source code is bunch of C# files (.cs). This is where code of your classes is
When you compile source code you will get an assembly (.dll). Assembly contains metadata about your classes and compiled binary code, but not actual source code.
When you compile your source code, Visual Studio produces also .PDB file along with your assembly. PDB files allows you to see the source code of the assembly. PDB files are necessary for debugging. It is somewhat similar to javascript source maps.
Now, when in Visual Studio you Go to Definition of a class or a method , then following can happen:
The class is in your solution -> you are navigated to the source code file (.cs)
The class is defined in a referenced assembly and PDB file is available -> you are navigated to source code extracted from the PDB file. You can debug it, (however, you cannot edit it).
The class is defined in a references assembly and PDB file is NOT available -> you are navigated the assembly metadata. (this is what happend on the picture you've posted)
So answer to your question is: isolate your assembly from .PDB and source code. However, you should be aware, that there are tools, that can reverse engineer C# code from the binary code that is in the assembly. It will be not exactly the same as your original source code but very similar.
This is the default behavior if Visual Studio can't find the PDB file which contains information on the location of the actual file and the line numbers in the compiled code.
This should work if you include a referenced assembly from another solution, and then rename the folder where the code is contained. Remove the PDB from the referenced location, and you will see this outline.
For you as a developer, showing the code is a feature: it helps you to debug and analyse problems in assemblies you have built. So I would advice to keep it on. Don't worry too much about other developers, if you don't send the PDB file, they won't see the code from Visual Studio. They still can read the assembly's source code using Reflector for example.
I converted my console app to Class Library project so that I can use dll again for multiple project. I am getting an error
Could not load file or assembly 'System.Net.Http.Primitives,
Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f711d50a3a' or
one of its dependencies. The system can not find the file
I've already tried the solution mentioned here: Could not load file or assembly System.Net.Http.Primitives. Located assembly's manifest definition does not match the assembly reference.
But no luck. Any suggestion
1- check if you are referencing an assembly which in turn referencing an old version of unity. for example let's say you have an assembly called ServiceLocator.dll which needs an old version of Unity assembly, now when you reference the ServiceLocator you should provide it with the old version of Unity, and that makes the problem.
2- may be the output folder where all projects build their assemblies, has an old version of unity.
you can use FuseLogVw application to find out who is loading the old assemblies, just define a path for the log, and run your solution, then check (in FuseLogvw) the first line where the Unity assembly is loaded, double click it and see the calling assembly, and here you go.
Your problem posted here previously: Could not load file or assembly or one of its dependencies
Please search before rising your question. Thanks
try right click -> Properties -> Build Action -> Embeded Resource should make it work
I will show you clearly the mean of Lucky Lefty. In Solution Explorer, right click on you .dll file and choose properties. The properties pane appears then on Buil Action option, you choose Embeded Resource. After that, you rebuil your solution.
You can view more information from here: http://www.codeproject.com/Articles/528178/Load-DLL-From-Embedded-Resource
Remember: Google search is your best friend.
I have a referenced assembly that keeps failing when I call it. I have the source for this assembly in a large project, Project A. I've compiled it and have been using it in Project B. Unfortunately Project B keeps failing and the stack trace shows that it fails on Project A's assembly.
It seems like I have two options:
Add Project A to Project B, change all references to the assembly to the project. This seems like it'd be a lot of work.
Use some third party tool, like Reflector, to step through the assembly.
Is there any other way I'm missing it? Is there anyway to link the projects easily?
Sorry if this sounds naive. it is the first time I've run into it.
if you have source code of project A
just include PDB file and assign referecne of the project A dll.
when you reach method of prject A press f11 which will take you to project A.
Add ProjectA.pdb to the folder that you're referencing the DLL from and Visual Studio should pick up the debugging symbols and step in automatically.
I am working on a c# codedom project which provides users to dynamically compile the c# code.
I am getting error when adding assembly dll of wpf (it is working fine for winforms). It is saying that "Can not find #### in assembly. Are you missing some reference" when I try to add the reference like "System.Windows.Media". But when I am adding the reference by its dll path like "C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.Printing.dll" then it is saying that "File C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.Printing.dll not found" but when I place the System.Printing.dll to the application executable folder, it is working fine.
Following is the code I am using to add the reference to compiler option:
CompilerParameters oParameters;
:
:
:
string lcAssemblyDll="C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.Printing.dll";
oParameters.ReferencedAssemblies.Add(lcAssemblyDll);
I am not able to understand the problem. Also is there any other approach to add the wpf assemblies?
Thanks
Well, I can't provide a thorough answer off the top of my head, but first of all you need to realize that a compilation reference is not the same as being able to resolve an assembly during application execution. So if that error was given during application execution I can imagine it throwing typeloader exceptions.
Second you are probably getting "Can not find #### in assembly. Are you missing some reference", because base types of classes you are dependent upon reside in assemblies to which the System.Windows.Media is referring.
You could try to solve this adding references to assemblies that get loaded during Assembly.ReflectionOnlyLoad of the assemblies you want referred.
If you add an event handler for AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve, you can add code that makes sure those assemblies may be loaded and then simply add references to the CodeCompileUnit.
I have run into one problem with this though and that was that some references get optimized away during compilation, so I implemented a nasty hack that simply adds a container class to the CodeCompileUnit which initializies the first constructable type found in each of those assemblies.
Hope that helps a bit.