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

Cannot find System.Coposition.TypedParts #9

Open
bezysoftware opened this issue Jul 10, 2015 · 11 comments
Open

Cannot find System.Coposition.TypedParts #9

bezysoftware opened this issue Jul 10, 2015 · 11 comments

Comments

@bezysoftware
Copy link

I just tried to use the T4 generator, but when I try to run the custom tool, I get following error:

Error   16  Running transformation: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AggregateException: One or more errors occurred. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Composition.TypedParts, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
   at Microsoft.CodeAnalysis.Host.Mef.MefHostServices.Create(IEnumerable`1 assemblies)
   at Microsoft.CodeAnalysis.Host.Mef.DesktopMefHostServices.get_DefaultServices()
   at Kent.Boogaart.PCLMock.CodeGeneration.Generator.<GenerateMocksAsync>d__0.MoveNext() in C:\Users\kent\Repository\PCLMock\Src\Kent.Boogaart.PCLMock.CodeGeneration\Generator.cs:line 24
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Kent.Boogaart.PCLMock.CodeGeneration.XmlBasedGenerator.<GenerateMocksAsync>d__2.MoveNext() in C:\Users\kent\Repository\PCLMock\Src\Kent.Boogaart.PCLMock.CodeGeneration\XmlBasedGenerator.cs:line 48
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at Kent.Boogaart.PCLMock.CodeGeneration.XmlBasedGenerator.GenerateMocks(String solutionPath, String xmlPath, Language language) in C:\Users\kent\Repository\PCLMock\Src\Kent.Boogaart.PCLMock.CodeGeneration\XmlBasedGenerator.cs:line 29
   at Kent.Boogaart.PCLMock.CodeGeneration.XmlBasedGenerator.GenerateMocks(String solutionPath, String xmlPath, String language) in C:\Users\kent\Repository\PCLMock\Src\Kent.Boogaart.PCLMock.CodeGeneration\XmlBasedGenerator.cs:line 21
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Microsoft.VisualStudio.TextTemplating59389E350AC879AC2313AB3BF88249987D0426CB576DCFE492173DC732D3844164099E1D5EA5CD146FE3DD173ED128E47A71AAFFE3474AF69A3196EB6CD0079A.GeneratedTextTransformation.TransformText() in c:\Src\Strat\ConsoleApplication5\UnitTestProject1\Mocks.tt:line 19   c:\Src\Strat\ConsoleApplication5\UnitTestProject1\Mocks.tt  19  1   UnitTestProject1

It's .net 4.5 project

@kentcb
Copy link
Owner

kentcb commented Jul 10, 2015

V3 was released in error - I'd have removed it if I could.

Basically, I thought my patches for Roslyn were applied, but they will not be available until Roslyn stable ships (which should be soonish). That said, it shouldn't lead to the error you're seeing. Anyway, once Roslyn v1 ships I'll release PCLMock v3.1 and will ping you here to retry with those binaries.

@bezysoftware
Copy link
Author

Alright, I'll wait for Roslyn, thanks for the info

@kentcb
Copy link
Owner

kentcb commented Jul 29, 2015

Hi,

v3.1 has been released and I've successfully integrated the code generation (T4 in my case, but I also tried via the console) in my own large project. Could you please try again and let me know how you get on?

Thanks

@bezysoftware
Copy link
Author

Hi, just tried v3.1 + T4 on a clean new project and still fails :(, VS2013 Premium, Windows 7, .NET 4.5 project.

I will try on Windows 10 & VS2015 when I get home.

@kentcb
Copy link
Owner

kentcb commented Jul 29, 2015

thanks @bezysoftware I'd appreciate you trying that. I assume it's the same error you're getting?

BTW, my setup is Win8.1 VS2015 RTM, .NET 4.5

@bezysoftware
Copy link
Author

I just tried multiple things (all on Windows 10 RTM)
VS 2015 Universal Project: didn't even create Mocks.tt and Mocks.xml, after I created them manually I get "Could not find packages directory relative to the template's directory". It seems the Universal Project uses completely different structure for packages, there is even no packages.config
VS 2015 .NET 4.6: WORKS

VS 2013 Windows 8.1 Project: Missing TypedParts (as in first post)
VS 2013 .NET 4.6: Missing TypedParts (as in first post)

@kentcb
Copy link
Owner

kentcb commented Jul 31, 2015

@bezysoftware thanks for that. Weird - I'll have a look when I get some time (which might not be for a while).

@bezysoftware
Copy link
Author

Seems there are some big changes with latest nuget for uwp... http://blog.nuget.org/20150729/Introducing-nuget-uwp.html

@kentcb
Copy link
Owner

kentcb commented Aug 2, 2015

Thanks for the link. NuGet 3 sounds like a WIP. Creating the content files manually (Mocks.tt Mocks.xml) is your only choice right now until they add support back in for content files. As for the other issue, I'll try to take a look at some point, but if it's a big issue I might have to postpone a resolution until NuGet 3 is bedded down more.

@elwray
Copy link

elwray commented Aug 26, 2015

Have the same error (Cannot find System.Coposition.TypedParts).
Windows 8 Pro / VisualStudio 2013 / Portable project with targeting Windows 8.1 and Windows Phone 8.1.
When I use PCLMockCodeGen tool all works fine.

@technicallyerik
Copy link

I'll try to submit a PR at some point, but using the T4 generator on UWP fails (even after manually copying over 'Mocks.tt' and 'Mocks.xml' because NuGet 3 packages are stored globally in your user profile, instead of "packages" project in your solution. This worked for me:

private void HookAssemblyResolution()
{
    // Get Packages Directory
    string packagesDirectory = Environment.ExpandEnvironmentVariables("%userprofile%\\.nuget\\packages");
    if (packagesDirectory == null)
    {
        throw new InvalidOperationException("Could not find packages directory in your user profile.");
    }
    this.Debug("packages directory: {0}", packagesDirectory);

    // Get T4 Code Generation Directory
    var packageDirectories = Directory.GetDirectories(packagesDirectory, "PCLMock.CodeGeneration.T4.*");
    if (packageDirectories.Length == 0)
    {
        throw new InvalidOperationException("Could not find PCLMock.CodeGeneration.T4 package in packages directory (" + packagesDirectory + ").");
    }
    var packageDirectory = packageDirectories.First();
    this.Debug("package directory: {0}", packageDirectory);

    // Get first version subfolder
    var packageVersionDirectories = Directory.GetDirectories(packageDirectory);
    if (packageDirectories.Length == 0)
    {
        throw new InvalidOperationException("Could not find any versions of PCLMock.CodeGeneration.T4 package in package directory (" + packageDirectory + ").");
    }
    var packageVersionDirectory = packageVersionDirectories.First();    // TODO:  Could do this smarter?

    // Get tools directory
    var assembliesDirectory = Path.Combine(packageVersionDirectory, "tools");
    this.Debug("assemblies directory: {0}", assembliesDirectory);
    if (!Directory.Exists(assembliesDirectory))
    {
        throw new InvalidOperationException("Package directory " + packageVersionDirectory + " was found but no 'tools' subdirectory was found within.");
    }

    AppDomain.CurrentDomain.AssemblyResolve += (s, e) =>
    {
        this.Debug("resolve: {0}", e.Name);

        var matches = Directory.GetFiles(assembliesDirectory, e.Name + ".dll", SearchOption.TopDirectoryOnly);

        if (matches.Length == 0)
        {
            this.Debug("Failed to find assembly in assemblies directory ({0}) named '{1}'.", assembliesDirectory, e.Name);
            return null;
        }
        else if (matches.Length > 1)
        {
            this.Debug("Found more than one potential match for '{0}' in assemblies directory ({0}). Bailing.", e.Name, assembliesDirectory);
            return null;
        }

        var match = matches.First();
        this.Debug("match: {0}", match);

        return Assembly.LoadFrom(match);
    };
}

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

4 participants