문제

I have this in my code:

Assembly assembly = Assembly.LoadFile(dllFile);
//dllFile has the correct value of a path of a .dll file
foreach (Type type in assembly.GetTypes()) {...}

When I debug my program, everything works fine. When I create the exe for my program, the code comes to assembly.GetTypes() and stops executing. What could cause assembly.GetTypes() to work differently when I'm debugging from when I'm using the exe?

도움이 되었습니까?

해결책

Take a look at this link:

http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/3bdaf65c-520c-4a1a-a825-fc2ca2957bf3/

You should never use Assembly.LoadFile(). Use LoadFrom() if you know where the assembly is located, use Load() to let .NET figure out where the assembly is located. Using Load() should be your preference but may require a .config file to help .NET find the assembly

credit to @HansPassant

다른 팁

When you create an exe file, you have to make sure that your assemblies are in the correct folder and also that the exe file has access to the folder.

You can subscribe to that event and do a simple Assembly.LoadFrom from a location known to you or even do some fancy loading of your own based on some system you engineer. There are also TypeResolve and ResourceResolve events in the AppDomain that let you handle those aspects of resolving the various dependencies of an AppDomain. For details see this Microsoft forum thread.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top