Compiling transformation: The type 'Object' is defined in an assembly that is not referenced
Asked Answered
A

5

14

I'm making some changes in an asp.Net MVC5 webapp, in which I used typelite to create .ts definitions from C# classes (really handy). For some reason now I've got this error when executing the T4:

Compiling transformation: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.

and this warning:

Compiling transformation: Assuming assembly reference 'mscorlib, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' used by 'EnvDTE' matches identity 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' of 'mscorlib', you may need to supply runtime policy Mair.Tracking.Web

I guess it's something related to the EnvDTE version used by TypeLite and the reference to mscorlib EnvDTE uses. Should I add a bindingRedirect in the web.config?

I'm using VS2015 with Update2 CTP.

Apsis answered 15/2, 2016 at 14:55 Comment(11)
I don't use typelite but I also get the mscorlib warning since I updated VS2015 to CTP 2.Cabral
I found your question and was reading thinking "perfect - exact same situation as me" right down to the version of VS2015, etc. Then sadness when I don't see an answer. I guess it's Update 2 CTP at fault. I'm going to install Update 2 RC in a few hours' time so will report back with an answer if that helpsLesbos
thank you Ian, didn't know Update2 RC is already outApsis
I'm having this same issue also with Update 2 RC :( Any suggestions?Evince
Updated to Update 2 RC, same errorApsis
That's a shame. I didn't get around to the RC release as things got in the way but I'll still try to install it later. I guess there's an assembly reference in the works somewhere and a binding redirect needs to be added/removed or updated.Lesbos
I've opened a Connect item for this: connect.microsoft.com/VisualStudio/feedback/details/2451005Lesbos
Same problem in Update 2 RTM. And, for the record, my .tt file doesn't access any external third party libraries, nor is it targeted at PCL, it's just a standard T4 template that doesn't do anything spectacular, just uses EnvDTE (which is the assembly my .tt file is complaining about).Cavort
I got this message as a warning, not an error in VS2015 in an WPF project with a Database first-model. The curious thing is that when it only appeared when i added a field in the DB, and then updated the "table" in the model designer. It did not crash, maybe this will help someone.Eula
@Eula I got it too on [all] my edmx. But just the warning, the T4 transform works properly.Apsis
I had to refresh my datasources and i had to update the model and it was fixed haven't got any problems with it, the added fields work like they are supposed to.Eula
C
11

I can confirm that Portable class libraries in combination with T4 templates cause this problem in Visual Studio 2015 Update 2. I wasn't able to find better solution then retargeting TypeLITE to full .NET framework.

From the version 1.8.0 TypeLITE nuget package contains a copy of the library that targets full .NET framework. If your project targets full .NET framework, the correct TypeLITE assembly is picked up during installation and everything works fine in Visual Studio 2015 Update 2. Unfortunately if your project targets PCL, you are out of luck with Visual Studio 2015 Update 2. I am looking for better solution.

Crenshaw answered 3/4, 2016 at 10:10 Comment(3)
@mythz should be notified about this for ServiceStack as wellMabe
Please try installing KB3151378 for VS 2015 Update 2.Colorable
I have encountered this problem with a .NET Core 3.1 app in VS 2019 Preview 2. Has anyone found an actual solution?Yachting
C
7

Thanks to Ian Yates for opening the Connect item.

Microsoft re-released KB3151378 on May 4, 2016. I can confirm that this update addresses the issue when T4 templates are used with EDMX files. Unfortunately I do not use TypeLite, so I am unable to confirm that it addresses the OP's issue, though I would suspect it does.

From the KB page:

Issue 6:

In T4 templates, errors occur when you reference an assembly that's built for a version of the .NET Framework that differs from the desktop (full) framework. For instance, errors occur when you reference portable libraries.

Colorable answered 11/5, 2016 at 23:3 Comment(0)
R
2

It looks like this should be fixed by KB3151378.

Notes for version 14.0.25130.0:

Issue 6

In T4 templates, errors occur when you reference an assembly that's built for a version of the .NET Framework that differs from the desktop (full) framework. For instance, errors occur when you reference portable libraries.

Rutharuthann answered 27/5, 2016 at 17:46 Comment(0)
L
1

Specifically for TypeLite, I opened my copy of it (fairly out of date but I've tweaked it to suit my needs) and stopped it being a portable library. That was done following the steps at https://mcmap.net/q/594424/-convert-a-pcl-to-a-regular-class-library. Now that it's not a portable library I'm able to execute my T4 template again.

I have many other T4 templates in my solution using ImmutableObjectGraph (search GitHub) and they ran fine despite it also using a portable library. I didn't dig too far into the specifics but I've learnt that mscorlib 2.0.5.0 is associated with portable libraries, etc and really we don't need TypeLite itself to be portable.

Hope this helps others.

There's also an open Connect issue at https://blogs.msdn.microsoft.com/visualstudio/2016/03/03/visual-studio-2015-update-2-rc/ since this is still a regression in VS2015 Update 2.

Lesbos answered 9/3, 2016 at 3:43 Comment(2)
Thanks! This worked for me (the warning is still present but the error is gone and it runs successfully). For other people coming this way, you can download the latest version of TypeLite from here: bitbucket.org/LukasKabrt/typelite/downloads. There was only one project I needed to convert and it was called "TypeLite.Net4". The other one "TypeLite" was already a class library. The final step was uninstalling the TypeLite nuget package from your project and adding a reference to those newly compiled dlls.Shandeigh
Glad it helped someone else out :)Lesbos
S
0

I had the full version of the TypeLite 1.5.1 installed (Regular WebApplication .Net Full version 4.5.1) and simple updating to 1.8.1 helped to resolve the issue. So I should say that VS 2015 Update2 RC and Update2 RTM doesn't work neither with the FULL version of the TypeLite nor with the PORTABLE (yes, version 1.5.1 already has the portable version)

Sex answered 12/4, 2016 at 9:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.