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

Notification

Icon
Error

Tests interacting with Odata fail with System.TypeInitializationException
christothes
#1 Posted : Tuesday, June 19, 2018 1:49:05 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/2/2018(UTC)
Posts: 5
Location: United States of America

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
This problem recently started occurring on a particular project. The tests all run and pass using MSTest Explorer. The file mentioned as not found does in fact exist in the directory it's being searched in.

Only tests that interact with Odata seem to be affected.


System.AggregateException: One or more errors occurred. ---> System.TypeInitializationException: The type initializer for 'Microsoft.OData.Edm.Vocabularies.V1.CoreVocabularyModel' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Xml.ReaderWriter, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. ---> System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Xml.ReaderWriter.dll' or one of its dependencies. The system cannot find the file specified.
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.LoadFrom(String assemblyFile)
at nCrunch.Common.CustomAssemblyResolver.(IEnumerable`1 , ParsedAssemblyName )
at nCrunch.Common.CustomAssemblyResolver.ResolveAssembly(ParsedAssemblyName parsedAssemblyName)
at nCrunch.Common.CustomAssemblyResolver.(Object , ResolveEventArgs )
at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
--- End of inner exception stack trace ---
at Microsoft.OData.Edm.Vocabularies.V1.CoreVocabularyModel..cctor()
--- End of inner exception stack trace ---
at Microsoft.OData.Edm.EdmModelBase..ctor(IEnumerable`1 referencedModels, IEdmDirectValueAnnotationsManager annotationsManager)
at Microsoft.OData.Edm.EdmModel..ctor()
at System.Web.OData.Builder.EdmModelHelperMethods.BuildEdmModel(ODataModelBuilder builder)
at System.Web.OData.Builder.ODataConventionModelBuilder.GetEdmModel()
at Microsoft.Sirona.Api.ProfileService.Tests.Controllers.UsersControllerTests.GetUsers.<GetUsersReturnsResults>d__5.MoveNext() in C:\src\ProfileService\ProfileService.Tests\Controllers\UsersControllerTests.cs:line 215
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
---> (Inner Exception #0) System.TypeInitializationException: The type initializer for 'Microsoft.OData.Edm.Vocabularies.V1.CoreVocabularyModel' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Xml.ReaderWriter, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. ---> System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Facades\System.Xml.ReaderWriter.dll' or one of its dependencies. The system cannot find the file specified.
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.LoadFrom(String assemblyFile)
at nCrunch.Common.CustomAssemblyResolver.(IEnumerable`1 , ParsedAssemblyName )
at nCrunch.Common.CustomAssemblyResolver.ResolveAssembly(ParsedAssemblyName parsedAssemblyName)
at nCrunch.Common.CustomAssemblyResolver.(Object , ResolveEventArgs )
at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
--- End of inner exception stack trace ---
at Microsoft.OData.Edm.Vocabularies.V1.CoreVocabularyModel..cctor()
--- End of inner exception stack trace ---
at Microsoft.OData.Edm.EdmModelBase..ctor(IEnumerable`1 referencedModels, IEdmDirectValueAnnotationsManager annotationsManager)
at Microsoft.OData.Edm.EdmModel..ctor()
at System.Web.OData.Builder.EdmModelHelperMethods.BuildEdmModel(ODataModelBuilder builder)
at System.Web.OData.Builder.ODataConventionModelBuilder.GetEdmModel()
<....>

Remco
#2 Posted : Tuesday, June 19, 2018 11:16:59 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi, thanks for sharing this issue.

It looks like NCrunch is trying to resolve this file to a build-time facade rather than the run-time binary.

Can you share any more details about how this test project is structured? Which platform does it target? Is it using any .NET Standard dependencies?

Does turning on the Preload Assembly References setting for your test project resolve the issue?
christothes
#3 Posted : Wednesday, June 20, 2018 3:16:32 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/2/2018(UTC)
Posts: 5
Location: United States of America

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
Remco;12361 wrote:
Hi, thanks for sharing this issue.

It looks like NCrunch is trying to resolve this file to a build-time facade rather than the run-time binary.

Can you share any more details about how this test project is structured? Which platform does it target? Is it using any .NET Standard dependencies?

Does turning on the Preload Assembly References setting for your test project resolve the issue?



  • Standard Unit Test library that is testing an ASP.Net Web API 2 Odata controller
  • Target platform: .Net Framework 4.6.1
  • No .Net Standard assemblies
  • Turning on pre-load does not affect the issue.


I'm not aware of any changes with regard to structure of the code, test, or referecnces since this started failing.
MSTest has non problem at all and only tests that reference Odata are failing in this way.

ex of failing line:
Code:
var options =
    new ODataQueryOptions<MyModel>(
        new ODataQueryContext(
            modelBuilder.GetEdmModel(),
            typeof(MyModel),
            new System.Web.OData.Routing.ODataPath(segments)),
        request);
Remco
#4 Posted : Wednesday, June 20, 2018 9:34:59 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Thanks for these extra details.

I think the root issue here is that the NCrunch environment is resolving this dependency to a facade assembly, rather than a runtime one. This would be because the build system is using the facades at the time it builds your project. Although such behaviour is normal under .NET Core/.NET Standard and is catered for by NCrunch, I haven't seen it happen before for classic .NET Framework. This suggests that something has either changed in the platform or there is something interesting about your dependency structure that is causing it to surface.

Unfortunately, to troubleshoot this problem, I'll need to have a sample solution that can reproduce it. Is there any chance you could share one with me? You can submit code through the contact form on this site.
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.054 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download