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.Initialize with null or NOOP throws odd exception #476

Closed
subtlekiller opened this issue Mar 10, 2014 · 10 comments
Closed

Mapper.Initialize with null or NOOP throws odd exception #476

subtlekiller opened this issue Mar 10, 2014 · 10 comments
Labels
Milestone

Comments

@subtlekiller
Copy link

Using version 3.0.0.

Following code blows a gasket:

    public void Initialize(string assemblySearchString)
    {
        List<Profile> profiles = new List<Profile>();
        var profileType = typeof(Profile);
        var assemblies = AppDomain.CurrentDomain.GetAssemblies()
            .Where(a => a.FullName.Contains(assemblySearchString));
        foreach (var assembly in assemblies)
        {
            profiles.AddRange(
               assembly.GetTypes()
                // where the type implements the Profile type (or of the same type)
                   .Where(t => profileType.IsAssignableFrom(t) &&
                       // get the default constructor for the profiles (one with no parameters)
                          t.GetConstructor(Type.EmptyTypes) != null)
                // Instantiate the profile.
                   .Select(Activator.CreateInstance)
                   .Cast<Profile>());
        }

        Mapper.Initialize(c => profiles.ForEach(c.AddProfile));
    }

When passing an empty profiles list OR passing null to Mapper.Initialize, AutoMapper gives:
at AutoMapper.TypeMapFactory..ctor()
at AutoMapper.Mapper.<.cctor>b__0() in c:\tfs\Raton\Dev\2014\ThirdParty\AutoMapper-3.0.0\src\AutoMapper\Mapper.cs:line 14
at AutoMapper.Internal.LazyFactory.LazyImpl1.get_Value() in c:\tfs\Raton\Dev\2014\ThirdParty\AutoMapper-3.0.0\src\AutoMapper\Internal\IDictionary.cs:line 124 at AutoMapper.Mapper.get_ConfigurationProvider() in c:\tfs\Raton\Dev\2014\ThirdParty\AutoMapper-3.0.0\src\AutoMapper\Mapper.cs:line 453 at AutoMapper.Mapper.get_Configuration() in c:\tfs\Raton\Dev\2014\ThirdParty\AutoMapper-3.0.0\src\AutoMapper\Mapper.cs:line 446 at AutoMapper.Mapper.Initialize(Action1 action) in c:\tfs\Raton\Dev\2014\ThirdParty\AutoMapper-3.0.0\src\AutoMapper\Mapper.cs:line 232
at Baxter.Raton.BITS.Presentation.WindowsService.AutoMapperInitializer.Initialize(String assemblySearchString) in c:\tfs\Raton\Dev\2014\Raton\BITS\Source\Presentation\WindowsService\AutoMapperInitializer.cs:line 53
at Baxter.Raton.BITS.Presentation.WindowsService.Test.WindowsServiceTests.AutoMapperInitNoProfilesSuccessful() in c:\tfs\Raton\Dev\2014\Raton\BITS\Test\WindowsService\WindowsServiceTests.cs:line 347

@subtlekiller
Copy link
Author

Get this issue in unit test project no matter how many profiles I pass in. Loading the profiles via Assembly.FromFile...

@jbogard
Copy link
Member

jbogard commented Mar 10, 2014

What's the exception?

On Mon, Mar 10, 2014 at 1:06 PM, subtlekiller notifications@github.comwrote:

Using version 3.0.0.

Following code blows a gasket:

public void Initialize(string assemblySearchString)
{
    List<Profile> profiles = new List<Profile>();
    var profileType = typeof(Profile);
    var assemblies = AppDomain.CurrentDomain.GetAssemblies()
        .Where(a => a.FullName.Contains(assemblySearchString));
    foreach (var assembly in assemblies)
    {
        profiles.AddRange(
           assembly.GetTypes()
            // where the type implements the Profile type (or of the same type)
               .Where(t => profileType.IsAssignableFrom(t) &&
                   // get the default constructor for the profiles (one with no parameters)
                      t.GetConstructor(Type.EmptyTypes) != null)
            // Instantiate the profile.
               .Select(Activator.CreateInstance)
               .Cast<Profile>());
    }

    Mapper.Initialize(c => profiles.ForEach(c.AddProfile));
}

