Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Threading.Tasks.Dataflow FileLoadException #855

Closed
basprins opened this issue Jul 2, 2019 · 3 comments
Closed

System.Threading.Tasks.Dataflow FileLoadException #855

basprins opened this issue Jul 2, 2019 · 3 comments

Comments

@basprins
Copy link

basprins commented Jul 2, 2019

Hi,

I am stuck with an issue in our build which I can't seem to resolve, and I am not sure which library is causing the issue; Moq or Workstation.UaClient.

A little backgroud:
We use two libraries (among many many others) in our solution:

  • Workstation.UaClient (opcua stack), which depends on >= System.Threading.Tasks.Dataflow 4.8.0
  • System.Threading.Tasks.Dataflow 4.9.0

In essence that shouldn't be a problem, the dependency on System.Threading.Tasks.Dataflow >= 4.8.0 is satisfied. The project that uses Workstation.UaClient explicitly references System.Threading.Tasks.Dataflow 4.9.0, so nuget is not confused which version to use. It nicely downloads the 4.9.0 dependency, and everything compiles just fine.

The problem arises, when I create a new Mock and retrieve its object as follows:


    public interface IWhatever
    {
        void Initialize(UaTcpSessionChannel channel);
    }

    [TestFixture]
    public class DataflowDependencyTest
    {
        [Test]
        public void FileLoadException()
        {
            var mock = new Mock<IWhatever>();
            var _ = mock.Object;
        }
    }

I get a FileLoadException on the statement 'mock.Object'. The interface (IWhatever) which is mocked, defines a type which depends on System.Threading.Tasks.Dataflow.

The stacktrace looks as follows:

System.IO.FileLoadException : Could not load file or assembly 'System.Threading.Tasks.Dataflow, Version=4.6.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
at System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
at System.Reflection.RuntimeMethodInfo.GetParameters()
at Castle.DynamicProxy.Generators.MethodSignatureComparer.GetHashCode(MethodInfo obj)
at System.Linq.Set1.InternalGetHashCode(TElement value) at System.Linq.Set1.Find(TElement value, Boolean add)
at System.Linq.Enumerable.d__641.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)
at Castle.DynamicProxy.Generators.MethodFinder.GetAllInstanceMethods(Type type, BindingFlags flags)
at Castle.DynamicProxy.Contributors.MembersCollector.CollectMethods(IProxyGenerationHook hook)
at Castle.DynamicProxy.Contributors.MembersCollector.CollectMembersToProxy(IProxyGenerationHook hook)
at Castle.DynamicProxy.Contributors.InterfaceProxyWithoutTargetContributor.d__3.MoveNext()
at Castle.DynamicProxy.Contributors.CompositeTypeContributor.CollectElementsToProxy(IProxyGenerationHook hook, MetaType model)
at Castle.DynamicProxy.Generators.InterfaceProxyWithoutTargetGenerator.GenerateType(String typeName, Type proxyTargetType, Type[] interfaces, INamingScope namingScope)
at Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.<>c__DisplayClass6_0.b__0(String n, INamingScope s)
at Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func3 factory) at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, IInterceptor[] interceptors) at Moq.Mock1.InitializeInstancePexProtected() in C:\projects\moq4\src\Moq\Mock.Generic.cs:line 264
at Moq.Mock1.OnGetObject() in C:\projects\moq4\src\Moq\Mock.Generic.cs:line 277 at Moq.Mock1.get_Object() in C:\projects\moq4\src\Moq\Mock.Generic.cs:line 208
at ClassLibrary2.Class1.Reproduce() in D:\Development\uaclientdataflow\ClassLibrary2\ClassLibrary2\Class1.cs:line 16

So, the Moq library throws the exception. Is it fair to say that Moq also causes this problem? And if so, can it be fixed?

I uploaded this very trivial project to github:
https://github.com/basprins/uaclientdataflow

I hope somebody can have a look at this !

Many thanks in advance,
if I need to provide anything else, I am more than willing to share!

@basprins
Copy link
Author

basprins commented Jul 2, 2019

Ps: maybe not entirely clear from my initial issue description, but we have a hard dependency on Dataflow 4.9.0. I know this issue is resolved by using Dataflow 4.8.0, but that's not an option for us.

@stakx
Copy link
Contributor

stakx commented Jul 2, 2019

Can you please post a minimal, complete and verifiable code example that reproduces this problem? Without that, we can only guess.

P.S.: If the problem isn't assembly binding policy / version conflict, I'd say this looks more like a problem with DynamicProxy. The stack trace is interesting, it appears as if the FileLoadException were actually caused by a method signature that isn't understood (either by DynamicProxy, or by reflection). Let's take a look at your repro first, though, before we open an issue over at the DP repo.

@stakx
Copy link
Contributor

stakx commented Jul 4, 2019

I uploaded this very trivial project to github:
https://github.com/basprins/uaclientdataflow

Apologies, I overlooked the link to your repository. I've posted an "answer" there in the form of a PR there. I cannot reproduce the problem you mentioned, and I am fairly confident this is (as almost always in such cases) due to .NET / NuGet tooling. I'll close this issue here, in favor of the PR at your repo.

@stakx stakx closed this as completed Jul 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants