Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileLoadException: API restriction: The assembly has already loaded from a different location #2

Open
chucklu opened this issue Apr 23, 2021 · 3 comments

Comments

@chucklu
Copy link
Owner

chucklu commented Apr 23, 2021

2021-04-23 10:31:17.122 +08:00 [ERR] System.IO.FileLoadException: API restriction: The assembly 'bin\Debug\Edenred.Rdc.Pdf.dll' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.ReflectionOnlyLoadFrom(String assemblyFile)
at DependentChecker.MainWindow.SetInfoText(String dependencyPath, Boolean needBindingRedirect) in C:\Users\clu\source\repos\DependentChecker\DependentChecker\MainWindow.xaml.cs:line 63
at DependentChecker.MainWindow.DependencyChoose_Click(Object sender, RoutedEventArgs e) in C:\Users\clu\source\repos\DependentChecker\DependentChecker\MainWindow.xaml.cs:line 38
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)

@chucklu
Copy link
Owner Author

chucklu commented May 11, 2021

https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.reflectiononlyload?view=net-5.0
You cannot execute code from an assembly loaded into the reflection-only context. To execute code, the assembly must be loaded into the execution context as well, using the Load method.

The reflection-only context is no different from other contexts. Assemblies that are loaded into the context can be unloaded only by unloading the application domain.

@chucklu
Copy link
Owner Author

chucklu commented May 11, 2021

https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.reflectiononlyloadfrom?view=net-5.0
Dependencies are not automatically loaded into the reflection-only context. To automatically load dependencies, handle the ReflectionOnlyAssemblyResolve event and load the dependency in the event handler.

You cannot execute code from an assembly that has been loaded into the reflection-only context. To execute the code, load the assembly with the LoadFile method.

The assemblyFile parameter must refer to a URI without escape characters. This method supplies escape characters for all invalid characters in the URI.

The path specified for assemblyFile is relative to the current directory. The assembly is loaded into the domain of the caller.

The reflection-only context is no different from other contexts. Assemblies that are loaded into the context can be unloaded only by unloading the application domain.

@chucklu
Copy link
Owner Author

chucklu commented May 11, 2021

Assemblies that are loaded into the context can be unloaded only by unloading the application domain.
Maybe we need to create an new AppDomain when click the choose dependency or choose folder button.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant