Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

dnu restore says JSON.NET could not be found #1934

Closed
borgdylan opened this issue May 22, 2015 · 8 comments
Closed

dnu restore says JSON.NET could not be found #1934

borgdylan opened this issue May 22, 2015 · 8 comments
Assignees
Milestone

Comments

@borgdylan
Copy link

When i restore packages i get this stack trace:

dylan@ubuntu-server:/var/www/Code/dylannet/vnext/dylan.NET.K$ dnu restore
Restoring packages for /var/www/Code/dylannet/vnext/dylan.NET.K/project.json
----------
System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies
File name: 'Newtonsoft.Json'
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0xb41f5cc0 + 0x00035> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0xb41f4d20 + 0x000b7> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0xb41f4c90 + 0x00084> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0xb41f4c40 + 0x0003f> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () <0xb44e96d0 + 0x0001f> 24246 in <filename unknown>:0 
  at Microsoft.Framework.PackageManager.RestoreCommand+<>c__DisplayClass72_0+<<ExecuteCommand>b__0>d.MoveNext () <0xb39075d0 + 0x00157> in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0xb41f5cc0 + 0x00035> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0xb41f4d20 + 0x000b7> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0xb41f4c90 + 0x00084> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0xb41f4c40 + 0x0003f> in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () <0xb41f4c10 + 0x0001f> in <filename unknown>:0 
  at Microsoft.Framework.PackageManager.RestoreCommand+<ExecuteCommand>d__72.MoveNext () <0xb391b958 + 0x00787> in <filename unknown>:0 
----------
Restore failed
Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies
@borgdylan
Copy link
Author

I do not use JSON.NET in this project at all.

@muratg
Copy link
Contributor

muratg commented May 22, 2015

What version of dnx are you using?

cc @troydai

@troydai
Copy link
Contributor

troydai commented May 22, 2015

Microsoft.Framework.PackageManager still needs Newtonsoft.Json

@troydai
Copy link
Contributor

troydai commented May 22, 2015

@BrennanConroy hit this issue today, too. It seems to be only repo on mono

@davidfowl
Copy link
Member

Hmm

@muratg
Copy link
Contributor

muratg commented May 23, 2015

@troydai Shouldn't it come transitively though?

@ChengTian
Copy link
Contributor

Just want to let people know that this is under investigation.

@BrennanConroy investigated this and found the commit e9b8144 is the root cause.

@davidfowl and @BrennanConroy will do some further investigation

@davidfowl
Copy link
Member

Ok I debugged it and figured it out. It's a behavior difference on mono with how assembly resolve works:

This is the minimal repro:

using System;
using System.Reflection;

public class Program
{
    public static void Main()
    {
        AppDomain.CurrentDomain.AssemblyResolve += (sender, e) =>
        {
            Console.WriteLine($"AssemblyResolve({e.Name})");

            Assembly.Load(new AssemblyName(e.Name));

            return null;
        };

        var an = new AssemblyName("Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed");
        var assembly = Assembly.Load(an);
        Console.WriteLine("Hello World");
    }
}

On windows .NET this stack overflows, on mono it just fails on the second call to load. It looks like the call is cached before a result is returned from the handler. This used to work because we only passed in the short name:

Assembly.Load(PackageManager)
-> AssemblyResolve (PackageManager)
-> ImplicitLoad(Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed)
-> AssemblyResolve(Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed)
-> loadContext.Load(Newtonsoft.Json)
-> Call loader chain, and it works!

Notice the rename from Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed to Newtonsoft.Json. I'll file a mono bug but also work around this in teh codez.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants