我想在运行时使用实例化一个类
_syncHelper = (ISyncHelper) Activator.CreateInstance("SBD.Syrius.Synchronisation", "SyncHelper");
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
System.IO.FileNotFoundException: Could not load file or assembly
'SBD.Syrius.Synchronisation' or one of its dependencies. The system cannot find the file specified.
File name: 'SBD.Syrius.Synchronisation'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase,
Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName)
at SBD.Syrius.DataLayer.DataHelper.get_SyncHelper() in e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DataLayer\DataHelper.cs:line 35
at SBD.Syrius.DataLayer.Context.SaveChanges() in e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DataLayer\Context.cs:line 99
at SBD.Syrius.UI.MDIHelper.AttemptToSave(Context Db) in e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.UI\MDIHelper.cs:line 51
=== Pre-bind state information ===
LOG: User = saturn\kirsten
LOG: DisplayName = SBD.Syrius.Synchronisation
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: SBD.Syrius.Synchronisation | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information
and common solutions to this issue.
LOG: Appbase = file:///E:/EShared/Syrius6/syrius_syrius/SBD.Syrius.UI/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : SBD.Syrius.DataLayer, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file:
E:\EShared\Syrius6\syrius_syrius\SBD.Syrius.UI\bin\Debug\SBD.Syrius.UI.vshost.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from
C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or
location-based assembly bind).
LOG: Attempting download of new URL file:///E:/EShared/Syrius6/syrius_syrius/SBD.Syrius.UI/bin/Debug/SBD.Syrius.Synchronisation.DLL.
LOG: Attempting download of new URL file:///E:/EShared/Syrius6/syrius_syrius/SBD.Syrius.UI/bin/Debug/SBD.Syrius.Synchronisation/SBD.Syrius.Synchronisation.DLL.
LOG: Attempting download of new URL file:///E:/EShared/Syrius6/syrius_syrius/SBD.Syrius.UI/bin/Debug/SBD.Syrius.Synchronisation.EXE.
LOG: Attempting download of new URL file:///E:/EShared/Syrius6/syrius_syrius/SBD.Syrius.UI/bin/Debug/SBD.Syrius.Synchronisation/ SBD.Syrius.Synchronisation.EXE.
我收到的错误包含指向 MSDN here的链接,但我找不到如何为程序集指定文本标识的示例。
我注意到完整的错误表明它正在寻找错误的文件夹以及带有大写 .DLL 的文件。我的文件是用小写的 .dll 创建的
是否有示例说明如何为程序集提供完全指定的文本标识?我应该尝试更改 .dll 扩展名的大小写吗?
如果我实际上将 .dll 复制到 UI\bin\debug 文件夹,那么我会得到一个不同的错误
A first chance exception of type 'System.TypeLoadException' occurred in mscorlib.dll
System.TypeLoadException: Could not load type 'SyncHelper'
from assembly
'SBD.Syrius.Synchronisation,版本 = 1.0.0.0,文化 = 中性,PublicKeyToken = null'。
at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name,
Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName)
at SBD.Syrius.DataLayer.DataHelper.get_SyncHelper() in
e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DataLayer\DataHelper.cs:line 35
at SBD.Syrius.DataLayer.Context.SaveChanges() in
e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DataLayer\Context.cs:line 99
at SBD.Syrius.UI.MDIHelper.AttemptToSave(Context Db) in
e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.UI\MDIHelper.cs:line 51