Recently noticed a strange thing in my solutions. I always leave the root namespace empty in my projects. Then, I write all as normal including namespaces on the inherits directives of pages and using the clause namespace in the code behind. Everything worked as expected.
Now I'm experiencing with plugin oriented programming and I'm using a VirtualPathProvider. Standard class that can be found at forums.asp.net article. What happened is that The VirtualPathProvider could not resolve the embedded pages in the plugins projects (namespace MEFTestPlugin1 pEx.) and I found that there where present without namespace.
Wrong: ~/Plugins/MEFTestPlugin1.dll/MEFTestPlugin1.Default.aspx
Found: ~/Plugins/MEFTestPlugin1.dll/Default.aspx
So I had to inform the root namespace in the project and then the first url worked. But then the code-behind was not found.
So I finally found that the only two working combinations are:
<%@ Page Title="" Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="MEFTestPlugin1._Default" %>
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Write("Code-Behinds Worky")
End Sub
End Class
Or
<%@ Page Title="" Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="MEFTestPlugin1.MEFTestPlugin1._Default" %>
Namespace MEFTestPlugin1
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Write("Code-Behinds Worky")
End Sub
End Class
End Namespace
Notice the double namespace in the page directive.
So that was happening in all my solutions and projects and I didn't know about. Any example solutions I download have both assembly and root namespaces informed and namespace defined in code-behind but they work normally !!
Does anyone knows what could be the problem? Sure is something I missed on solutions configuration... Or the fact that all my stuff is VB!!?? My solutions are upgraded from previous versions to VS2010. Could that fact be the problem?
Thanks.
Well, found that this is something related to VB namespaces management, that works different from C# and affects DI. I dropped MEF for Areas and Ninject for IoC and decoupling.