.netservicestackormlite-servicestack

Servicestack - OrmLite not part of the ServiceStack namespace


I keep on getting the following compilation error message (" The type or namespace name 'OrmLite' does not exist in the namespace 'ServiceStack' (are you missing an assembly reference?)"). This is after successfully building & publishing a ServiceStack web app (running the latest ServiceStack version 5.0.2 and using the Servicestack VS Razor and Bootstrap template).

The compilation error message sometimes only appears after a while (e.g. 10 minutes) when browsing to the localhost where it is deployed.

To resolve, I have tried to

Server Error in '/' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0234: The type or namespace name 'OrmLite' does not exist in the namespace 'ServiceStack' (are you missing an assembly reference?)

    Source Error:


    Line 20:     using ServiceStack;
    Line 21:     using ServiceStack.Html;
    Line 22:     using ServiceStack.OrmLite;
    Line 23:     using ServiceStack.Razor;
    Line 24:     using ServiceStack.Text;

    Source File: d:\local\Temp\cuapf353.0.cs    Line: 22

Solution

  • This should be resolved in the latest v5.0.3 on MyGet (possibly also in v5.0.2 on NuGet). It was due to Razor pages referencing ServiceStack.Ormlite but not using it.

    A workaround is to remove ServiceStack.Ormlite from the Razor namespaces in your Web.config:

    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <pages pageBaseType="ServiceStack.Razor.ViewPage">
            <namespaces>
                <add namespace="System" />
                <add namespace="System.Linq" />
                <add namespace="ServiceStack" />
                <add namespace="ServiceStack.Html" />
                <add namespace="ServiceStack.Razor" />
                <add namespace="ServiceStack.Text" />
                <!-- add namespace="ServiceStack.OrmLite" / --> remove this
                <add namespace="ProjectNamespace" />
                <add namespace="ProjectNamespace.ServiceModel" />
            </namespaces>
        </pages>
    </system.web.webPages.razor>