Unity application block 2.0 - The given assembly name or codebase was invalid

前端 未结 7 1548
-上瘾入骨i
-上瘾入骨i 2021-01-04 03:26

Interfaces (In the assembly named \"Interfaces\". In project :- Interfaces)

namespace Interfaces
{
    public interface IDoSomeWork1
    {
          


        
相关标签:
7条回答
  • 2021-01-04 04:07

    I found that the least time consuming method of finding which Type exactly failed to bind is the following:

    1. Go to Sources section of Unity page at codeplex http://unity.codeplex.com/SourceControl/list/changesets
    2. Select a version and download the sources
    3. Build DEBUG version of Unity and Unity.Configuration (if your project uses more of unity assemblies, build them as well)
    4. Remove references to unity from your project and add references to assemblies from step 3
    5. In Visual Studio go to Debug > Exceptions and make sure Common Language Runtime Exceptions has a checkbox in the Thrown column.

    Now go crash that thing. Execution will stop in Unitys' TypeResolverImpl.SearchAssemblies method and typeNameOrAlias parameter will hold the answer!

    0 讨论(0)
  • 2021-01-04 04:10

    In case anyone else ever has the same problem - I was also getting this error but had a slightly different problem. I was trying to load an assembly that clearly existed like the following:

    Assembly.Load("C:\\Program Files\\MyProgram\\MyAssembly.dll");
    

    After lots of trial and error I figured out that you aren't supposed to pass the path and you certainly aren't supposed to include .dll extension. The following fixed my issue:

    Assembly.Load("MyAssembly");
    

    Hopefully that helps someone else sooner or later!

    0 讨论(0)
  • 2021-01-04 04:12

    If you connect up the domain AssemblyResolve event you can get the assembly that has failed to bind.

     AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
    
    0 讨论(0)
  • 2021-01-04 04:18

    works like this

    Dim dllData = System.IO.File.ReadAllBytes(dllFullPath)
    Dim asb As System.Reflection.Assembly
    
    asb = System.Reflection.Assembly.Load(dllData)
    
    Dim cls As Object = asb.CreateInstance("namespace.class")
    
    0 讨论(0)
  • 2021-01-04 04:19

    There is a better way now! Unity has a new version (currently 2.1.505.2) which clearly reports the details and lets you get to the bottom of it immediately.

    You can find binaries and source here: http://unity.codeplex.com/releases

    0 讨论(0)
  • 2021-01-04 04:26

    Before I answer my question, I must state that the code posted above didn't give me any problem (build error etc.). It just gave me the error I stated in my question. The problem with Unity at this point of time is that It does not provide which assembly or a which types in the assembly could not be loaded. This is a requested feature.

    In my case It was a missing assembly problem. I didn't reference Entities assembly in to the client application project. It seems that that "Entities" assembly could be resolved only at the run-time (since it didn't give me any compile time error). However, the run-time error was also not useful at all.

    I had a look a Fusion Log viewer (It should be in the .NET SDK folder). What a gem of an utility It is. It can log all kind of assembly bindings (all or only failures) and It give a very neat description of which assembly could not load. Very helpful! FailedToLoadAssemblyDetected

    Log

    So, next time, you get this "The given assembly name or codebase was invalid" error, try Fusion Log Viewer. It wont help you in finding which types couldn't be loaded. However,at least you will be sure all your assemblies are getting loaded correctly.

    0 讨论(0)
提交回复
热议问题