Roslyn Issue - Metadata file System.Runtime.dll could not be found - c#

We use the CodeDomProvider to compile C# and VB code in our app. We have been using Roslyn ever since it came out for this purpose. We are currently using version 1.0.8 of Roslyn. Recently, we started getting this error:
Metadata file
'C:\Windows\system32\config\systemprofile\AppData\Local\assembly\dl3\8GTGDQKQ.4QR\V42JN801.7NM\36a4366e\f1f27652_1972d301\System.Runtime.dll'
could not be found
I'm not adding this reference manually. Roslyn seems to be adding this reference in arbitrarily. I've tried adding a reference to System.Runtime.dll inside our app's bin folder, but the problem does not go away.
I've logged a bug with the repo here, but not response:
https://github.com/dotnet/roslyn/issues/24630
Has anyone else seen this bug? Is there a workaround? Why is the compiler looking for System.Runtime.dll at this path? Why won't it just use the DLL inside our bin folder?

I found a workaround. If I copy the file System.Runtime.dll from my bin folder to the path C:\Windows\system32\config\systemprofile\AppData\Local\assembly\dl3\8GTGDQKQ.4QR\V42JN801.7NM\36a4366e\f1f27652_1972d301 the assembly compiles fine.
So, Roslyn is ignoring the path I am telling it that System.Runtime.dll is in and expecting to find the DLL in a hard coded path instead. This does seem like a bug to me.

Related

Consume all source code (non-compiled) from one project into another (PDFSharp)

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...

Referenced namespace not being recognized

I cant get the namespace system.runtime.caching to be recognized despite adding the reference. Based on research to similar problems, I've checked the target framework and all seems in order (currently 4.5.2).
Has anyone got a suggestion on how to solve this?
Probably the problem is you are putting your code in App_Code folder. Files in this folder are treated as content by default. You can solve this issue setting Build Action to Compile for .cs files in this folder.
However, you shouldn't use this folder for code, it will surely cause problems. I recommend you to move your code to another folder Infrastructure or Code.
I think you may have to add a reference to System.Core in your project. See these links, particularly the first one:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/804fdc52-1082-4f93-b256-902ab300d78d/problem-with-namespacesystemruntimecaching?forum=vbgeneral
The type or namespace name 'Caching' does not exist in the namespace 'System.Runtime'
Have you tried restarting Visual Studio? I added the reference and I was able to use it as a namespace.

Reference could not be found.(are you missing a using directive...)

I have created a project library dll and it resides in the bin directory of the solution. I've got a second solution that references that dll. In the VS2013 IDE my 'Using' directive is happy and down n the code when I reference a class in the dll the code is happy. If I view the object reference in the object browser all look ok. I've also looked in the csproj file and the correct reference is in there. When I try to build the project I receive the type or namespace for my dll could not be found error message. I've tried cleaning first, I've also closed VS2013 and restarted all to no avail. I've also tried copying the dll to the local bin directory for this solution and re-referencing and still no joy
Ok, I found the solution. The project that I am referencing is targeting .net4.5.2 of the framework. THe project that was referencing it was only referencing .net4.5 I have set this to .net4.5.2 and it now builds.
Thanks
For all the input

VS 2010: C# Project Cannot Open DLL

