0

I'm currently rewriting a legacy SharePoint application and I need to figure out how to deploy it.
The application itself is SharePoint solution with several features, including webparts and simple web pages with some code.

There is a webpage that is designed to be deployed in layouts subfolder.
In production environment, there is no codebehind in layouts subdirectory, just the .aspx file.

I understand that corresponding codebehind assembly is loaded from GAC. Indeed, it is there.
However the page code doesn't contain <%@ Assembly %> directive that would ask it look in GAC, nor does it specify fully-qualified name:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="BadWolf._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <!-- -->
</html>

So how does this page locate its code assembly in the production environment? I need to deploy the same code to a different server but if I don't specify <%@ Assembly %> SharePoint gives me Unknown Error, which is represented in logs as follows:

Exception Type: System.Web.HttpException
Exception Message: Could not load type 'BadWolf._Default'.   

What did I miss? Is there any special config, any special setting, whatever?

2 Answers 2

0

You need to use Inherits= with the fully qualified assembly name...

Inherits="MyAssembly.MyNamespace.MyClass, MyAssembly, version=1.0.0.0, culture=neutral, publickeytoken=123456789"
5
  • It works this way. But what I can't figure out is how does this work in production without assembly directive or attribute? Commented Feb 17, 2011 at 18:16
  • The Assembly attribute is only used in TagPrefix directives (I thought)
    – James Love
    Commented Feb 17, 2011 at 18:18
  • Which pages are you seeing this in? Application Pages or Layout Pages?
    – James Love
    Commented Feb 17, 2011 at 18:32
  • Just found an answer, stackoverflow.com/questions/5032724/… . Thanks for helping. Commented Feb 17, 2011 at 18:34
  • Oh, there's another interesting detail there, you might want to take a look (see my answer). Commented Feb 17, 2011 at 18:59
0

Turned out the assembly was in SharePoint bin folder, that's why it was loaded without specifying the fully qualified name. However removing it from GAC yielded another issue:

Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed

This is funny because removing the assembly from either GAC or bin folder makes it unusable (or else requiring additional configuration which I seek not), and I'm not sure which one is actually being loaded.

I think I'll stick with keeping assembly in GAC (to have full trust) and specifying fully qualified name.

4
  • If it's in the bin, you probably need a CodeAccessSecurity policy for the assembly in place in your web.config for that web application (a right PITA, tbh).
    – James Love
    Commented Feb 17, 2011 at 19:14
  • Yep, that's exactly what drives my decision to put it into GAC. It's legacy code and I don't want to spend time evaluating what it may or may not do. Commented Feb 17, 2011 at 21:03
  • Actually, I have the same issue (MOSS 2007, custom ASP.NET application under SP LAYOUTS): stackoverflow.com/questions/19421286/… I have no problem installing the assembly in the GAC but it is very disconcerting to have to leave it in the BIN folder as well. So, should I add the Inherits= or @Assembly directive? I really wish to take it out of the BIN folder. Please advice. Thanks!
    – Web User
    Commented Oct 17, 2013 at 14:29
  • 1
    In my case, it was missing the <% Assembly %> directive in the ASPX page as well as in a ASCX page control. Adding those resolved the problem right away.
    – Web User
    Commented Oct 18, 2013 at 4:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.