Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 588
Lukas Kabrt Avatar asked Jun 28 '13 17:06

Lukas Kabrt


People also ask

How do I fix CS0012?

You could resolve this CS0012 by compiling with /reference:cs0012b. dll;cs0012a. dll , or in Visual Studio by using the Add Reference Dialog Box to add a reference to cs0012a. dll in addition to cs0012b.

Which feature is used to store the assemblies that are shared across all of the applications?

In order to share an assembly with other applications, it must be placed in the global assembly cache (GAC).

Is defined in an assembly that is not referenced you must add a reference?

The type 'SpatialReference' is defined in an assembly that is not referenced. You must add a reference to assembly 'Esri. ArcGISRuntime, Version=10.2. 7.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86'.

What is reference assemblies folder in Program Files?

Reference assemblies are usually distributed with the Software Development Kit (SDK) of a particular platform or library. Using a reference assembly enables developers to build programs that target a specific library version without having the full implementation assembly for that version.


2 Answers

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.

like image 159
David Kean Avatar answered Oct 05 '22 08:10

David Kean


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

like image 23
William Jockusch Avatar answered Oct 05 '22 07:10

William Jockusch