问题
I have a C# Solution which spits out an executable binary on compilation. The binary depends on a library which is the product of another solution which I wrote, all code concerned I created.
Recently I played around with a number of project settings in a fairly haphazard manner, trying to get a feel for how CLR building an linking works. Unfortunately (predictably?) I have managed to break the linking on my binary but I'm not sure how to fix the issue.
- When I my binary I get the following feedback before the application falls over
Loading assemblies........Could not add types in assembly MY.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information
- The fusion log for the MY.Library.resources DLL is below. The mentioned binary doesn't exist and I don't know where or why it's trying to be loaded.
>
All probing URLs attempted and failed
*** Assembly Binder Log Entry (22/04/2011 @ 10:34:17) ***
The operation failed. Bind result: hr
= 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll Running under executable G:\SVN\dev\Debug\MYExecutable.exe
--- A detailed error log follows.
=== Pre-bind state information === LOG: User = UBERIT\gavina LOG: DisplayName = MY.Library.resources, Version=1.0.0.0, Culture=en, PublicKeyToken=null (Fully-specified) LOG: Appbase = file:///G:/SVN/dev/Debug LOG: Initial PrivatePath = x64 LOG: Dynamic Base = NULL LOG: Cache Base = NULL LOG: AppName = MYExecutable.exe Calling assembly : MY.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
=== LOG: This bind starts in default load context.
LOG: Using application configuration file: G:\BuildSVN\apps\ExecSys\MYExecutable\dev\Debug\MYExecutable.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: Attempting download of new URL file:///G:/SVN/dev/Debug/en/MY.Library.resources.DLL.
LOG: Attempting download of new URL file:///G:/SVN/dev/Debug/en/MY.Library.resources/MY.Library.resources.DLL.
LOG: Attempting download of new URL file:///G:/SVN/dev/Debug/x64/en/MY.Library.resources.DLL.
LOG: Attempting download of new URL file:///G:/SVN/dev/Debug/x64/en/MY.Library.resources/MY.Library.resources.DLL.
LOG: Attempting download of new URL file:///G:/SVN/dev/Debug/en/MY.Library.resources.EXE. LOG: Attempting download of new URL file:///G:/SVN/dev/Debug/en/MY.Library.resources/MY.Library.resources.EXE.
LOG: Attempting download of new URL file:///G:/SVN/dev/Debug/x64/en/MY.Library.resources.EXE.
LOG: Attempting download of new URL file:///G:/SVN/dev/Debug/x64/en/MY.Library.resources/MY.Library.resources.EXE.
LOG: All probing URLs attempted and failed.
- Are 'Resources' DLLs Implicit? Or do I necessarily have a reference to this DLL? How should I find the reference in the SLN for the library?
TL;DR
- How do I remove a reference to a non-existant resources DLL?
回答1:
- Are 'Resources' DLLs Implicit? Or do I necessarily have a reference to this DLL? How should I find the reference in the SLN for the library?
- How do I remove a reference to a non-existant resources DLL?
The resouces is actually embedded in your dll. You don't need to reference it.
The reason you see "library.resouce" is because your code asks .net to load assembly manually, either though app.config, or AppDomain.AssemblyResolve event.
In your case, I think it's the latter. Just find that event handler and do something like this:
static System::Reflection::Assembly^ HandleAssemblyResolveEvent(System::Object^ sender, System::ResolveEventArgs^ args)
{
System::String^ assemblyName = args->Name->Substring(0, args->Name->IndexOf(","));
if(assemblyName->EndsWith(".resources")) return nullptr;
}
The code is in C++\CLI but it's easy to translate to C#.
回答2:
I just had a problem like that, visual studio 2010 couldn't find all kinds of resources dlls, like xaml.resources.dll and presentationcore.resources.dll. Turns out (in the end) it was the result of me moving the MainWindow.xaml to a subfolder. I don't know if it's the same with windows forms, but to anyone out there doing WPF: DO NOT MOVE MainWindow.xaml. Another day of my life wasted.
回答3:
Normally your referenced DLLs should be in the References
folder in your C# project (you should also add your external DLLs from there too). You can right-click the DLL you want to kick out and click Remove
.
来源:https://stackoverflow.com/questions/5755852/c-sharp-resources-dll-failing-to-be-loaded-as-it-doesnt-exist-how-might-i