Issue while adding a AssemblyRefrence to ProjectAssembly.

SyntaxEditor for WPF Forum

Posted 5 years ago by Manoj
Version: 15.1.0620
Platform: .NET 4.5
Environment: Windows 8 (64-bit)
Avatar

Hi, 

 

When I call this code Project.AssemblyReferences.AddFrom(filename);, it consistently failed to add the assembly, it does not throws an error at all, any idea what could be causing this?

Comments (7)

Posted 5 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

There is likely an exception that we are catching.  I would recommend that in the VS exceptions window, you set all CLR Exceptions to break when thrown. That way you can see anything internal that our assembly might be catching, such as file not found exceptions, etc.  That should give you more insight about the problem.


Actipro Software Support

Posted 5 years ago by Manoj
Avatar

Thanks for reply, 

 

Yes I did enabled the CLR Exception, and it is not throwing any exception, nothing at all.

Posted 5 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

If you do have break on throw for all CLR exceptions then you should see something if you are calling that method.  For instance, when I ran the sample you emailed, I got a FileNotFoundException (Could not find file 'S:\Test\ConsoleApplication3\bin\Debug\WSI.Common.Configuration') since that assembly wasn't in the bin/Debug folder.

Also I noticed that your Program class code didn't include the ".dll" at the end of the path passed to AddFrom().  So even if you included the .dll in bin/Debug, it still would get a FileNotFoundException unless you append ".dll" to the end of the path.  It should work if you do both those things.


Actipro Software Support

Posted 5 years ago by Manoj
Avatar

Yes you are right, sorry I was dumb enough to not realize that, however would you mind changing that code in there and do this -

Project.AssemblyReferences.AddFrom(AssemblyDirectory + "\\WSI.Common.Configuration.dll");
Project.AssemblyReferences.Remove(Project.AssemblyReferences[0]);
Project.AssemblyReferences.AddFrom(AssemblyDirectory + "\\WSI.Common.Configuration.dll");

 

You will see what I am seeing at my end, can happily send you update Solution, if you like.

Also the main problem is if I remove the assembly and add the assembly again it does not Add the dll to assembly refrence.

Posted 5 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Ok when I do that, I get this FileLoadException:

"The assembly '' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain."

Basically .NET reflection for assemblies stinks.  We used to do Assembly.ReflectionOnlyLoadFrom(path) calls internally when you called AddFrom() however customers reported that the method locked the file (bad design in .NET itself).  Thus we switched over to effectively doing Assembly.ReflectionOnlyLoad(File.ReadAllBytes(path)), but that has the downside of not supporting reloading.

I'd recommend that you call Assembly.ReflectionOnlyLoadFrom on your side and pass that result to the Add (instead of AddFrom) method.  That will allow you to add/remove assemblies.  We hope to provide some workaround for this sort of thing in the future, whether it be using separate AppDomains for loading or using Roslyn.

[Modified 5 years ago]


Actipro Software Support

Posted 5 years ago by Manoj
Avatar

Well understood, However my concerned is that why I am not able to see this FileLoadException at my end, if we were getting that error, we could have shown it our users.

Posted 5 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

We do handle the FileLoadException so it won't bubble up, but you should still be able to see it when debugging in VS if you have break on throw checked for that exception type.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.