I have a WPF exe that after being built, if the exe is renamed, will not run because a FileNotFoundException is thrown. I have never seen this in ten years of working with .NET executables and this is not supposed to be a problem. Our exe name is built as "Installer.exe", but if we rename it to anything else and try to run it it fails with the following call stack:
Application: test.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
at System.Reflection.RuntimeAssembly._nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(System.Reflection.AssemblyName, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
at System.Reflection.Assembly.Load(System.Reflection.AssemblyName)
at System.Windows.Navigation.BaseUriHelper.GetLoadedAssembly(System.String, System.String, System.String)
at MS.Internal.AppModel.ResourceContainer.GetResourceManagerWrapper(System.Uri, System.String ByRef, Boolean ByRef)
at MS.Internal.AppModel.ResourceContainer.GetPartCore(System.Uri)
at System.IO.Packaging.Package.GetPartHelper(System.Uri)
at System.IO.Packaging.Package.GetPart(System.Uri)
at System.Windows.Application.GetResourceOrContentPart(System.Uri)
at System.Windows.Application.LoadComponent(System.Object, System.Uri)
at Installer.App.InitializeComponent()
at Installer.App.Main()
If I debug the executable I can further expand that to:
System.IO.FileNotFoundException: 'Could not load file or assembly 'Installer, Version=1.0.0.0,
Culture=neutral' or one of its dependencies. The system cannot find the file specified.'
I have also investigated the Fusion Log:
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\Users\dande\Downloads\test.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = Installer, Version=1.0.0.0, Culture=neutral
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Installer, Version=1.0.0.0, Culture=neutral | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/dande/Downloads/
LOG: Initial PrivatePath = NULL
Calling assembly : PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
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:///C:/Users/dande/Downloads/Installer.DLL.
LOG: Attempting download of new URL file:///C:/Users/dande/Downloads/Installer/Installer.DLL.
LOG: Attempting download of new URL file:///C:/Users/dande/Downloads/Installer.EXE.
LOG: Attempting download of new URL file:///C:/Users/dande/Downloads/Installer/Installer.EXE.
And I have investigated and ruled out the following:
We are not using Assembly.Load to load 'Installer' (which is the executing assembly)
We do not have any pack:// usages in XAML.
We have no code analysis warnings, errors, or XAML errors
It is not related to a application configuration file
It is not related to the application manifest
Application crashes even if I change the code to use a normal Window and not our MainWindow (eliminating a lot of XAML from the equation)
.NET version doesn't make a difference. It's targeting and built for .NET 4.6, but changing this doesn't change the outcome
Confirmed that all dependencies are referenced/present using DotPeek/JustDecompile
Confirmed that all namespaces internally are still 'Installer'
Investigated the partial binding via reading documentation, but this isn't a reference issue, the error indicates its the executing assembly itself that is the issue (it's looking for itself?)
Is not related to code signing as it occurs with or without it
It is not related to strong name signing as we are not using that
Changing the project properties assembly output name but leaving the namespace as Installer works and presents no issues
Things I have observed:
This happens prior to OnStartup. I cannot debug into the application.
It appears to be PresentationCore.dll (from Fusion Log) originating this issue
Confirmed with ProcMon.exe that it is in fact trying to access one of the four logged fusion log paths (Installer.DLL, Installer/Installer.DLL, Installer.EXE, Installer.Installer.EXE)
This occurs on any environment and I can reproduce locally by building the solution then renaming, the output file and then running it
If I copy the executable and rename that and run it it works fine because Installer.exe is present in the same directory
I have never seen this problem before and researching it I have not been successful because I'm just finding all the basic stuff new developers typically run into with reference problems and the like.
My only assumption is that possibly its XAML related but I haven't found anything in XAML out of the ordinary and we don't have any pack:// usages or anything.
Only way we managed to solve this was by adding an AssemblyName attribute to the .csproj file with the name of the assembly after renaming. That way you wouldn't have to do the rename anymore yourself.
Related
We are having an issue related to starting a few in house developed .NET applications on Windows 10 Version 1607 machines. Sometimes starting an application doesn't succeed. This is because loading a dependent .NET assembly fails. The error message is:
System.IO.FileLoadException: Could not load file or assembly
'[assemblyname], Version=[version], Culture=neutral,
PublicKeyToken=[publickeytoken]' or one of its dependencies. The data
area passed to a system call is too small. (Exception from HRESULT:
0x8007007A)
The issue happens about 10% of the application startups in different .NET applications. It happens with 32-bit as well as 64-bit applications. During all the startups also many other applications start that start up OK. I wonder why we get the 0x8007007a error? Maybe it is collateral due to a heap corruption that happened before?
You can see related logging from FUSLOGVW below. The filepaths and assembly names are anonymised. The assembly that is attempted to be loaded has quite a long name (59 characters without the .dll postfix). As a test, we changed the name of the assembly to a shorter name. Unfortunately the issue remained. Adding a probing path in the exe.config also did not fix the issue.
Furthermore, there seems to be code of an older version of the Microsoft Assembly Resolver available at Github: https://github.com/fixdpt/shared-source-cli-2.0. I suspect there is something wrong in the ConstructCodeBaseList in adlmgr.cpp. But I can't figure out what triggers the issue.
*** Assembly Binder Log Entry (2020/01/30 # 13:48) ***
The operation failed.
Bind result: hr = 0x8007007a. The data area passed to a system call is too small.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Program Files (x86)\XXX\XXX\XX.X.X.X\XXX\XXXXXXXXXXXXXX\ApplicationWeWantToStart.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = AnAssem.blyWi.th.AVeryLon.gNameAA.AAAAAAAA.AAAAAAAAAAA.AAAA, Version=13.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXXXX
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/XXX/XXX/XX.X.X.X/XXX/XXXXXXXXXXXXXX/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = ApplicationWeWantToStart.exe
Calling assembly : ApplicationWeWantToStart, Version=13.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXXXX.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files (x86)\XXX\XXX\XX.X.X.X\XXX\XXXXXXXXXXXXXX\ApplicationWeWantToStart.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: AnAssem.blyWi.th.AVeryLon.gNameAA.AAAAAAAA.AAAAAAAAAAA.AAAA, Version=13.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXXXX
LOG: GAC Lookup was unsuccessful.
ERR: Error occurred constructing the probing codebase list.
ERR: Unrecoverable error occurred during pre-download check (hr = 0x8007007a).
Any change your startup issue may be related to this Microsoft Support Link
In a C# application I'm Loading 2 DLLs provided by user during runtime (not a pre-difined reference) Let it be A.dll, B.dll.
A.dll is referencing B.dll, but they are supplied separately.
When I try to access a method from A.dll, with a parameter of type that is declared in B.dll, I get an:
"Could not load file or assembly 'B, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' or one of its dependencies. The system cannot
find the file specified.".
error, although both DLLs were loaded. Even calling MethodInfo.GetParameters() will throw the exception.
Tried to Load both DLLs with different methods:
Assembly.Load(<Path>)
Assembly.LoadFile(<Path>)
Assembly.LoadFrom(<Path>)
I set the reference in project A to B.dll as "Copy Local = false".
Any usage of types and method from A or B which does not involve the connection described above seems to work fine.
I made sure both assembly were loaded with
AppDomain.CurrentDomain.GetAssemblies()
(they both are).
I have to presume I don't have developer access to A.dll and B.dll projects (provided by users), but for testing purpose I can try to change stuff in them as well.
Fusion log For A.dll:
*** Assembly Binder Log Entry (8/10/2019 # 11:47:04 PM) ***
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 C:\Users\<username>\AppData\Local\JetBrains\Installations\ReSharperPlatformVs15_95cb26a8\JetBrains.ReSharper.TaskRunner.CLR45.x64.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = A, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///<project fullpath>/bin/Debug
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = C:\Users\<username>\AppData\Local\Temp\u5r0nb10.kwf\k2mn3yzp.umi
LOG: AppName = AppTest
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
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:///<project fullpath>/bin/Debug/A.DLL.
LOG: Attempting download of new URL file:///<project fullpath>/bin/Debug/A/A.DLL.
LOG: Attempting download of new URL file:///<project fullpath>/bin/Debug/A.EXE.
LOG: Attempting download of new URL file:///<project fullpath>/bin/Debug/A/A.EXE.
LOG: All probing URLs attempted and failed.
You are missing are probably missing another dependency of B.dll it.
When you try to load a dll, Windows will try to look all dependency of it (other dlls). Unfortunately, the error you see will be:
"The system can not find the specified"
All dependencies of B.dll should be also copied to the local directory.
Use Dependency Walker .NET to find the missing dependencies.
Since everything is "there" I've got another possibility. Normally, this is obscure, but it can happen.
If B.dll depends on a higher version of a dll that your main program depends on, sometimes the lower version dll you loaded can't be made to work with the higher version B wants. In that case, you get this error.
I have a WPF application that follows the MVVM pattern. We recently signed the app and now I am getting a lot of first chance exceptions on startup. I have traced the problem to the following:
In any view, if I reference another namespace with in the application when the view is initialized I get the error:
"Could not load file or assembly 'MyApplication, Version=3.0.5917.24348, Culture=neutral, PublicKeyToken=xxxxxxxxxxxx' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"MyApplication, Version=3.0.5917.24348, Culture=neutral, PublicKeyToken=xxxxxxxxxxx"
Its always looking for a version that is 1 behind the version that I'm actually running.
If I remove the references to the other namespaces from the views, the InitializeComponent() does not throw the error
View:
<UserControl x:Class="MyApplication.View.DiagnosticsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:convert="clr-namespace:MyApplication.Converters" <!--Causes error-->
xmlns:behave="clr-namespace:MyApplication.Behaviors" <!--Causes error-->
xmlns:controls="clr-namespace:MyApplication.UserControls" <!--Causes error-->
If I remove these references, and move my converters and behaviors into another DLL and then reference them through the DLL there is no problem. The errors go away. Also If I don't sign the application I do not get the errors. I don't really want to have to reference these things in a different DLL, it seems like this should work fine. It also spends about 30 seconds throwing all of these errors as all of the views are created, so I am taking a hit on performance. I dont get why the application is trying to load itself, and why its trying to load an older version of itself. No matter how many times I build, the error is always 1 version behind.
Fusion Log:
*** Assembly Binder Log Entry (3/17/2016 # 10:30:11 AM) ***
The operation failed.
Bind result: hr = 0x80131040. No description available.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\tfs\Development\dev-feature\src\MyApplication\bin\Debug\MyApplication.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = MyApplication, Version=3.0.5920.15594, Culture=neutral, PublicKeyToken=xxxxxxxxxxxx
(Fully-specified)
LOG: Appbase = file:///C:/tfs/Development/dev-feature/src/MyApplication/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyApplication.exe
Calling assembly : PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\tfs\Development\dev-feature\src\MyApplication\bin\Debug\MyApplication.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: MyApplication, Version=3.0.5920.15594, Culture=neutral, PublicKeyToken=7b0591cb18d2a932
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/tfs/Development/dev-feature/src/MyApplication/bin/Debug/MyApplication.DLL.
LOG: Attempting download of new URL file:///C:/tfs/Development/dev-feature/src/MyApplication/bin/Debug/MyApplication/MyApplication.DLL.
LOG: Attempting download of new URL file:///C:/tfs/Development/dev-feature/src/MyApplication/bin/Debug/bin/MyApplication.DLL.
LOG: Attempting download of new URL file:///C:/tfs/Development/dev-feature/src/MyApplication/bin/Debug/bin/MyApplication/MyApplication.DLL.
LOG: Attempting download of new URL file:///C:/tfs/Development/dev-feature/src/MyApplication/bin/Debug/MyApplication.EXE.
LOG: Assembly download was successful. Attempting setup of file: C:\tfs\Development\dev-feature\src\MyApplication\bin\Debug\MyApplication.exe
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: MyApplication, Version=3.0.5920.15596, Culture=neutral, PublicKeyToken=7b0591cb18d2a932
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Edit:
Did you use ProcessMonitor to see where Visual Studio is loading v 3.0.5917.24348 from? Visual Studio wants v3.0.5920.15596 so you have to put that DLL where its expected.
Edit 2:
Can you put in a binding redirect in your config file like this?
<dependentAssembly>
<assemblyIdentity name="xxxxxx" publicKeyToken="121fae78165ba3d4"/>
<bindingRedirect oldVersion="3.0.5920.15596" newVersion="3.0.5917.24348"/>
</dependentAssembly>
Ref: .Net picking wrong referenced assembly version
Original:
One reason you might get the error:
Could not load file or assembly 'MyApplication, Version=3.0.5917.24348, Culture=neutral, PublicKeyToken=xxxxxxxxxxxx' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
Is when your assembly is signed and your reference to it has the Specific Version property set to True, resulting in FileLoadException.
Check you have Specific Version set to False:
Is it possible that you're trying to use strong-named URI references in your XAML? For example, by setting the AssemblyPublicKeyToken attribute your project file or by modifying the generated code-behind for the XAML?
If your XAML references are using a strong name and you use a constantly-changing version, then your XAML may end up using the previous version of the project, because the references are generated prior to the build being completed (and the new version being set).
To check, find your generated for your XAML under the obj directory and check for Uris (for example ~\obj\Debug\TestControl.g.i.cs):
System.Uri resourceLocater = new System.Uri("/T_Signing;V1.0.0.0;76005ee8ffcf5f2d;component/testcontrol.xaml", System.UriKind.Relative);
Above the URI has the full name and version. Whereas if you don't have strong named references, the uri would be more like:
System.Uri resourceLocater = new System.Uri("/T_Signing;component/testcontrol.xaml", System.UriKind.Relative);
I have a C# class which calls a .Net assembly built from a Matlab function. I am able to call this function from a simple C# console application with no problems.
However if I try to run a unit test from NUnit I get the following exception:
ClassLibrary1.Tests.UnitTests.TestPerformOptimization:
System.Reflection.TargetInvocationException : Exception has been
thrown by the target of an invocation. ----> System.Exception :
Error marshalling .NET object. 'Message: Unable to find assembly
'ClassLibrary1, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'. Source: mscorlib HelpLink: '
I get the same error if I try to call the class from either the standalone NUnit console, from ReSharper's test runner or if I try to call the function from say Excel (using Excel-DNA).
When calling my compiled Matlab component I actually wrap up a C# method (in an MWObjectArray object) and inject it in. I think the problem is happening when the compiled Matlab component tries invoking this injected method.
The only workaround I've found is to simply place a copy of my class (containing the method that is injected) in the same location as the NUnit test runner, the ReSharper test runner or Excel. However this is simply not a practical solution going forward as I need to install this application onto users machines. The other option which I can't use is copying the files to my %DEVPATH% for the same reason.
Is there a way I can tell the Matlab component where to find the assembly of my injected method/class?
SAMPLE PROJECT DOWNLOAD
There is a sample project available for download here. Just follow the instructions in the README.txt file located in the zip file.
Update 1
I manage to get my unit test to recognise my assembly by modifying my class to include the following in its constructor:
AppDomain.CurrentDomain.AssemblyResolve +=
(sender, args) => typeof(OptimizationFunction).Assembly;
However now I get the following exception:
Exception: System.Reflection.TargetInvocationException: Exception has
been thrown by the target of an invocation. ---> System.Exception:
Error marshalling .NET object. 'Message: Could not load file or
assembly 'dotnetcli, Version=1.0.5488.33915, Culture=neutral,
PublicKeyToken=da1231a838c93da4' or one of its dependencies. A
strongly-named assembly is required. (Exception from HRESULT:
0x80131044) Source: mscorlib HelpLink: ' at
dotnetcli.throwNetExceptionID(BaseMsgID* msgId) at
dotnetcli.DeployedDataConversion.GetMxArrayFromObject(Object data)
--- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[]
arguments, Signature sig, Boolean constructor)
So now it has a problem resolving the dotnetclli.dll (See Fusion log/exception below) which as far as I know should reside only in C:\Program Files (x86)\MATLAB\MATLAB Runtime\v85\bin\win32.
Here's an excerpt from the Fusion Log:
=== Pre-bind state information ===
LOG: DisplayName = ClassLibrary1 (Partial)
WRN: Assembly Name: ClassLibrary1 | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token. > WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/XXXXX/ConsoleApplication1/packages/NUnit.Runners.2.6.3/tools/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = nunit-agent-x86.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file:
C:\Insight\TFS\Asg\ConsoleApplication4\packages\NUnit.Runners.2.6.3\tools\nunit-agent-x86.exe.Config
LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\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:///C:/XXXXX/ConsoleApplication4/packages/NUnit.Runners.2.6.3/tools/ClassLibrary1.DLL.
LOG: Attempting download of new URL
file:///C:/XXXXX/ConsoleApplication1/packages/NUnit.Runners.2.6.3/tools/ClassLibrary1/ClassLibrary1.DLL.
LOG: Attempting download of new URL
file:///C:/XXXXX/ConsoleApplication1/packages/NUnit.Runners.2.6.3/tools/lib/ClassLibrary1.DLL.
LOG: Attempting download of new URL
file:///C:/XXXXX/ConsoleApplication1/packages/NUnit.Runners.2.6.3/tools/lib/ClassLibrary1/ClassLibrary1.DLL.
LOG: Attempting download of new URL
file:///C:/XXXXX/ConsoleApplication1/packages/NUnit.Runners.2.6.3/tools/addins/ClassLibrary1.DLL.
LOG: Attempting download of new URL
file:///C:/XXXXX/ConsoleApplication1/packages/NUnit.Runners.2.6.3/tools/addins/ClassLibrary1/ClassLibrary1.DLL.
LOG: Attempting download of new URL
file:///C:/XXXXX/ConsoleApplication1/packages/NUnit.Runners.2.6.3/tools/ClassLibrary1.EXE.
LOG: Attempting download of new URL
file:///C:/XXXXX/ConsoleApplication1/packages/NUnit.Runners.2.6.3/tools/ClassLibrary1/ClassLibrary1.EXE.
LOG: Attempting download of new URL
file:///C:/XXXXX/ConsoleApplication1/packages/NUnit.Runners.2.6.3/tools/lib/ClassLibrary1.EXE.
LOG: Attempting download of new URL
file:///C:/XXXXX/ConsoleApplication1/packages/NUnit.Runners.2.6.3/tools/lib/ClassLibrary1/ClassLibrary1.EXE.
LOG: Attempting download of new URL
file:///C:/XXXXX/ConsoleApplication1/packages/NUnit.Runners.2.6.3/tools/addins/ClassLibrary1.EXE.
LOG: Attempting download of new URL
file:///C:/XXXXX/ConsoleApplication1/packages/NUnit.Runners.2.6.3/tools/addins/ClassLibrary1/ClassLibrary1.EXE.
LOG: All probing URLs attempted and failed.
WRN: Partial binding information was supplied for an assembly: How come my console app can resolve this assembly by my NUnit test cannot?
Update 2
I got the following response from Matlab when I contacted them:
As far as I know this is the default .NET behavior when it comes to
deserializations. The application which deserializes the class looks
for the assembly in its own current folder and GAC where it cannot
find it. It is similar to (when you read this replace MATLAB with
Nunit)
http://www.mathworks.com/matlabcentral/answers/101695-why-can-my-assembly-not-be-found-when-deserializing-a-net-object-in-matlab-7-10-r2010a
You example does not represent the situation when MATLAB is involved.
MATLAB sends the class across APPDomains. Your example does not do
that.
Use Fuslogvw to have a look at the binding. You will see that it is
not MATLAB which cannot find the assembly it’s the calling application
which is unable to resolve the dependency (in your case
nunit-agent-x86.exe).
Make sure all needed files are produced by the compilation of ConsoleApplication4 and placed besides the executable (e.g. any needed assembly DLL, runtime DLL, .config file, etc.)
Once you are sure this happens, start NUnit with the --no-shadow-copy command line switch, or set it as a configuration parameter from your GUI tool. As Bush said, NUnit usually copies the files under test to a separate directory, and may leave behind important files.
If the class created by Matlab needs some sort of specific runtime, make sure it is correctly installed in the computers where you are running the tests / using Excel/ReSharper.
I would not try to fiddle, at this level, with the Assembly resolution process: please sum up the content at the article you linked, because it's paywalled, and try with NUnit's no-shadow-copy setting.
A propos first problem:
Run regedit
go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion
Add DWORD ForceLog = 1
Add DWORD LogFailures = 1
Add DWORD LogResourceBinds = 1
Add String LogPath = C:\log\ (last \ must be there)
Create a directory for logs (c:\logs for example)
It will log where your app looked for assemblies and how it failed. It probably means that working directory of nunit was different from working directory used by your console application.
A propos second error: strongly named assembly is required means that the library you have tried to use was not signed. If it's your assembly you simply have to use visual studio's sign the assembly from project properties. If it's not your assembly you can decompile it and compile it with strong name (with this method), but provider of third party dll should give you a strong-named assembly.
My guess this issue comes from an .NET CLR version incompatibility. Some client's (I mean client who calls your assembly) loads different versions of the CLE, then the resolved assembly may incompatible with that loaded CLR. This could cause not found error, because a compatible assembly really not found.
Try to check/play with both client's versions (the console app) and the server's version (your assembly) and diagnose what is changing.
Also check your assembly reference has "Copy to the output directory" is checked in all projects
You will want to study how the probing operation happens at .NET load time. Here's the rules for that: https://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.110).aspx
Outside of including the bin in the assembly you are publishing, it's the loader that decides if the support cast of DLLs are loadable. If it cannot find it using the rules above then you are simply out of luck.
We have seen issues similar to this in the past, some developer says to system admin, here's the Dlls you need to get the app running. System Admin follows instructions and boom, the application fails at load time.
Reason: Some child of a child in the assembly referred to a dll that's NOT on the system based on the probing rules.
Solution
1) Get the (child of the child) dll to include all dependencies in its assembly
2) Change the newer Main assembly to include all the dependencies (if the children assemblies cannot be changed).
3) Manually copy them in.
4) Create an installer that does it all.
Is the assembly in the Global Assembly Cache (GAC) or any place the might be overriding the assembly that you think is being loaded? This is usually the result of an incorrect assembly being loaded, for me it means I usually have something in the GAC overriding the version I have in bin/Debug.
My guess this issue comes from an .NET CLR version incompatibility. Some client's (I mean client who calls your assembly) loads different versions of the CLE, then the resolved assembly may incompatible with that loaded CLR. This could cause not found error, because a compatible assembly really not found.
Try to check/play with both client's versions (the console app) and the server's version (your assembly) and diagnose what is changing.
Also check your assembly reference has "Copy to the output directory" is checked in all projects
I am using the Magick.net library in an mvc3 web application and these are steps i did
My project is targeting AnyCPU and my machine is 64bit
Add reference of Magick.NET-x64.dll to the project.
Installed Visual C++ Redistributable for Visual Studio 2012 Update 4 from here http://www.microsoft.com/en-us/download/details.aspx?id=30679
Installed Ghostscript 9.14 for Windows (64 bit) on machine
Added
<add assembly="Magick.NET-x64, Version=7.0.0.0002, Culture=neutral, PublicKeyToken=2004825badfa91ec" />
on web.config file
Project is rebuilded successfully [and all dlls are in bin folder also], but while running i am getting the exceptions
Could not load file or assembly 'Magick.NET-x64' or one of its dependencies. An attempt was made to load a program with an incorrect format.
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.BadImageFormatException: Could not load file or assembly 'Magick.NET-x64' or one of its dependencies. An attempt was > made to load a program with an incorrect format.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the > exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Magick.NET-x64' could not be loaded.
=== Pre-bind state information ===
LOG: DisplayName = Magick.NET-x64
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Magick.NET-x64 | Domain ID: 6
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Fagbokforlaget/SourceCodes/fbf_internal/picsilo/Source/ImageTagger/
LOG: Initial PrivatePath = C:\Fagbokforlaget\SourceCodes\fbf_internal\picsilo\Source\ImageTagger\bin
Calling assembly : (Unknown).
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Fagbokforlaget\SourceCodes\fbf_internal\picsilo\Source\ImageTagger\web.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\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:///C:/Users/jibinmathew/AppData/Local/Temp/Temporary ASP.NET Files/root/a5b5e44f/dc1c4c69/Magick.NET-x64.DLL.
LOG: Attempting download of new URL file:///C:/Users/jibinmathew/AppData/Local/Temp/Temporary ASP.NET Files/root/a5b5e44f/dc1c4c69/Magick.NET-x64/Magick.NET-x64.DLL.
LOG: Attempting download of new URL file:///C:/Fagbokforlaget/SourceCodes/fbf_internal/picsilo/Source/ImageTagger/bin/Magick.NET-x64.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
A revision to the blog post sited by #dlemstra has the easiest solution I've found for this:
In VS2013/2015, go to Tools --> Options --> Projects and Solutions --> Web Projects and select "Use the 64 bit version of IIS Express for web sites and projects."
There seems to be a problem when running the 64 bit version of Magick.NET in Visual Studio 2013's IIS Express. You need to set a registry key according to the following answer 'High quality JPEG compression with c#'. You could set this flag or switch to the AnyCPU version of Magick.NET.
Make sure redistributable C++ package is also installed.
https://magick.codeplex.com/documentation
Make sure you have installed Visual C++ Redistributable for Visual
Studio
.NET 4.0: Visual C++ Redistributable for Visual Studio 2015 (x64 or x86)
.NET 2.0: Visual C++ Redistributable for Visual Studio 2008 (x64 or x86).