- Home /
FileNotFoundException (System.reflection) when using SmarFox2.dll
Hi everyone I compiled scripts via monoruntime and i got automatically their referenced assemblies (the 'usings') and its work but when i am using "Using Sfs2X" i got FileNotFoundException
I have only one library (SmartFoxServer2.dll) and it is driving me crazy. I am using in Unity 4.0 the "smartfox2.dll" which is in a folder named "Plugins". I am working with visual studio 2010. I can use it in my C# script :
public class ThisIsMyClass : MonoBehaviour
{
Sfs2X.SmartFox _smartFoxSession = null;//This causes an exception
[...]
}
And in another script in charge to compile "ThisIsMyClass.cs" into "ThisIsMyClass.dll" :
public class CompileTheseScripts : MonoBehaviour
{
List<string> locationsOfAssemblies = new List<string>();
void OnGUI()
{
if (GUILayout.Button("Compile")) { Compilation(); }
[...]
}
void Compilation()
{
//Get the referenced assemblies in the given type
locationsOfAssemblies.AddRange(GetReferencesAssembliesPaths(typeof(ThisIsMyClass)));
[...]
}
public static IEnumerable<string> GetReferencesAssembliesPaths(Type type)
{
AssemblyName[] asns = type.Assembly.GetReferencedAssemblies();
foreach (AssemblyName an in asns)
{
yield return Assembly.ReflectionOnlyLoad(an.FullName).Location;
//This instruction causes the FileNotFoundException
//when using Sfs2X in ThisIsMyClass.cs
}
}
}
This is the Exception i got when using Sfs2X in ThisIsMyClass.cs :
FileNotFoundException: Could not load file or assembly 'SmartFox2, Version=0.9.4.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
This is the SmartFox2.dll view:
#region Assembly SmartFox2.dll, v2.0.50727
// C:\Users\usrlocal\Desktop\shell\Assets\Plugins\SmartFox2.dll
#endregion
using Sfs2X.Bitswarm;
using Sfs2X.Core;
using Sfs2X.Entities;
using Sfs2X.Entities.Managers;
using Sfs2X.Logging;
using Sfs2X.Requests;
using Sfs2X.Util;
using System;
using System.Collections.Generic;
namespace Sfs2X
{
public class SmartFox : IDispatchable
{
public SmartFox();
public SmartFox(bool debug);
public IBuddyManager BuddyManager { get; }
public int CompressionThreshold { get; }
public ConfigData Config { get; }
[...]
}
}
Is someone have an idea of how to solve this exception please ?
Answer by PommPoirAbricot · Jun 18, 2013 at 12:42 PM
For those having a similar problem i finally find another way :
public static IEnumerable<string> GetReferencesAssembliesPaths1(Type type)
{
AssemblyName[] asns = type.Assembly.GetReferencedAssemblies();
AppDomain domain;
foreach (AssemblyName an in asns)
{
domain = AppDomain.CurrentDomain;
yield return domain.Load(an.FullName).Location;
}
}
Instead of that:
public static IEnumerable<string> GetReferencesAssembliesPaths(Type type)
{
AssemblyName[] asns = type.Assembly.GetReferencedAssemblies();
foreach (AssemblyName an in asns)
{
yield return Assembly.ReflectionOnlyLoad(an.FullName).Location;
}
}
Your answer
Follow this Question
Related Questions
Reflection on Unity class 1 Answer
How can I get more information about this error: "The classes in the module cannot be loaded"? 1 Answer
Loading Script from Asset Bundle in iOS and WebGL. 2 Answers
Are Assembly definition files are not build system files? 1 Answer
How does Unity call Update() etc without override or reflection? 2 Answers