Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapper.Register throws System.ArgumentException exception #540

Closed
ArgoZhang opened this issue May 30, 2019 · 19 comments

Comments

@ArgoZhang
Copy link
Contributor

commented May 30, 2019

hi, PetaPoco.Mapper.Register throws exception in Multi-threading.

System.ArgumentException: An item with the same key has already been added. Key: Bootstrap.Security, Version=1.3.0.0, Culture=neutral, PublicKeyToken=c20f2177a7066899
  Module "System.ThrowHelper", in ThrowAddingDuplicateWithKeyArgumentException
  Module "System.Collections.Generic.Dictionary`2", in TryInsert
  Module "PetaPoco.Mappers", in RegisterInternal
  Module "Bootstrap.Security.DataAccess.DbHelper", in get_DbAccess
  Module "Bootstrap.Security.DataAccess.DbHelper", in RetrieveRolesByUserName
  File "C:\Users\Administrator\Desktop\kasenhoo-BootstrapAdmin-dev-Tabs\BootstrapAdmin\Bootstrap.DataAccess\Role.cs", line 190, col 88, in RetrieveRolesByUserName
    System.Collections.Generic.IEnumerable`1[System.String] RetrieveRolesByUserName(System.String)

how to avoid this exception?

@pleb

This comment has been minimized.

Copy link
Member

commented May 30, 2019

@ArgoZhang what version of PP are you using?

@ArgoZhang

This comment has been minimized.

Copy link
Contributor Author

commented May 30, 2019

PetaPoco | 6.0.415.0
get from Nuget

@ArgoZhang

This comment has been minimized.

Copy link
Contributor Author

commented May 31, 2019

is bug right? or by design?

@pleb

This comment has been minimized.

Copy link
Member

commented May 31, 2019

I’m thinking Bug. But, I can’t say for sure. Are you able to provide a small sample of code that reproduces it?

@ArgoZhang

This comment has been minimized.

Copy link
Contributor Author

commented May 31, 2019

sure.

public class MapperTest
{
    private class StringMapperTest : ConventionMapper
    {
        public StringMapperTest()
        {
            // for test
            Thread.Sleep(2000);
        }
    }

    [Fact]
    public void Register_Exception()
    {
        Assert.ThrowsAny<AggregateException>(() => ThrowExceptionMethod());
    }

    private void ThrowExceptionMethod()
    {
        var t1 = Task.Run(() => OrginalRegisterMethod());
        var t2 = Task.Run(() => OrginalRegisterMethod());
        Task.WaitAll(t1, t2);
    }

    private void OrginalRegisterMethod()
    {
        if (Mappers.GetMapper(typeof(string), null) == null) Mappers.Register(typeof(string), new StringMapperTest());
    }
}
@pleb

This comment has been minimized.

Copy link
Member

commented Jun 5, 2019

@ArgoZhang, I'll get the PRs soon. Sorry, I'm a little snowed under at the moment. I just wanted to drop a message to say "Hey, I see the PRs. Thanks. But, it might be a little bit before I get to them"

@ArgoZhang

This comment has been minimized.

Copy link
Contributor Author

commented Jun 5, 2019

fine! :)

@ArgoZhang

This comment has been minimized.

Copy link
Contributor Author

commented Jul 20, 2019

hi, I have to release a new package(Longbow.PetaPoco) on nuget feeds. because my project have been blocked by the Mapper and IsNew issues. sorry for that. hope resolve the issues ASAP. thanks.

@asherber

This comment has been minimized.

Copy link
Collaborator

commented Jul 20, 2019

If this is something you need for your own use, for now, I would suggest not making the new package publicly available on nuget.org, because then it'll be there forever. You can use a local package source to host your private package, or you can create a free account on myget.org.

@ArgoZhang

This comment has been minimized.

Copy link
Contributor Author

commented Jul 20, 2019

sound good. let me try myget.org

@asherber

This comment has been minimized.

Copy link
Collaborator

commented Jul 20, 2019

Hmm, looks like MyGet has been acquired by another company, and I don't see the free plan advertised anymore. Looks like gemfury.com has a free plan....although it only lets you host a single package!

@asherber

This comment has been minimized.

Copy link
Collaborator

commented Jul 20, 2019

It's possible that if you sign up for a trial at MyGet, it will revert to the old free plan once the trial ends. The free plan only supports public feeds, which usually isn't an issue because someone would still have to have your feed URL to get your package. This tweet suggests that free public feeds are still supported, though they don't say if that's just for existing accounts: https://twitter.com/MyGetTeam/status/1055884411818909696

@ArgoZhang

This comment has been minimized.

Copy link
Contributor Author

commented Jul 20, 2019

@asherber thanks. unfortunately both twitter and myget can not be accessed in China

@asherber

This comment has been minimized.

Copy link
Collaborator

commented Jul 20, 2019

@pleb

This comment has been minimized.

Copy link
Member

commented Jul 20, 2019

@ArgoZhang

This comment has been minimized.

Copy link
Contributor Author

commented Jul 21, 2019

@pleb thanks. i will reuse PetaPoco.Compiled when resolved those issues. 😋
what is GH? Fullname

@pleb

This comment has been minimized.

Copy link
Member

commented Jul 21, 2019

pleb added a commit that referenced this issue Aug 1, 2019

fix(#540): Mapper register method throw ArgumentException (#541)
* fix(#540): Mapper register method throw ArgumentException

#Issue
link #540

* fix: GetMapper check both type and assembly in the key
@pleb

This comment has been minimized.

Copy link
Member

commented Aug 2, 2019

Hey everyone, this is now in dev. Use the latest beta nuget package to try it out

@ArgoZhang

This comment has been minimized.

Copy link
Contributor Author

commented Aug 2, 2019

@pleb its works.

@ArgoZhang ArgoZhang closed this Aug 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.