Question

Below here is my code within the project named Presentation, and I also have another project named MyNamespace and MyNamespace2 (within same solution) in which I have classes generated by EntityFramework. I added reference of MyNamespace project into Presentation project.

1: <asp:Repeater ID="MyRepeater" runat="server" ItemType="MyNamespace.MyEntityClass" SelectMethod="SelectMethod">
2:     <ItemTemplate>
3:         <li><a href="<%# Item.Link %>">
4:             <%# Item.Text %>
5:         </a></li>
6:     </ItemTemplate>
7: </asp:Repeater>

Now when I try using IntelliSense within the quotes after ItemType attribute, I only get classes listed from MyNamespace2, but none from MyNamespace. Also, when I try to run this web application navigate to the page that contains above code, even though builds successfully, I get following error:

Compiler Error Message: CS0246: The type or namespace name 'MyNamespace' could not be found (are you missing a using directive or an assembly reference?)

Interestingly enough, within the designer, IntelliSense works with Item's properties, so the type of Item was actually resolved correctly by the designer.

Now what is wrong here? Thanks.

Was it helpful?

Solution

I found my problem. It seems it is not enough to have the other project (MyNamespace) referenced in Presentation. Doing this let me use classes in MyNamespace in codebehind files, but not in aspx files.

I added following lines to my Web.Config file, in order to use those classes in aspx pages:

<configuration>
....
  <system.web>
  ....
    <compilation debug="true" targetFramework="4.5">
      ....
      <assemblies>
        .....
        <add assembly="MyNamespace, Version=1.0.0.0, Culture=neutral, PublicKeyToke=null" />
      </assemblies>
    </compilation>
    ....
    <pages>
    ....
      <namespaces>
        ....
        <add namespace="MyNamespace" />
      </namespaces>
    </pages>
  </system.web>
</configuration>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top