Hi Philip,
Sorry to bother you again.... Been really pushing LinFu on some edge cases lately... but I've come across a serious problem.
For some reason, the types created by LinFu seem to be somewhat different than the types used by the by running code in the .NET framework.
I'm not sure why this is happening, and the only way I can really explain this issue is through some code.
So, I've posted a Unit Test that, in my view, should pass, but fails when using LinFu.
http://www.bitarmory.com/temp/TestLinFu.zip
A type set from a constructor of a constructed object (by LinFu) is different than the type retrieved from the typeof() operator.
The TypeHandle.Value on both types (from Container.GetService<>()->.ctor():this.GetType() and typeof()) return different pointers to type metadata structures.. I'm not sure why when they should be the same types.
The unit test in the TestLinFu.zip illustrates this point. I look forward to your insight. It's quite possible I'm overlooking something minor here, but from what I can see, they should be both the same exact type and the test should pass.
It's possible, that the Loader is loading the .dlls in different load contexts? I found this issue when I was working with Dictionary<Type>, and noticed that the types created from the Container were not correctly hashing with types created from typeof() when they should have been the same.
Environment:
Visual Studio 2008 SP1 Beta
.NET 3.5 SP1 Beta
I've also tested in VS 2005, the same unit test fails in .NET 2.0.
Thanks,
Brian
----------------------------------------------
Brian Chavez
Bit Armory, Inc.
http://www.bitarmory.com
Hi Philip,
Thanks for the clarification. But this is a really weird situation..
http://www.bitarmory.com/temp/fail.jpg
and I'm not crazy......the unit test is failing on my end.. haha. What happened to Unit Tests and repeatability?!?!
I'll try on my laptop.
Thanks,
Brian
----------------------------------------------
Brian Chavez
Bit Armory, Inc.
http://www.bitarmory.com
Thanks for the patch Philip.
It took me nearly 2 days to figure out what was going wrong with my code, until I found that the Dictionary< Type > wasn't working like it was suppose to.
Then finding that the TypeHandle pointers were pointing to different metadata structures when they should logically be the same. Then finding that LinFu was the culprit passing in the bad TypeHandle.Value.
Thanks again for the fix, I'll update my assemblies tonight, and now I can get back into my main work!
Yeah, sometimes a single line of code can have far reaching consequences. :)
Take care,
Brian
----------------------------------------------
Brian Chavez
Bit Armory, Inc.
http://www.bitarmory.com
From:
linfufr...@googlegroups.com [mailto:linfufr...@googlegroups.com] On
Behalf Of Philip Laureano
Sent: Friday, July 18, 2008 10:24 PM
To: linfufr...@googlegroups.com
Subject: Re: LinFu and .NET type problems
Thanks for pointing this out,
Brian! I never thought that a single line of code would make such a difference.
I went ahead and patched the AssemblyLoader in revision 137, so you shouldn't
have anymore problems with duplicate assemblies. Thanks for all your help!
Regards,
Philip Laureano
Actually, Assembly.LoadFrom(string) takes in a filename/path, not an assembly name.
From:
linfufr...@googlegroups.com [mailto:linfufr...@googlegroups.com] On
Behalf Of Philip Laureano
Sent: Friday, July 18, 2008 9:25 PM
To: linfufr...@googlegroups.com
Subject: Re: LinFu and .NET type problems
If InterfaceAssemblyC is only loaded once, then you should be able to get around the duplication by working with the interfaces instead of the concrete class instances. On the other hand, if you absolutely need to do name-based assembly loading, you can probably derive your own implementation from AssemblyLoader and call Assembly.LoadFrom() so that you'll have complete control over which assembly gets loaded into memory.