locked
Error Using Html.Hidden: "...add a reference to assembly 'System.Data.Linq'..." RRS feed

  • Question

  • User-1198726085 posted

    In my MVC app, when I put a hidden field on a view using the HtmlHelper, I get the exception below.  When do as the exception says and add a reference to System.Data.Linq, I still get the same error, that is unless I set Copy Local to true.  Of course I should not have to copy local a GAC'd assembly; however when I do that it works, well almost...

    When System.Data.Linq is copied local the view renders okay, but then whenever I try to edit that view, Visual Studio crashes.  When I remove System.Data.Linq.dll from the target build folder the crashing stops.

    Here's what else I have tried.  I ran all Windows updates.  I have also tried using System.Web.Mvc version 1 and version 2.  No help.  The only thing that works is to forego the helper and use straight HTML for hidden fields.

    One other detail that might be relevant.  This is a hybrid site.  That is, we are adding MVC to what is largely a WebForms site.  I don't see how that would make any difference, but it maybe somehow it does.

    Here is the exception:

    System.Web.HttpCompileException: c:\Projects\FAS\FasWeb\Mvc\Views\DamageWorkItemList\index.aspx(17): error CS0012: The type 'System.Data.Linq.Binary' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
    at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
    at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
    at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
    at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
    at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
    at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(String virtualPath, Type requiredBaseType)
    at System.Web.Mvc.BuildManagerWrapper.System.Web.Mvc.IBuildManager.CreateInstanceFromVirtualPath(String virtualPath, Type requiredBaseType)
    at System.Web.Mvc.WebFormViewEngine.FileExists(ControllerContext controllerContext, String virtualPath)
    at System.Web.Mvc.VirtualPathProviderViewEngine.GetPathFromGeneralName(ControllerContext controllerContext, String[] locations, String name, String controllerName, String cacheKey, String[]& searchedLocations)
    at System.Web.Mvc.VirtualPathProviderViewEngine.GetPath(ControllerContext controllerContext, String[] locations, String locationsPropertyName, String name, String controllerName, String cacheKeyPrefix, Boolean useCache, String[]& searchedLocations)
    at System.Web.Mvc.VirtualPathProviderViewEngine.FindView(ControllerContext controllerContext, String viewName, String masterName, Boolean useCache)
    at System.Web.Mvc.ViewEngineCollection.<>c__DisplayClass6.<FindView>b__4(IViewEngine e)
    at System.Web.Mvc.ViewEngineCollection.Find(Func`2 cacheLocator, Func`2 locator)
    at System.Web.Mvc.ViewEngineCollection.FindView(ControllerContext controllerContext, String viewName, String masterName)
    at System.Web.Mvc.ViewResult.FindView(ControllerContext context)
    at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
    at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<InvokeActionResultWithFilters>b__e()
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
    at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10()
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
    at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) 

    Thursday, October 22, 2009 12:30 AM

All replies

  • User1854625640 posted

    Hi,

    It seems that your issue is very strange.

    Can you reproduct it by creating a new project and adding a hidden field using Html helper.

    Friday, October 23, 2009 2:56 AM
  • User-1032240251 posted

    The message is correct.

    Html.Hidden() has special support for both byte[] and System.Data.Linq.Binary to ensure that the value get serialized as a Base-64 representation of the bytes.

    Sunday, October 25, 2009 9:23 PM
  • User-1198726085 posted

    I think the message is not correct, insofar as I get it when I have referenced System.Data.Binary.  No?

    CORRECTION: I meant to say, my project references System.Data.Linq.dll (which contains System.Data.Linq.Binary)

    Sunday, October 25, 2009 9:40 PM