none
DbProviderFactories.GetFactory Fails for Assembly in Working Directory RRS feed

  • Question

  • Hi, I have created a custom data provider with a custom DbProviderFactory.  The problem is that I cannot load the DbProviderFactory using the DbProviderFactories.GetFactory method.  I suspect this is because I don't have the assembly in the GAC, but for this problem, I don't want the assembly in the GAC, I want it in the working directory of the application.  I'm testing this using VS 2010, and the Environment.CurrentDirectory matches the location of the assembly, so according to http://msdn.microsoft.com/en-us/library/ms379620(VS.80).aspx, this should work, because it says "the provider itself must be installed in the Global Assembly Cache (GAC) or in the working directory of the application for DbProviderFactories to work with it."  I have checked for things like typos in the assembly qualified name, not having the type visible in the assembly, but everything seems to be correct.

    Does anyone know why this isn't working and how I could get it to work?


    my blog - Tea Time with Meowkins
    Saturday, June 5, 2010 7:14 PM

Answers

  • Agreed, you should try DbProviderFactories.GetFactoryClasses. I just tested
    the original provider that I wrote with .NET 2.0 with .NET 4.0, the custom
    factory class doesn't show up in the GetFactoryClasses enumeration. I'm
    guessing that the app.config file that I used in .NET 2.0 would have to be
    changed for 4.0 to accommodate the "provider in the working directory,
    machine.config embellished with the custom provider information in
    app.config" method that I referred to in that article.
     
    So does GetFactoryClasses return your custom provider as one of the existing
    factory classes?
     
    Cheers,
    Bob Beauchemin
    SQLskills
     
     
    "ErikEJ" wrote in message news:28af8d08-641f-4142-8357-b43c777189f8...
    Have you tested with DbProviderFactories.GetFactoryClasses ?
    Could you share your app.config file?
     
     
    http://erikej.blogspot.com Erik Ejlskov Jensen - Please mark as answer, if
    this was it.
     
     
    Monday, June 7, 2010 10:17 PM
  • Thanks for the help guys.  I ended up changing everything such that I'm not even using DbProviderFactories anymore, and I'm on to something else now, so I'll have to come back to this later, but I'll tell you what I can remember relating to this.

    First, I made no changes to the app.config, only the machine.config, in the DbProviderFactories node - could that have been the problem?  I don't think so because I also used the GetFactory(DataRow providerRow) method.  Also, the provider factory works great if it is in the GAC (using both GetFactory methods).

    Now, about DbProviderFactories.GetFactoryClasses.  I played around with that for a while with the DbProviderFactory entry in the machine.config.  At first, I had it in the wrong place, and GetFactoryClasses did not show my factory class.  The problem was that I had the wrong machine.config, I was using the .net 2.0 one, under the Framework directory, and I had to switch to the Framework64 one.  When I put the entry there, it showed up with GetFactoryClasses, but GetFactory would throw an exception...unfortunately, I can't remember what that exception was at the moment, so I'll come back later after I get a chance to test this out again.


    my blog - Tea Time with Meowkins
    Wednesday, June 9, 2010 5:27 PM

All replies

  • Have you tested with DbProviderFactories.GetFactoryClasses ?

    Could you share your app.config file?


    http://erikej.blogspot.com Erik Ejlskov Jensen - Please mark as answer, if this was it.
    Monday, June 7, 2010 7:09 AM
  • Agreed, you should try DbProviderFactories.GetFactoryClasses. I just tested
    the original provider that I wrote with .NET 2.0 with .NET 4.0, the custom
    factory class doesn't show up in the GetFactoryClasses enumeration. I'm
    guessing that the app.config file that I used in .NET 2.0 would have to be
    changed for 4.0 to accommodate the "provider in the working directory,
    machine.config embellished with the custom provider information in
    app.config" method that I referred to in that article.
     
    So does GetFactoryClasses return your custom provider as one of the existing
    factory classes?
     
    Cheers,
    Bob Beauchemin
    SQLskills
     
     
    "ErikEJ" wrote in message news:28af8d08-641f-4142-8357-b43c777189f8...
    Have you tested with DbProviderFactories.GetFactoryClasses ?
    Could you share your app.config file?
     
     
    http://erikej.blogspot.com Erik Ejlskov Jensen - Please mark as answer, if
    this was it.
     
     
    Monday, June 7, 2010 10:17 PM
  • Thanks for the help guys.  I ended up changing everything such that I'm not even using DbProviderFactories anymore, and I'm on to something else now, so I'll have to come back to this later, but I'll tell you what I can remember relating to this.

    First, I made no changes to the app.config, only the machine.config, in the DbProviderFactories node - could that have been the problem?  I don't think so because I also used the GetFactory(DataRow providerRow) method.  Also, the provider factory works great if it is in the GAC (using both GetFactory methods).

    Now, about DbProviderFactories.GetFactoryClasses.  I played around with that for a while with the DbProviderFactory entry in the machine.config.  At first, I had it in the wrong place, and GetFactoryClasses did not show my factory class.  The problem was that I had the wrong machine.config, I was using the .net 2.0 one, under the Framework directory, and I had to switch to the Framework64 one.  When I put the entry there, it showed up with GetFactoryClasses, but GetFactory would throw an exception...unfortunately, I can't remember what that exception was at the moment, so I'll come back later after I get a chance to test this out again.


    my blog - Tea Time with Meowkins
    Wednesday, June 9, 2010 5:27 PM