1

Closed

FileLoadException - Could not load file or assembly 'OpenRiaServices.DomainServices.Client.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies

description

The commit: ddcb0ea2 made by danneesset daniel.svensson@hotmail.seat 8/12/2016 12:54:52 PM introduced FileLoadException in Silverlight version of OpenRiaServices.DomainServices.Client. The root cause is the change of AssemblyVersion to 4.0.0.0 (from 2.0.5.0). In the effect most probably the following code fails:

OpenRiaServices.DomainServices.Client.Data.DefaultDomainClientFactory:
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultDomainClientFactory"/> class.
        /// </summary>
        public DefaultDomainClientFactory()
        {
            // Look for the WebDomainClient in an assembly with the same version and with same signing key as this assembly
            var webDomainClientName = "OpenRiaServices.DomainServices.Client.WebDomainClient`1, "
                                    + TypeUtility.GetAssembly(typeof(DomainClient)).FullName.Replace("OpenRiaServices.DomainServices.Client", "OpenRiaServices.DomainServices.Client.Web");
            _webDomainClientType = Type.GetType(webDomainClientName); // Exception here
        }
The full stack trace is in here:

Unhandled exception at line 58, column 13 in http://localhost:20172/ 0x800a139e - JavaScript runtime error: Unhandled Error in Silverlight Application Code: 4004 Category: ManagedRuntimeError Message: Microsoft.Practices.ServiceLocation.ActivationException: Activation error occurred while trying to get instance of type ILoggingManager, key "" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "VTS.Core.Logging.ILoggingManager", name = "(none)".

Exception occurred while: Calling constructor VTS.Core.Web.Services.LoggingContext().

Exception is: FileLoadException - Could not load file or assembly 'OpenRiaServices.DomainServices.Client.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The requested assembly version conflicts with what is already bound in the app domain or specified in the manifest. (Exception from HRESULT: 0x80131053)

At the time of the exception, the container was:



Resolving VTS.Core.Logging.LoggingManager,(none) (mapped from VTS.Core.Logging.ILoggingManager, (none))

Resolving parameter "loggingContext" of constructor VTS.Core.Logging.LoggingManager(VTS.Core.Services.ILoggingContext loggingContext, VTS.Core.Mvvm.IDialogService dialogService)
Resolving VTS.Core.Web.Services.LoggingContext,(none) (mapped from VTS.Core.Services.ILoggingContext, (none))

Calling constructor VTS.Core.Web.Services.LoggingContext()
---> System.IO.FileLoadException: Could not load file or assembly 'OpenRiaServices.DomainServices.Client.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The requested assembly version conflicts with what is already bound in the app domain or specified in the manifest. (Exception from HRESULT: 0x80131053)

at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)

at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName)

at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)

at System.Type.GetType(String typeName)

at OpenRiaServices.DomainServices.Client.DomainContext.CreateDomainClientFactory()

at OpenRiaServices.DomainServices.Client.DomainContext.get_DomainClientFactory()

at OpenRiaServices.DomainServices.Client.DomainContext.CreateDomainClient(Type serviceContract, Uri serviceUri, Boolean usesHttps)

at VTS.Core.Web.Services.LoggingContext..ctor(Uri serviceUri)

at VTS.Core.Web.Services.LoggingContext..ctor()

at BuildUp_VTS.Core.Web.Services.LoggingContext(IBuilderContext )

at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)

at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)

at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)

at Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey)

at Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context)

at BuildUp_VTS.Core.Logging.LoggingManager(IBuilderContext )

at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)

at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)

at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)

at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable1 resolverOverrides)

--- End of inner exception stack trace ---

at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable
1 resolverOverrides)

at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides)

at Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key)

at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)

--- End of inner exception stack trace ---

at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)

at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstanceTService

at VTS.AM.App.Application_UnhandledException(Object sender, ApplicationUnhandledExceptionEventArgs e)

at MS.Internal.Error.CallApplicationUEHandler(Exception e)

at MS.Internal.Error.GetXresultForUserException(Exception ex)
Closed Jun 14 at 12:53 PM by danneesset

comments

leszekrogowski wrote Feb 3 at 2:58 PM

If anyone needs workaround, you can implement on your own custom DomainClientFactory and set it in DomainContext.
using System;
using OpenRiaServices.DomainServices.Client;

namespace VTS.Core.Services
{
    /// <summary>
    /// This is temporary solution to avoid:
    /// FileLoadException - Could not load file or assembly 'OpenRiaServices.DomainServices.Client.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies
    /// </summary>
    /// <remarks>
    /// Issue is described here: https://openriaservices.codeplex.com/workitem/98
    /// </remarks>
    public sealed class CustomDomainClientFactory : DomainClientFactory
    {
        private readonly Type _webDomainClientType = typeof(WebDomainClient<>);

        /// <summary>
        /// Creates a WebDomainClient{serviceContract} using reflection.
        /// </summary>
        protected override DomainClient CreateDomainClientCore(Type serviceContract, Uri serviceUri, bool requiresSecureEndpoint)
        {
            // Try to create a WebDomainClient using reflection
            if (_webDomainClientType != null)
            {
                var domainClientType = _webDomainClientType.MakeGenericType(serviceContract);
                if (domainClientType == null)
                {
                    throw new InvalidOperationException("Faild to construct generic WebDomainClient");
                }

                return (DomainClient)Activator.CreateInstance(domainClientType, serviceUri, requiresSecureEndpoint);
            }

            throw new InvalidOperationException("You must reference the assembly 'OpenRiaServices.DomainServices.Client.Web'");
        }
    }
}
App.xaml.cs
        public App()
        {
            // TEMP: This is bug fix for issue reported by me: https://openriaservices.codeplex.com/workitem/98
            OpenRiaServices.DomainServices.Client.DomainContext.DomainClientFactory = new Core.Services.CustomDomainClientFactory();
            // TEMP: END

danneesset wrote Feb 3 at 7:10 PM

Thank you for reporting the Issue, I will update the version of the Silverlight web assembly in order to fix the issue.

You can find the latest non-released code from https://ci.appveyor.com/project/Daniel-Svensson/openriaserviecs/branch/master/job/ojqnyexfc1ot4lxf if you want to test it. It should be possible to just replace the web assembly with the latest build until the next release on nuget

danneesset wrote Feb 3 at 7:19 PM

Fixed in changeset b6f16b484965962708a7c891626e2ed7c332180a

danneesset wrote Feb 8 at 7:53 PM

Workaround

You should be able to use the WebDomainClientFactory in the Client.Web.dll for a somewhat simpler workaround in the mean time:
   public App()
        {
            OpenRiaServices.DomainServices.Client.DomainContext.DomainClientFactory = new    OpenRiaServices.DomainServices.Client.Web.WebDomainClientFactory();