When passing an empty profiles list OR passing null to Mapper.Initialize,
AutoMapper gives:
at AutoMapper.TypeMapFactory..ctor()
at AutoMapper.Mapper.<.cctor>b__0() in
c:\tfs\Raton\Dev\2014\ThirdParty\AutoMapper-3.0.0\src\AutoMapper\Mapper.cs:line
14
at AutoMapper.Internal.LazyFactory.LazyImpl1.get_Value() in
c:\tfs\Raton\Dev\2014\ThirdParty\AutoMapper-3.0.0\src\AutoMapper\Internal\IDictionary.cs:line
124
at AutoMapper.Mapper.get_ConfigurationProvider() in
c:\tfs\Raton\Dev\2014\ThirdParty\AutoMapper-3.0.0\src\AutoMapper\Mapper.cs:line
453
at AutoMapper.Mapper.get_Configuration() in
c:\tfs\Raton\Dev\2014\ThirdParty\AutoMapper-3.0.0\src\AutoMapper\Mapper.cs:line
446
at AutoMapper.Mapper.Initialize(Action1 action) in
c:\tfs\Raton\Dev\2014\ThirdParty\AutoMapper-3.0.0\src\AutoMapper\Mapper.cs:line
232
at
Baxter.Raton.BITS.Presentation.WindowsService.AutoMapperInitializer.Initialize(String
assemblySearchString) in
c:\tfs\Raton\Dev\2014\Raton\BITS\Source\Presentation\WindowsService\AutoMapperInitializer.cs:line
53
at
Baxter.Raton.BITS.Presentation.WindowsService.Test.WindowsServiceTests.AutoMapperInitNoProfilesSuccessful()
in
c:\tfs\Raton\Dev\2014\Raton\BITS\Test\WindowsService\WindowsServiceTests.cs:line
347

Reply to this email directly or view it on GitHubhttps://github.com//issues/476
.

@subtlekiller
Copy link
Author

Exception: 'System.TypeInitializationException'
Inner: {System.PlatformNotSupportedException: This type is not supported on this platform IDictionaryFactory
at AutoMapper.Internal.PlatformAdapter.Resolve[T](Boolean throwIfNotFound) in c:\tfs\Raton\Dev\2014\ThirdParty\AutoMapper-3.0.0\src\AutoMapper\Internal\PlatformAdapter.cs:line 15
at AutoMapper.TypeMapFactory..cctor() in c:\tfs\Raton\Dev\2014\ThirdParty\AutoMapper-3.0.0\src\AutoMapper\Internal\TypeMapFactory.cs:line 13}

This type is not supported on this platform IDictionaryFactory

using .NET 4.5.1

Both automapper and .Net4 assemblies are included in the test project as well as the dlls that contain profiles.

@jbogard
Copy link
Member

jbogard commented Mar 11, 2014

There were a few bugs around this fixed in 3.1, and some in the 3.2
prerelease. Can you try the 3.2 prerelease?

On Mon, Mar 10, 2014 at 4:19 PM, subtlekiller notifications@github.comwrote:

'System.TypeInitializationException'

Reply to this email directly or view it on GitHubhttps://github.com//issues/476#issuecomment-37235687
.

@subtlekiller
Copy link
Author

I will try, but I will only be allowed to use an official release.

@subtlekiller
Copy link
Author

It appears that Net4 is not getting copied to my unit test output folder even though AutoMapper is...

@jbogard
Copy link
Member

jbogard commented Mar 11, 2014

Those are to be expected. Try only "uncaught exceptions". This is the only
really possible way for me to probe for assemblies easily.

