Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Effort Error in Test Project #272


User avatar
0
ecairncross created

Hi There,

Thanks again for the fantastic work on the Framework. I followed the test tutorial you made on Code Project, and everything was working fine, but now I'm getting this error message from Effort, and ALL my tests fail. I'm not sure what I changed to create the error, but I can't seem to find a way to fix it...

I've tried the suggestions in the error, but no luck. Any help would be much appreciated!!

Effort.Exceptions.EffortException : The Effort library failed to register its provider automatically, so manual registration is required.

a) Call the Effort.Provider.EffortProviderConfiguration.RegisterProvider() method at entry point of the application

or

b) Add the following configuration to the App.config file: <system.data> <DbProviderFactories> <add name="Effort.Provider" invariant="Effort.Provider" description="Effort.Provider" type="Effort.Provider.EffortProviderFactory, Effort" /> </DbProviderFactories> </system.data>

<entityFramework> <providers> <provider invariantName="Effort.Provider" type="Effort.Provider.EffortProviderServices, Effort" /> </providers> </entityFramework> ---- System.InvalidOperationException : The Entity Framework was already using a DbConfiguration instance before an attempt was made to add an 'Loaded' event handler. 'Loaded' event handlers can only be added as part of application start up before the Entity Framework is used. See <a class="postlink" href="http://go.microsoft.com/fwlink/?LinkId=260883">http://go.microsoft.com/fwlink/?LinkId=260883</a> for more information.


6 Answer(s)
  • User Avatar
    0
    iyhammad created

    I faced this issue before. The Issue simply is, there are some part of your code that requires DbConnection and it's executing before the registration of the the Effort. this happens a lot with the Migration initialization. my issue was I've the Migration initialization part of the Data Module init function which requires DbConnection and it executes before the Effort DbConnection registeration. What I did is i moved the migration initialization to the static constructor of the DbContext (I don't know if this is the best practices or not.) and it worked.

  • User Avatar
    0
    hikalkan created
    Support Team

    If you have used Database.SetInitializer... method in somewhere in your code, it causes that problem. Remove it (at least for tests) and try again. At least that was my case. Also, you can ask it on Effort's Github page.

  • User Avatar
    0
    laasri created

    You can solve this by overriding Dispose method in your Test DbContext class: :)

    public class TestDbContext : DbContext { public TestDbContext() : base("Name=TestConnection") {

      }
    

    ...... protected override void Dispose(bool disposing) { Dispose(); base.Dispose(disposing); } }

  • User Avatar
    0
    worthyvii created

    Just my 2 cents, this happened because I had checked "Run tests in parallel" at the top of the Test Explorer in VS.

  • User Avatar
    0
    worthyvii created

    Oh no, what fixed the problem was running a single test by itself... something seems wrong.

  • User Avatar
    0
    worthyvii created

    Ok this was down to the App.Config in the test project. It needs to be configured to be using the Effort provider instead of your usual one. That fixes all problems