Editor throws TypeLoadException during build

Hi. I have a project that runs without errors in the editor. But when i try to make a build, it stops compiling at ~15-20% and gives me those errors (horizontal lines are not part of error text, i just thought it would be nice to separate everything visualy):

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.AssemblyTypeInfoGenerator.GetFields (Mono.Cecil.TypeDefinition type, Boolean isGenericInstance, System.Collections.Generic.Dictionary`2 genericInstanceTypeMap) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/BuildPipeline/AssemblyTypeInfoGenerator.cs:229)
UnityEditor.AssemblyTypeInfoGenerator.AddType (Mono.Cecil.TypeReference typeRef, System.Collections.Generic.Dictionary`2 genericInstanceTypeMap) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/BuildPipeline/AssemblyTypeInfoGenerator.cs:150)
UnityEditor.AssemblyTypeInfoGenerator.AddBaseType (Mono.Cecil.TypeReference typeRef, System.Collections.Generic.Dictionary`2 genericInstanceTypeMap) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/BuildPipeline/AssemblyTypeInfoGenerator.cs:209)
UnityEditor.AssemblyTypeInfoGenerator.AddType (Mono.Cecil.TypeReference typeRef, System.Collections.Generic.Dictionary`2 genericInstanceTypeMap) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/BuildPipeline/AssemblyTypeInfoGenerator.cs:161)
UnityEditor.AssemblyTypeInfoGenerator.GatherClassInfo () (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/BuildPipeline/AssemblyTypeInfoGenerator.cs:302)
UnityEditor.AssemblyHelper.ExtractAssemblyTypeInfo (System.String assemblyPathName) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/AssemblyHelper.cs:262)

Internal compiler error. See the console log for more information. output was:
Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.

  at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)

  at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0 

  at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0 

Error building Player because scripts had compiler errors

All hubbub aside, the compiler is throwing a TypeLoadException because it’s failing to access some class during the build process. This is usually caused by a conflicting name.

Do any of your classes have the same name as some class in Unity?

Are you using any plugins that might have that problem? Especially if you have dll files in your project. Most reports I saw about this were trying to mix Playmaker and some Kinect plugin, but that doesn’t mean it couldn’t happen elsewhere.

Okay it’s kinda solved, but is even wierder now. I’ve mede a new project and copied all the files from this one to mess with them an see what causes the mistake. I tryied to make a build as it is just to be sure to get same mistakes - and everything worked out! The build was complete with no errors! I launched it and it worked as intended.
Tried to do same with old project - and got those errors. Tried do do that in new project - everything was working.

I have no problems with finishing the projest in the new folder, but i’m still curious: what could that be?