Custom Role Provider give "can't load type error"

A

Alias

Hi -

I'm trying to implement a custom RoleProvider based on the SqlRoleProvider.
I keep receiving a an error that it can't load type
'MyRoleTest.MyRoleProvider' when trying to load my RoleProvider. However
this only occurs after deployment. On my local machine it works fine. So I
created the most basic role provider project I could think of. It is below:


Imports System.Web.Security
Imports System.Web.Configuration
Imports System.Configuration.Provider
Imports System.Collections.Specialized
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Diagnostics
Imports System.Web
Imports System.Globalization
Imports System.Text
Imports Microsoft.VisualBasic

Public Class MyRoleProvider
Inherits SqlRoleProvider
Public Overrides Sub Initialize(ByVal name As String, ByVal config As
System.Collections.Specialized.NameValueCollection)
MyBase.Initialize(name, config)
End Sub
End Class

Here is how I reference it in the web.config :

<roleManager enabled="true" defaultProvider="TheRoleProvider">
<providers>
<clear/>
<add name="TheRoleProvider" type="MyRoleTest.MyRoleProvider"
connectionStringName="dbConn" applicationName="TestApp"/>
</providers>
</roleManager>

Locally it runs fine, but once deployed on the server it errors out on the
<add...> line. I'm using the fully qualified type name and the DLL for the
project containing the provider is in the Bin folder.

The odd thing is that I did the exact same thing for the MembershipProvider,
inheriting from SqlMembershipProvider and referencing it the same way in the
web.config and it works without a hitch. I would apprecieate any ideas. I
did try adding the MyRoleProvider class to the Web App Project itself in the
App_Code folder but that gave the same error.
 
G

Guest

Good morning,

Assuming class definition should stay withing web app project, move
MyRoleProvider class file to app_code folder (do not define custom namespace
name in the class file), remove 'MyRoleTest' from webconfig
<add name="TheRoleProvider" type="MyRoleProvider"
connectionStringName="dbConn" applicationName="TestApp"/>
Otherwise, if provider resides in separate control library, reference
library and add fully qualified class name:
<add name="TheRoleProvider" type="FullyQuilifiedClassNameWithNamespace"
connectionStringName="dbConn" applicationName="TestApp"/>

hope it helps
 
A

Alias

Hi Milosz -

Thanks for responding. Is there anything else I can be looking for? What
you wrote is exactly what I wrote, that is why I can't figure this out. I'm
wondering if I'm missing a reference or something. I've tried it both ways
and I didn't use a namespace when I had it included in my web project. The
class is scaled down to the bare minimum and it works perfect locally but
not when it is deployed. Is there something I must override when inheriting
from SqlRoleProvider? I'm starting to wonder if their is a native .Net DLL
that isn't being deployed. Thanks!
 
G

Guest

No no, read my reply again :) I pointed you were using
"MyRoleTest.MyRoleProvider" instead of just "MyRoleProvider" in web.config. I
reckon this is the only reason for this exception (the message clearly
indicates certain type cannot be loaded). All references are there, i they
weren't, you would get exception like 'cannot load assembly blablalaa'. Move
the class to app_code directory (make sure it's public), then update
web.config with

<add name="TheRoleProvider" type="MyRoleProvider"
connectionStringName="dbConn" applicationName="TestApp"/>

Should work.
 
A

Alias

Hi Milosz -

I was using MyRoleTest.MyRoleProvider for the type because my class was in a
seperate project.

At the bottom of my post I said that I tried adding the class directly to
the App_Code folder, when I did that I was using only the class name for
MyRoleProvider for the type. Which is why I can find no reason for this not
to work.

It works perfect for my custom MembershipProvider class however the exact
same thing doesn't work for my custom RoleProvider class when deployed.

Thanks for taking the time to respond. I appreciate that.
 
G

Guest

Howdy,

Sorry for misunderstanding. Try another resolution -create a control library
with the custom provider, then reference it in web site project, (don't
forget about with fully quilified name in web application's web.config file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top