The type 'System.Object' is defined in an assembly that is not referenced - Windows Store Application
Asked Answered
C

2

10

I have a Windows Store Application that use a portable class library with a T4 template. When I run the transformation it fails with the following error:

Compiling transformation: The type 'System.Object' is defined in an assembly 
that is not referenced. You must add a reference to assembly 'System.Runtime,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

I tried to add reference to the System.Runtime library manually, but I got message "The component is already automatically referenced by the build system"

The same library works in a Silverlight project as well as in a Windows Phone project.

Does anybody have an idea where is the problem?

I am new in developing Windows Store applications, so it might be some trivial error, but I am unable to find any solution.

Cesya answered 28/6, 2013 at 17:54 Comment(1)
Unfortunately I cannot reproduce your error. Maybe you could share at least the header part of your T4 template? Have you tried adding a reference to the System.Runtime assembly inside the template (via <#@ assembly #> directive), because the references used by a template are independent of references used by its containing project.Haynor
L
4

Summary:

To solve this exact issue, simply add the following to the top of the T4 template:

<#@ assembly name="System.Runtime" #>

Long answer:

T4 templates are a compile-time concept, and therefore runs in the context & framework of the build stack (ie .NET Framework 4.5), not in the context of the host project, so modifying the Store project to add the reference to System.Runtime is not going to help.

Instead, what you should be doing is telling T4 about the reference via the template itself. This is normally handled automatically for tools that use MSBuild, however, T4 basically calls the compilers directly and therefore needs to manually be told about each portable reference assembly.

As you start to write real code in the portable library, you will quickly find that you need to add a lot more references; basically, every assembly under %PROGRAMFILES(x86)%\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\Facades. If you do this in a lot of templates, I'd recommend creating a single include template that contains an assembly directive for every file in the above folder.

Lieb answered 30/7, 2013 at 20:50 Comment(0)
I
1

In my case (Xamarin Studio), the solution was to do a clean build.

Imbibition answered 11/3, 2014 at 3:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.