Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

Unable to cast object of type 'System.Compiler.TypeParameter' to type 'System.Compiler.Class'. #20

@DzonnyDZ

Description

@DzonnyDZ

When I have somewhat crazy class in my project like this:

public abstract class EntityDataAccessLayerPart<TDal, TDataContext, TItemBase, TSoftDelete> : EntityDataAccessLayerPart
    where TItemBase : class
    where TSoftDelete : class, TItemBase
    where TDal : EntityDataAccessLayer<TDataContext, TItemBase, TSoftDelete>
    where TDataContext : EntityContextBase

When I have code contracts enabled in my project I get following error when compiling

1>------ Build started: Project: RFERL.EntityFramework, Configuration: Debug-Fast Any CPU ------
1>  elapsed time: 1672ms
1>C:\Program Files (x86)\Microsoft\Contracts\MsBuild\v12.0\Microsoft.CodeContracts.targets(397,5): warning : Contract reference assembly for project 'RFERL.CoreUtilities' not found. Select 'Build' or 'DoNotBuild' for Contract Reference in project settings.
1>  Reading assembly 'RFERL.EntityFramework' from 'C:\Code\common\RFERL.EntityFramework\obj\Debug-Fast\RFERL.EntityFramework.dll' resulted in errors.
1>      Unable to cast object of type 'System.Compiler.TypeParameter' to type 'System.Compiler.Class'.
1>ccrewrite : error : Rewrite aborted due to metadata errors. Check output window
1>  elapsed time: 789,191ms
1>C:\Program Files (x86)\Microsoft\Contracts\MsBuild\v12.0\Microsoft.CodeContracts.targets(254,5): error MSB3073: The command ""C:\Program Files (x86)\Microsoft\Contracts\Bin\ccrewrite.exe" "@RFERL.EntityFrameworkccrewrite.rsp"" exited with code -1.
========== Build: 0 succeeded, 1 failed, 7 up-to-date, 0 skipped ==========

When I comment out part of the code like this

public abstract class EntityDataAccessLayerPart<TDal, TDataContext, TItemBase, TSoftDelete> : EntityDataAccessLayerPart
    where TItemBase : class
    where TSoftDelete : class, TItemBase
    where TDal : EntityDataAccessLayer//<TDataContext, TItemBase, TSoftDelete>
    where TDataContext : EntityContextBase

everything works

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions