I have a need to create a custom SqlDataProvider for DNN (v4.05.03). However, once I created it and made my optimizations and changes, I began receiving the following error:
System.ArgumentNullException: Value cannot be null. Parameter name: type
Having created alternate providers before, I know that this error normally points to the "type" value of the provider node being incorrect (missing, typo, etc.). However, this is not the case. I copied and pasted to ensure this (and over and over again during troubleshooting).
So, in order to remove the variables of my changes, I recreated the error and this problem by creating a new project pointing at the DNN dll and then copied and pasted the default data provider code from DNN. I had to make 5 changes in order for this work. These were to move the type into my namespaces, and to avoid namespace/type ambiguity. Here are the changes:
Line 35: (FROM) Namespace DotNetNuke.Data
(TO) Namespace MyCompany.Provider
Line 37: (FROM) Public Class SqlDataProvider
(TO) Public Class PortalSqlDataProvider
Line 38: (FROM) Inherits DataProvider
(TO) Inherits DotNetNuke.Data.DataProvider
Line 56: (FROM) Dim objProvider As Provider = CType(_providerConfiguration.Providers(_providerConfiguration.DefaultProvider), Provider)
(TO) Dim objProvider As DotNetNuke.Framework.Providers.Provider = CType(_providerConfiguration.Providers(_providerConfiguration.DefaultProvider), DotNetNuke.Framework.Providers.Provider)
Line 150: (FROM) If RoleID.ToString = Common.Globals.glbRoleNothing Then
(TO) If RoleID.ToString = DotNetNuke.Common.Globals.glbRoleNothing Then
I KNOW that this is all I have changed because I am using software to compare the two files. When I compile the new provider and deploy it to the bin of the DNN site, I also add the following line to the Web.Config:
<add name="MyCompanySqlDataProvider" type="MyCompany.Provider.PortalSqlDataProvider, MyCompany.SqlDataProvider" connectionStringName="SiteSqlServer" upgradeConnectionString="" providerPath="~\Providers\DataProviders\SqlDataProvider\" objectQualifier="" databaseOwner="dbo" />
As you can see, this is identical to the line used for the DNN provider except that there are the necessary changes for "type" and "name". I also changed the "defaultProvider" value to match the new provider "name" (copied and pasted). Here is the finished product:
<data defaultProvider="MyCompanySqlDataProvider">
<providers>
<clear />
<add name="MyCompanySqlDataProvider" type="MyCompany.Provider.PortalSqlDataProvider, MyCompany.SqlDataProvider" connectionStringName="SiteSqlServer" upgradeConnectionString="" providerPath="~\Providers\DataProviders\SqlDataProvider\" objectQualifier="" databaseOwner="dbo" />
<add name="SqlDataProvider" type="DotNetNuke.Data.SqlDataProvider, DotNetNuke.SqlDataProvider" connectionStringName="SiteSqlServer" upgradeConnectionString="" providerPath="~\Providers\DataProviders\SqlDataProvider\" objectQualifier="" databaseOwner="dbo" />
</providers>
</data>
I have verified in the bin directory that the DLL is present and accounted for. Also, the name matches the defined name in the provider configuration above. Just to be sure that the DLL is indeed found, I tried changing the value of "type" and the error changed. In addition, I have also deleted the temporary files for the DNN sites (several times).
As a final troubleshooting step, I built and ran the source version of DNN v4.05.03 and set breakpoints to the line in Reflection.vb (line: 227) that this error occurs at, and all of the arguments are valid and NOT null. The CreateInstance method of the mscorlib.Activator class is throwing this error.
Line 227: Return Activator.CreateInstance(CreateType(TypeName, CacheKey, UseCache))
Each time I try to use this new (almost unchanged) provider, I get the same error:
System.ArgumentNullException: Value cannot be null. Parameter name: type
Does anyone know what the problem is? I am killing myself trying to get this to work. Most importantly, can you recreate this problem using the same steps I described?