I'm having an issue building a project that references a DLL located in the project's bin folder, which up until yesterday was building and running without issue.
The error I'm getting is fatal error CS0009: Metadata file 'c:\MyProject\bin\myClient.dll' could not be opened -- 'Error importing module 'myClient.netmodule' of assembly 'c:\MyProject\bin\myClient.dll' -- The system cannot find the file specified.' Intellisense is similarly complaining that The type or namespace 'Api' does not exist in the namespace 'Client' since it can't find the DLL.
Let me know if you think this is a duplicate, but I've viewed several similar posts and the solutions did solve my problem. Here are some examples:
Visual Studio 2010 — are you missing a using directive or an assembly reference?
VS2010 - Getting “type or namespace name could not be found” but everything seems ok?
Stymied by ASP.NET Compilation Error CS0009
Metadata file '…\Release\project.dll' could not be found in Visual Studio
Visual Studio 2010: Metadata file “…/Debug/Graph.dll” could not be found
Metadata file … could not be found error when building projects
Specifically, I've tried the following solutions (and combinations of these):
Cleaned and rebuilt my project.
Made sure that the target framework is not a 'client profile' version of .NET
Verifyied that the dll has been added as a project reference
Removed and re-added the project reference
Verified that the project is showing the DLL in the References section in Visual Studio
Repaired .NET
Verified the location of the DLL (it is in the local project's bin folder as given by the error)
Tried other versions of .NET
Closed and restarted Visual Studio
Rebooted my machine
Verified there are no hidden characters surrounding the 'using' statement
Removed all code changes since the last working build
Verified the settings in Configuration manager, including that 'Build' is checked
The project calling the DLL is a small class library that resides in a solution with one other small project (a console application). The DLL is an external DLL that I've been using successfully for several weeks in this project/solution. The error arises regardless of whether I build the project from the solution or by itself.
Any ideas about what could be going on?
Have you included bin folder in your project accidentally? If yes that might cause the issue. You can't include bin folder in your project as the bin folder will be created by the VS. If you accidentally include bin folder in your project, the bin project will be set to Copy to output which when you compile, the file is deleted and copied to output by Visual Studio that trigger weird behavior that some file is missing.
Hopes this help
Well I'm not sure exactly what happened here, but here is what finally resolved the issue:
A good-old-fashioned delete every single file and rebuild the project from those files from scratch. I gave +1 to some of the responses because they were useful to consider, and because there was probably a messed-up reference some where as Jonathon Wood suggested.

VS2010 C# missing project dll during build

I have problem with build in VS2010. I´m trying to develop small Prism, MVVM application.
I added new project "Toolbar" to my solution "MyApp" and during the build I get following error (propably project´s dll is not created for some reason):
Error 2 Could not load referenced assembly
"C:\net\projects\MyApp\MyApp.Modules.Toolbar\bin\Debug\MyApp.Modules.Toolbar.dll".
Caught a FileNotFoundException saying "Could not load file or assembly
'C:\net\projects\MyApp\MyApp.Modules.Toolbar\bin\Debug\MyApp.Modules.Toolbar.dll'
or one of its dependencies. The system cannot find the file
specified.".
C:\net\projects\MyApp\MyApp\ResGen MyApp
I´m quite new to VS2010 and C# so I really don´t know what happend, wheter project dll is missing because of some mistake in source code or why this can even happend? I also don´t know how to find such a mistake in source code, because VS shows up only the error mentioned above. Dependenies of the project should be ok i guess, file MyApp.Modules.Toolbar.dll really doesn´t exist in any folder on my hdd.
The problem was the bad class name defined in xaml of Toolbar project (UserControl x:Class="BAD CLASS HERE").
After many googles for a similar problem where I had at one time toyed with using open office in a .net project and then all my aspx pages had the blue squiggely line saying cli_uno couldn't be found which was referenced no where and in none of my project or lib files.
I deleted all the bin folders, a dll referencing it was hiding in one of them and making vs2010 freak out.
I realize this isn't the exact solution to the above but there isn't much out there for this error and it is a head scratcher and deleting all the bin folders worked for me so it's something to try.
You provide too litle information, so I'll ask some questions (and some possible fixes):
Is the file at the specified path to begin with?
If not, is there a project you need to build to create the dll?
If there is such project, does it build the .dll where yours is looking for it -- if not, you either need to copy it by hand or set up a post-build process to do the copy automatically after each build
If there is no such project, do you have the .dll itself somewhere. If yes, you need to copy it to the correct location.
If the .dll is at the correct location, is there some protection preventing the other project to access it?

Categories

Resources