Build/Test Issues

BadImageFromatException when using ValueTuple

Started by GibSral on 8,333 views

Hi,

I just created a simple MsBuildTask with the appropriate NUnit (3.7) test project. (both .net 4.6.1)
When using the new Tuple I get a BadImageFormatException when ncrunch (Version 3.11.0.5) executes the test.
This also happens in Version 3.10.0.20.

[h]An error occurred while analysing this project after it was built: System.BadImageFormatException: Die Datei oder Assembly "System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" oder eine Abhängigkeit davon wurde nicht gefunden. Verweisassemblys sollten nicht für die Ausführung geladen werden. Sie können nur in einem Ladekontext nur für die Reflektion geladen werden. (Ausnahme von HRESULT: 0x80131058)
Dateiname: "System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" ---> System.BadImageFormatException: Die Datei oder Assembly "file:///C:\Users\lab\.nuget\packages\System.ValueTuple\4.4.0\ref\net461\System.ValueTuple.dll" oder eine Abhängigkeit davon wurde nicht gefunden. Verweisassemblys sollten nicht für die Ausführung geladen werden. Sie können nur in einem Ladekontext nur für die Reflektion geladen werden. (Ausnahme von HRESULT: 0x80131058)
Dateiname: "file:///C:\Users\lab\.nuget\packages\System.ValueTuple\4.4.0\ref\net461\System.ValueTuple.dll" ---> System.BadImageFormatException: Es kann keine Verweisassembly für die Ausführung geladen werden.
bei System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
bei System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
bei System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
bei System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
bei System.Reflection.Assembly.LoadFrom(String assemblyFile)
bei nCrunch.Common.CustomAssemblyResolver.ResolveAssembly(ParsedAssemblyName parsedAssemblyName)
bei nCrunch.Common.CustomAssemblyResolver.(Object , ResolveEventArgs )
bei System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)[/h]

You can reproduce this by simply creating a .net 4.6.1 project that referenecs NUnit and ValueTuple by using the latter in code
For exapmle:

        [Test]
        public void SomeTest()
        {
            DoSomething(("1", "2"));
        }

        public void DoSomething((string value1, string value2) values)
        {
            
        }


Any suggestions?
The ReSharper testrunner executes the tests without error.


Thanks in advance

Lars

Edited

Hi Lars,

I've just today been implementing a fix for this issue. I'll let you know as soon as I have a build available.
FYI: Just ran into the same issue. Any updates are much appreciated
I've prepared a new build including what I hope is a fix for this issue. Would you be interested in giving it a try?

http://downloads.ncrunch.net/NCrunch_Console_3.11.0.6.msi
http://downloads.ncrunch.net/NCrunch_Console_3.11.0.6.zip
http://downloads.ncrunch.net/NCrunch_GridNodeServer_3.11.0.6.msi
http://downloads.ncrunch.net/NCrunch_GridNodeServer_3.11.0.6.zip
http://downloads.ncrunch.net/NCrunch_LicenseServer_3.11.0.6.zip
http://downloads.ncrunch.net/NCrunch_VS2008_3.11.0.6.msi
http://downloads.ncrunch.net/NCrunch_VS2010_3.11.0.6.msi
http://downloads.ncrunch.net/NCrunch_VS2010_3.11.0.6.zip
http://downloads.ncrunch.net/NCrunch_VS2012_3.11.0.6.msi
http://downloads.ncrunch.net/NCrunch_VS2012_3.11.0.6.zip
http://downloads.ncrunch.net/NCrunch_VS2013_3.11.0.6.msi
http://downloads.ncrunch.net/NCrunch_VS2013_3.11.0.6.zip
http://downloads.ncrunch.net/NCrunch_VS2015_3.11.0.6.msi
http://downloads.ncrunch.net/NCrunch_VS2015_3.11.0.6.zip
http://downloads.ncrunch.net/NCrunch_VS2017_3.11.0.6.msi
http://downloads.ncrunch.net/NCrunch_VS2017_3.11.0.6.zip
Yes, this build solves my problem. I did have some problems unignoring the tests that I previously ignored though. I have to unignore all leafs in the tree that was displaying the ignored tests. But, after that, the tests ran and completed successfully.
I encountered the same problem on Visual Studio 15.3.3 (Enterprise) and installed the build you provided, however it does not solve my issues.

I get the same stacktrace:

System.BadImageFormatException: Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net47\ref\System.ValueTuple.dll' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)
at Microsoft.CodeAnalysis.GreenNode.WriteTo(TextWriter writer, Boolean leading, Boolean trailing)
at Microsoft.CodeAnalysis.GreenNode.ToFullString()
at Microsoft.CodeAnalysis.SyntaxNode.ToFullString()
at <snip>my code</snip>
System.BadImageFormatException: Cannot load a reference assembly for execution.

I'm available for any testing you require.
Would you be able to try the build below to see if this is any better for you?

http://downloads.ncrunch.net/NCrunch_Console_3.11.0.8.msi
http://downloads.ncrunch.net/NCrunch_Console_3.11.0.8.zip
http://downloads.ncrunch.net/NCrunch_GridNodeServer_3.11.0.8.msi
http://downloads.ncrunch.net/NCrunch_GridNodeServer_3.11.0.8.zip
http://downloads.ncrunch.net/NCrunch_VS2017_3.11.0.8.msi
http://downloads.ncrunch.net/NCrunch_VS2017_3.11.0.8.zip

If not, I may need to get a sample solution from you, or steps to reproduce the problem from a project template. Sorry, it doesn't help when MS introduce massive changes to the assembly referencing system between the last preview build and the RTM :(
Unfortunately, this doesn't fix it.
I've sent you a sample solution through the contact form.

If you need to discuss the contents with me, please only do so in direct mail contact as opposed to the forum.
These fixes have now been released with v3.11.

thijstijsma and I had an offline discussion about this problem. In their case, the problem disappeared after cleaning up the obj/bin directories and the NCrunch cache file. I suspect that it may have been caused by old/invalid state in the project.assets.json file.
The problem did not disappear after deleting the NCrunch cache folder. I tried that first.
Afterwards I deleted both the bin/obj folders and the NCrunch .project/.solution files.

Unfortunately I didn't do that in two steps, so I don't know which one was problematic.

Post a reply

Log in to reply.