0

I have created a class

public static class UnitOfWorkFactory
{
    public static T Resolve<T>()
    {
        return Application.UnityContainer.Resolve<T>();
    }
}

Everything compiles fine unless I put this class in separate code file: The name 'UnitOfWorkFactory' does not exist in the current context. The problem persists even with no reference to assemblies:

public static class UnitOfWorkFactory
{
    public static T Resolve<T>()
    {
        return default(T);
    }
}

[Probably this is unrelated to the main question] Even more, if I try to run successfully compiled application it produces error: Parser Error Message: Could not load type 'MyWCFProject.Application'.

Line 1: <%@ Application Codebehind="Global.asax.cs" Inherits="MyWCFProject.Application" Language="C#" %>

Please suggest what is going on here..

EDIT: I moved file from App_Code with its properties, that caused first error.

amuliar
  • 1,318
  • 15
  • 26
  • 1
    If you put it into a file under AppCode folder, in asp.net project, then it cannot be referenced from the "regular" code, because such files are compiled later by asp.net itself. You can read more in this answer: http://stackoverflow.com/a/42562315/5311735 – Evk Apr 13 '17 at 11:16
  • I can put any number of files with class UnitOfWorkFactory under project root and it will compile. – amuliar Apr 13 '17 at 11:21
  • I see. App_Code has Build Action: Content. I copied file from app_code with properties. – amuliar Apr 13 '17 at 11:24

0 Answers0