I'm getting a FileNotFoundException when i'm trying to access the ExportedTypes of a loaded assembly.
Basically, I have a solution with two projects: Proj1 and Proj2. Proj1 has a reference from Proj2 and i'm trying to load a DLL of Proj1 through their path.
This was the code I tryed:
Dim sLoad As System.Reflection.Assembly
Try
sLoad = System.Reflection.Assembly.LoadFrom(PathDLL)
Dim ob = sLoad.ExportedTypes
Catch ex As System.IO.FileNotFoundException
Dim msh = ex.Message
End Try
I already checked AppDomain.CurrentDomain.GetAssemblies() and has the assemblie to my Proj2 so I don't understand why it doesn't work.
Already tryed LoadFile too.
This is my error message:
Could not load file or assembly 'Proj2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
This is my Fusion Log:
=== Pre-bind state information ===
LOG: DisplayName = Proj2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Users/jsantos/Source/Workspaces/UP/UP/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\jsantos\Source\Workspaces\UP\UP\bin\Debug\UP.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
Note I've also asked this question (with reproduction code) on Roslyn's GitHub
Create a new solution with 2 projects (CoreLibrary and DownstreamLibrary).
Add a project reference from DownstreamLibrary to CoreLibrary.
Run the following code and note that DownstreamLibrary no longer compiles.
Note that I've tried net461, netcoreapp2.1 and netstandard2.0 as target frameworks for the projects - same problem each time.
static async Task Main(string[] args)
{
MSBuildLocator.RegisterDefaults();
using (var workspace = MSBuildWorkspace.Create())
{
workspace.WorkspaceFailed += (sender, workspaceFailedArgs) => WriteLine(workspaceFailedArgs.Diagnostic.Message);
var solution = await workspace.OpenSolutionAsync(#"c:\source\ForRoslynTest\ForRoslynTest.sln");
WriteLine($"Loaded solution {solution.FilePath}");
var projectTree = workspace.CurrentSolution.GetProjectDependencyGraph();
foreach (var projectId in projectTree.GetTopologicallySortedProjects())
{
await CompileProject(workspace.CurrentSolution.GetProject(projectId));
}
}
}
private static async Task CompileProject(Project project)
{
WriteLine($"Compiling {project.Name}. It has {project.MetadataReferences.Count} metadata references.");
var compilation = await project.GetCompilationAsync();
var errors = compilation.GetDiagnostics().Where(diagnostic => diagnostic.Severity == DiagnosticSeverity.Error);
if (errors.Any())
{
WriteLine($"COMPILATION ERROR: {compilation.AssemblyName}: {errors.Count()} compilation errors: \n\t{string.Join("\n\t", errors.Where(e => false).Select(e => e.ToString()))}");
}
else
{
WriteLine($"Project {project.Name} compiled with no errors");
}
}
You will receive the following output:
Msbuild failed when processing the file 'c:\source\ForRoslynTest\DownstreamLibrary\DownstreamLibrary.csproj' with message: C:\Program Files\dotnet\sdk\2.1.602\Microsoft.Common.CurrentVersion.targets: (1548, 5): The "Microsoft.Build.Tasks.ResolveNonMSBuildProjectOutput" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
Found project reference without a matching metadata reference: c:\source\ForRoslynTest\CoreLibrary\CoreLibrary.csproj
Loaded solution c:\source\ForRoslynTest\ForRoslynTest.sln
Compiling CoreLibrary. It has 113 metadata references.
Project CoreLibrary compiled with no errors
Compiling DownstreamLibrary. It has 0 metadata references.
COMPILATION ERROR: DownstreamLibrary: 3 compilation errors:
c:\source\ForRoslynTest\DownstreamLibrary\Class1.cs(1,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
c:\source\ForRoslynTest\DownstreamLibrary\Class1.cs(5,18): error CS0518: Predefined type 'System.Object' is not defined or imported
c:\source\ForRoslynTest\DownstreamLibrary\Class1.cs(5,18): error CS1729: 'object' does not contain a constructor that takes 0 arguments
So my question is how do I fix the above errors and get DownstreamLibrary to compile?
EDIT
I'm 99% sure the underlying cause is this error
The "Microsoft.Build.Tasks.ResolveNonMSBuildProjectOutput" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0
I've confirmed with procmon that it's loading the following DLL (C:\Program Files\dotnet\sdk\2.1.602\Microsoft.Build.Tasks.Core.dll) which I've confirmed with ILSpy DOESN'T have the ResolveNonMSBuildProjectOutput task in it. Older versions of this DLL did have this task.
I found a manual workaround to this WorkspaceFailed error:
[Failure] Msbuild failed when processing the with message: The "Microsoft.Build.Tasks.ResolveNonMSBuildProjectOutput" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
There were a few resolution steps:
following https://github.com/microsoft/msbuild/issues/4770 I updated VS 2019 from 16.2 to 16.5.3... This didn't fix my bug, but it's worth documenting I did this.
I upgraded my Microsoft.Build.* and Microsoft.CodeAnalysis dependencies to latest, THIS DIDN'T FIX THINGS YET, same bug.
I navigated to C:\Program Files\dotnet\sdk which previously had a few directories:
1.0.0/ 1.0.0-rc4-004771/ 2.0.3/ 2.1.505/
1.0.0-preview1-002702/ 1.0.3/ 2.1.202/ 3.1.100/
1.0.0-preview2-003121/ 1.0.4/ 2.1.4/ 3.1.201/
1.0.0-preview4-004233/ 1.1.0/ 2.1.502/ NuGetFallbackFolder/
I renamed this to sdk_o and created a new folder C:\Program Files\dotnet\sdk, copying in only 3.1.201/
Success! This error was gone, but running my roslyn app then resulted in some error like (paths stripped)
[Failure] Msbuild failed when processing the file with message The "ProcessFrameworkReferences" task failed unexpectedly. System.IO.FileNotFoundException: Could not load file or assembly 'NuGet.Frameworks, Version=5.5.0.4, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified. File name: 'NuGet.Frameworks, Version=5.5.0.4, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
Solved this one by adding NuGet.ProjectModel 5.5.1 to my project, the csproj now has the following package references:
<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="16.5.0" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Framework" Version="16.5.0" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.2.6" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="16.5.0" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="3.5.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.5.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="3.5.0" />
<PackageReference Include="NuGet.ProjectModel" Version="5.5.1" />
</ItemGroup>
No more WorkspaceFailed events for this code:
Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults();
var workspace = MSBuildWorkspace.Create();
workspace.WorkspaceFailed += (s, e) => { Console.WriteLine(e.Diagnostic); };
var project = await workspace.OpenProjectAsync(#"C:/path/to.csproj");
The csproj I'm loading with Roslyn looks as follows:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<OutputType>Library</OutputType>
<ApplicationIcon />
<StartupObject />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\dependencies\some.csproj" />
</ItemGroup>
</Project>
Getting error as "Application has been upgraded" while executing selenium script
1503335038389 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/XPIProvider.jsm: ["XPIProvider"]
1503335038402 addons.manager DEBUG Loaded provider scope for resource://gre/modules/LightweightThemeManager.jsm: ["LightweightThemeManager"]
1503335038434 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/GMPProvider.jsm
1503335038452 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/PluginProvider.jsm
1503335038456 addons.manager DEBUG Starting provider: XPIProvider
1503335038458 addons.xpi DEBUG startup
1503335038463 addons.xpi INFO Mapping fxdriver#googlecode.com to C:\Users\admin\AppData\Local\Temp\anonymous8300782133030252087webdriver-profile\extensions\fxdriver#googlecode.com
1503335038467 addons.xpi DEBUG Ignoring file entry whose name is not a valid add-on ID: C:\Users\admin\AppData\Local\Temp\anonymous8300782133030252087webdriver-profile\extensions\webdriver-staging
1503335038468 addons.xpi INFO Removing all system add-on upgrades.
1503335038472 addons.xpi INFO SystemAddonInstallLocation directory is missing
1503335038478 addons.xpi INFO Mapping aushelper#mozilla.org to C:\Program Files (x86)\Mozilla Firefox\browser\features\aushelper#mozilla.org.xpi
1503335038484 addons.xpi INFO Mapping e10srollout#mozilla.org to C:\Program Files (x86)\Mozilla Firefox\browser\features\e10srollout#mozilla.org.xpi
1503335038485 addons.xpi INFO Mapping firefox#getpocket.com to C:\Program Files (x86)\Mozilla Firefox\browser\features\firefox#getpocket.com.xpi
1503335038783 addons.xpi INFO Mapping screenshots#mozilla.org to C:\Program Files (x86)\Mozilla Firefox\browser\features\screenshots#mozilla.org.xpi
1503335038785 addons.xpi INFO Mapping webcompat#mozilla.org to C:\Program Files (x86)\Mozilla Firefox\browser\features\webcompat#mozilla.org.xpi
1503335038794 addons.xpi INFO Mapping {972ce4c6-7e08-4474-a285-3208198ce6fd} to C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi
1503335038794 addons.xpi DEBUG Skipping unavailable install location app-system-share
1503335038795 addons.xpi DEBUG Skipping unavailable install location app-system-local
1503335038799 addons.xpi DEBUG checkForChanges
1503335038801 addons.xpi INFO SystemAddonInstallLocation directory is missing
Code which i am executing
package newpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Myclass {
public static void main(String[] args) {
System.setProperty("webdriver.firefox.marionette","C:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
String baseUrl = "facebook.com";;
String tagName = ""; driver.get(baseUrl);
tagName = driver.findElement(By.id("email")).getTagName();
System.out.println(tagName);
driver.close();
System.exit(0);
}
}
I have VS 2015 and a web api soultion.
I get this error now
Server Error in '/SiteIntegration' Application.
Failed to compile both on .NET 4.5 and on .NET 4.0. 4.5 Exception: System.InvalidOperationException: Failed to compile the following symbols: 'NET40;NET45'
Source file 'C:\windows\TEMP\cq1ln2ls.0.cs' could not be found
Source file 'C:\windows\TEMP\cq1ln2ls.1.cs' could not be found
Source file 'C:\windows\TEMP\cq1ln2ls.2.cs' could not be found
Source file 'C:\windows\TEMP\cq1ln2ls.3.cs' could not be found
No source files specified
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileInternally(String fileName, List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String outputFolder, String compilerVersion, Int32 tryCount)
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileAssembly(List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String assemblyFileName, String outputFolder). 4.0 Exception: System.InvalidOperationException: Failed to compile the following symbols: 'NET40'
Source file 'C:\windows\TEMP\ggvdikxf.0.cs' could not be found
Source file 'C:\windows\TEMP\ggvdikxf.1.cs' could not be found
Source file 'C:\windows\TEMP\ggvdikxf.2.cs' could not be found
Source file 'C:\windows\TEMP\ggvdikxf.3.cs' could not be found
No source files specified
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileInternally(String fileName, List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String outputFolder, String compilerVersion, Int32 tryCount)
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileAssembly(List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String assemblyFileName, String outputFolder)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Failed to compile both on .NET 4.5 and on .NET 4.0. 4.5 Exception: System.InvalidOperationException: Failed to compile the following symbols: 'NET40;NET45'
Source file 'C:\windows\TEMP\cq1ln2ls.0.cs' could not be found
Source file 'C:\windows\TEMP\cq1ln2ls.1.cs' could not be found
Source file 'C:\windows\TEMP\cq1ln2ls.2.cs' could not be found
Source file 'C:\windows\TEMP\cq1ln2ls.3.cs' could not be found
No source files specified
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileInternally(String fileName, List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String outputFolder, String compilerVersion, Int32 tryCount)
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileAssembly(List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String assemblyFileName, String outputFolder). 4.0 Exception: System.InvalidOperationException: Failed to compile the following symbols: 'NET40'
Source file 'C:\windows\TEMP\ggvdikxf.0.cs' could not be found
Source file 'C:\windows\TEMP\ggvdikxf.1.cs' could not be found
Source file 'C:\windows\TEMP\ggvdikxf.2.cs' could not be found
Source file 'C:\windows\TEMP\ggvdikxf.3.cs' could not be found
No source files specified
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileInternally(String fileName, List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String outputFolder, String compilerVersion, Int32 tryCount)
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileAssembly(List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String assemblyFileName, String outputFolder)
Source Error:
Line 9: {
Line 10: // Initialize the profiler
Line 11: NHibernateProfiler.Initialize();
Line 12:
Line 13: // You can also use the profiler in an offline manner.
Source File: C:\Users\compName\Source\Repos\Siteintegration\SiteIntegration\App_Start\NHibernateProfilerBootstrapper.cs Line: 11
Stack Trace:
[InvalidOperationException: Failed to compile both on .NET 4.5 and on .NET 4.0. 4.5 Exception: System.InvalidOperationException: Failed to compile the following symbols: 'NET40;NET45'
Source file 'C:\windows\TEMP\cq1ln2ls.0.cs' could not be found
Source file 'C:\windows\TEMP\cq1ln2ls.1.cs' could not be found
Source file 'C:\windows\TEMP\cq1ln2ls.2.cs' could not be found
Source file 'C:\windows\TEMP\cq1ln2ls.3.cs' could not be found
No source files specified
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileInternally(String fileName, List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String outputFolder, String compilerVersion, Int32 tryCount)
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileAssembly(List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String assemblyFileName, String outputFolder). 4.0 Exception: System.InvalidOperationException: Failed to compile the following symbols: 'NET40'
Source file 'C:\windows\TEMP\ggvdikxf.0.cs' could not be found
Source file 'C:\windows\TEMP\ggvdikxf.1.cs' could not be found
Source file 'C:\windows\TEMP\ggvdikxf.2.cs' could not be found
Source file 'C:\windows\TEMP\ggvdikxf.3.cs' could not be found
No source files specified
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileInternally(String fileName, List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String outputFolder, String compilerVersion, Int32 tryCount)
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileAssembly(List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String assemblyFileName, String outputFolder)]
HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileAssembly(List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String assemblyFileName, String outputFolder) +859
[InvalidOperationException: System.InvalidOperationException: Failed to compile both on .NET 4.5 and on .NET 4.0. 4.5 Exception: System.InvalidOperationException: Failed to compile the following symbols: 'NET40;NET45'
Source file 'C:\windows\TEMP\cq1ln2ls.0.cs' could not be found
Source file 'C:\windows\TEMP\cq1ln2ls.1.cs' could not be found
Source file 'C:\windows\TEMP\cq1ln2ls.2.cs' could not be found
Source file 'C:\windows\TEMP\cq1ln2ls.3.cs' could not be found
No source files specified
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileInternally(String fileName, List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String outputFolder, String compilerVersion, Int32 tryCount)
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileAssembly(List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String assemblyFileName, String outputFolder). 4.0 Exception: System.InvalidOperationException: Failed to compile the following symbols: 'NET40'
Source file 'C:\windows\TEMP\ggvdikxf.0.cs' could not be found
Source file 'C:\windows\TEMP\ggvdikxf.1.cs' could not be found
Source file 'C:\windows\TEMP\ggvdikxf.2.cs' could not be found
Source file 'C:\windows\TEMP\ggvdikxf.3.cs' could not be found
No source files specified
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileInternally(String fileName, List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String outputFolder, String compilerVersion, Int32 tryCount)
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileAssembly(List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String assemblyFileName, String outputFolder)
at HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileAssembly(List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String assemblyFileName, String outputFolder)
ImageRuntimeVersion: v4.0.30319]
HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileAssembly(List`1 sources, HashSet`1 assemblies, HashSet`1 defineSymbols, String assemblyFileName, String outputFolder) +1189
HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.RegisterAppenderUsingNHibernateLogger() +387
HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.StartNHibernateProfiling() +170
HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize(NHibernateAppenderConfiguration configuration) +172
SiteIntegration.App_Start.NHibernateProfilerBootstrapper.PreStart() in C:\Users\compName\Source\Repos\Siteintegration\SiteIntegration\App_Start\NHibernateProfilerBootstrapper.cs:11
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +260
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +146
WebActivatorEx.BaseActivationMethodAttribute.InvokeMethod() +102
WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode) +434
WebActivatorEx.ActivationManager.Run() +100
[InvalidOperationException: The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +874
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +169
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +133
System.Web.Compilation.BuildManager.ExecutePreAppStart() +176
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +734
[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +579
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +120
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +712
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.81.0
The NHibernate support people just pointed me in the right direction to fix this.
The problem was that IIS didn't have permissions to access the windows\temp folder.
I went to the IIS AppPool > Advanced Settigns > Identity
And changed it to LocalSystem (since I'm the admin on my PC). That fixed it for me. Hope this helps.
Can you try with the latest build?