Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

BadImageFromatException when using ValueTuple
GibSral
#1 Posted : Friday, August 25, 2017 9:08:37 AM(UTC)
Rank: Member

Groups: Registered
Joined: 12/1/2014(UTC)
Posts: 27
Location: Germany

Thanks: 3 times
Was thanked: 3 time(s) in 3 post(s)
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.

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)


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:

Code:
        [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
Remco
#2 Posted : Friday, August 25, 2017 9:11:08 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
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.
fysiofriends
#3 Posted : Friday, August 25, 2017 11:32:09 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/25/2017(UTC)
Posts: 3
Location: Netherlands

Was thanked: 1 time(s) in 1 post(s)
FYI: Just ran into the same issue. Any updates are much appreciated
Remco
#4 Posted : Sunday, August 27, 2017 2:56:30 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
fysiofriends
#5 Posted : Monday, August 28, 2017 7:34:17 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/25/2017(UTC)
Posts: 3
Location: Netherlands

Was thanked: 1 time(s) in 1 post(s)
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.
1 user thanked fysiofriends for this useful post.
Remco on 8/28/2017(UTC)
thijstijsma
#6 Posted : Sunday, September 3, 2017 10:08:31 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/3/2017(UTC)
Posts: 6
Location: Netherlands

Was thanked: 2 time(s) in 2 post(s)
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.
Remco
#7 Posted : Sunday, September 3, 2017 11:33:16 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
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 :(
thijstijsma
#8 Posted : Sunday, September 3, 2017 12:42:07 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/3/2017(UTC)
Posts: 6
Location: Netherlands

Was thanked: 2 time(s) in 2 post(s)
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.
Remco
#9 Posted : Monday, September 4, 2017 7:17:19 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
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.
1 user thanked Remco for this useful post.
mc-clasoft on 11/12/2017(UTC)
thijstijsma
#10 Posted : Monday, September 4, 2017 7:40:34 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/3/2017(UTC)
Posts: 6
Location: Netherlands

Was thanked: 2 time(s) in 2 post(s)
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.
1 user thanked thijstijsma for this useful post.
Remco on 9/4/2017(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.072 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download