I understand you can only use approved, released versions, but is it
possible to try it out just to confirm? I can then try and get a hotfix
release out.

On Tue, Mar 11, 2014 at 11:28 AM, subtlekiller notifications@github.comwrote:

Still looking at 3.0.0. Using intellitrace I get a bunch of exceptions in:

private Assembly ProbeForPlatformSpecificAssembly(string platformName)
{
    var assemblyName = new AssemblyName(GetType().Assembly.FullName)
    {
        Name = "AutoMapper." + platformName
    };

    try
    {
        return _assemblyLoader(assemblyName.ToString());
    }
    catch (FileNotFoundException)
    {
    }

    return null;
}
  1. Exception:Thrown: "Could not load file or assembly
    'AutoMapper.Net4, Version=2.3.0.0, Culture=neutral, PublicKeyToken=null' or
    one of its dependencies. The system cannot find the file specified."
    (System.IO.FileNotFoundException) A System.IO.FileNotFoundException was
    thrown: "Could not load file or assembly 'AutoMapper.Net4, Version=2.3.0.0,
    Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
    system cannot find the file specified." Time: 3/11/2014 10:23:38 AM
    Thread:[45244]

Exception:Caught: "Could not load file or assembly 'AutoMapper.Net4,
Version=2.3.0.0, Culture=neutral, PublicKeyToken=null' or one of its
dependencies. The system cannot find the file specified."
(System.IO.FileNotFoundException)
A System.IO.FileNotFoundException was caught: "Could not load file or
assembly 'AutoMapper.Net4, Version=2.3.0.0, Culture=neutral,
PublicKeyToken=null' or one of its dependencies. The system cannot find the
file specified."
Time: 3/11/2014 10:23:38 AM
Thread:[45244]
3.
Exception:Thrown: "Could not load file or assembly 'AutoMapper.WinRT,
Version=2.3.0.0, Culture=neutral, PublicKeyToken=null' or one of its
dependencies. The system cannot find the file specified."
(System.IO.FileNotFoundException)
A System.IO.FileNotFoundException was thrown: "Could not load file or
assembly 'AutoMapper.WinRT, Version=2.3.0.0, Culture=neutral,
PublicKeyToken=null' or one of its dependencies. The system cannot find the
file specified."
Time: 3/11/2014 10:23:38 AM
Thread:[45244]
4.
Exception:Caught: "Could not load file or assembly 'AutoMapper.WinRT,
Version=2.3.0.0, Culture=neutral, PublicKeyToken=null' or one of its
dependencies. The system cannot find the file specified."
(System.IO.FileNotFoundException)
A System.IO.FileNotFoundException was caught: "Could not load file or
assembly 'AutoMapper.WinRT, Version=2.3.0.0, Culture=neutral,
PublicKeyToken=null' or one of its dependencies. The system cannot find the
file specified."
Time: 3/11/2014 10:23:38 AM
Thread:[45244]

and so on.

Reply to this email directly or view it on GitHubhttps://github.com//issues/476#issuecomment-37316463
.

@subtlekiller
Copy link
Author

I resolved this by adding [DeploymentItem("AutoMapper.Net4.dll")] to my unit test. Sorry for the trouble.

@jbogard
Copy link
Member

jbogard commented Mar 11, 2014

So 3.2 is supposed to fix this, by marking the .Net4.dll as a content item
to be copied out. I'm going to re-open and tag this on the 3.2 release just
to make sure.

On Tue, Mar 11, 2014 at 11:37 AM, subtlekiller notifications@github.comwrote:

I resolved this by adding [DeploymentItem("AutoMapper.Net4.dll")] to my
unit test.

Reply to this email directly or view it on GitHubhttps://github.com//issues/476#issuecomment-37317649
.

@jbogard jbogard added this to the 3.2.0 milestone Mar 11, 2014
@jbogard jbogard added the Bug label Apr 15, 2014
@lock
Copy link

lock bot commented May 8, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants