PRISM: referencing DLL's in the main Project that Module depends on - c#

I am getting this exception in the main Project PrismDashboard:
Source\PrismDashboard\bin\Debug\PrismDashboard.vshost.exe
System.Windows.Markup.XamlParseException occurred
HResult=-2146233087
Message=Could not load file or assembly 'Microsoft.Expression.Interactions, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
This is the project with Bootrstrapper and Shell. It is happening because Shell is using ModuleA from another Project:
Source\Modules\ModuleA
That requires refrence to Microsoft.Expression.Interactions and I can see that this DLL exists in:
Source\Modules\ModuleA\bin\Debug
I'm not getting compile error, and I'm getting runtime error.
ModuleA View will be injected into Shell Region, and this View requires Microsoft.Expression.Interactions which is referenced in ModuleA project but not in the main Project with Bootstrapper and Shell.
I don't want to add reference to DLL's required by other projects in my main project.
Have tried to set Embaded Interop Types on reference in ModulaA but getting error:
Error 1 Cannot embed interop types from assembly 'c:\Program Files (x86)\Microsoft SDKs\Expression\Blend.NETFramework\v4.0\Libraries\Microsoft.Expression.Interactions.dll' because it is missing either the 'ImportedFromTypeLibAttribute' attribute or the 'PrimaryInteropAssemblyAttribute' attribute c:\Program Files (x86)\Microsoft SDKs\Expression\Blend.NETFramework\v4.0\Libraries\Microsoft.Expression.Interactions.dll ModuleA
Error 2 Cannot embed interop types from assembly 'c:\Program Files (x86)\Microsoft SDKs\Expression\Blend.NETFramework\v4.0\Libraries\Microsoft.Expression.Interactions.dll' because it is missing the 'GuidAttribute' attribute c:\Program Files (x86)\Microsoft SDKs\Expression\Blend.NETFramework\v4.0\Libraries\Microsoft.Expression.Interactions.dll ModuleA

The main application needs to be able to find Microsoft.Expression.Interactions in order to load module A, no way around it. Also keep in mind when you distribite your application the same rule applies.
If you really don't want to reference that assembly in your shell project (which btw is actually the easiest way since it will copy it to the main application's output dir so you're settled) the only other option is copying it there manually. Could be done using a post-build event, but by doing that you're also tieing both projects together since they need to know about each other's output directory. Another way is making all projects put their output in the same directory. I'v been using that for some pretty large scale applications and it works nicely. Also distributing the application is then just a matter of copying that entire directory.

Related

errors CS0246, CS1504 and CS2015 when trying to compile through csc [duplicate]

I am trying to make a simple c# program using Growl C# API.
I tried to compile my program in two different ways:
1) I kept my .dll file in the same directory as my .cs file. Than I ran
csc /r:Growl.Connector.dll,Growl.CoreLibrary.dll /out:test.exe *.cs
It compiled fine and also ran fine.
2) Now I have created a directory inside my current working directory named growl and kept all my .dll references there.
Now when I try to compile it using the below command
csc /r:"D:\Modified\Growl_NET_Connector_SDK\libraries\growl\Growl.Connector.dll","D:
\Modified\Growl_NET_Connector_SDK\libraries\growl\Growl.CoreLibrary.dll" /out:test.exe *.cs
It compiled fine but when I tried to run it the below mentioned exception occurred.
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Growl.Connector, Version=2.0.0.0, Culture=n
eutral, PublicKeyToken=980c2339411be384' or one of its dependencies. The system cannot find the file specified.
at GrowlNotification.Program.Main(String[] args)
So, my question is what is the correct way to reference .dll file in csc when files are in an external folder.
Here is the directory structure for 2nd case.
So, my question is what is the correct way to reference .dll file in csc when files are in an external folder.
You're already referencing them at build time. You just need to make them available at execution time too, but copying them into the same directory as the executable, when you want to run it.
You could also investigate using the Global Assembly Cache if these are signed assemblies, but personally I'd stick with just keeping the executable with the libraries on which it depends.
You can add these using the /lib and /reference command-line switches while compiling.
http://msdn.microsoft.com/en-us/library/s5bac5fx.aspx
But (Quote from the article)
An alternative to using /lib is to copy into the working directory any
required assemblies; this will allow you to simply pass the assembly
name to /reference. You can then delete the assemblies from the
working directory. Since the path to the dependent assembly is not
specified in the assembly manifest, the application can be started on
the target computer and will find and use the assembly in the global
assembly cache.
Because the compiler can reference the assembly does not imply the
common language runtime will be able to find and load the assembly at
runtime. See How the Runtime Locates Assemblies for details on how the
runtime searches for referenced assemblies.
so Jon Skeet's answer is better. (I'm just adding this to provide more info than I could in a comment, not as an answer. Jon's answer is the best IMO)
You can create symlinks to the assemblies in your libraries folder so you would only need to keep them updated in one location.

dlls missing after publishing .NET Web

My web project use .NET Framework 4.7.2 and use some references like
System.IO
System.Net
System.Net.Http
System.Net.Http.Formatting
My project works perfectly in local.
However, when I publish my web project on a target directory (for online), and look what it contains in /bin/ :
System.IO is missing
System.Net is present
System.Net.Http is missing
System.Net.Http.Formattingis present
Therefore, when I use my website, I get the obvious error Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
All references have Copy Local = True in Properties but some dll are always ignored. If i copy the dlls from local directory to target directory i get the error Server Error in '/' Application. Cannot load a reference assembly for execution. Exception Details: System.BadImageFormatException: Cannot load a reference assembly for execution. Exactly the same problem as this one.
However the delete/rebuild solution, or adding compilation options solution, doesn't work for me
What do I need to do to get these missing dlls to the destination folder?
Go to Solution Explorer on VS, open references tree, right click on the library(dll) and select properties on the menu. On properties box Copy Local should be True

.net-assembly resolution

I am studying about assemblies and confused on some points after searching I am asking question here. I read about assembly resolution that for strongly named assemblies the order of assembly resolution is to first check GAC then the root directory and then private probing.
Suppose I have a solution with multiple projects and within this there is a folder to place all the reference assemblies lets say log4net and in project where I need to use log4net assembly I add reference of log4net dll pointing to the folder within application solution directory where all referenced dlls have been placed. So why CLR check GAC and then root directory etc why not from the path mentioned while adding reference.
I think you mean "in Visual Studio" when you say "add reference to this".
What will happen when you run the program on a machine where this path does not exist?
Btw. the "Add reference" in visual studio is only used at compile time. It will copy the referenced dll to the target folder.
Visual Studio creates a target folder (Standard bin\Debug or bin\Release) in the project folder and stores there all files (exe, dll, config) for deployment.
Installing DLLs into GAC has to be done manually and makes sense only if it is a DLL which is used by several applications and should be used carefully.
You could get strange and difficult to find errors when your application loads a dll from GAC and this dll has another version as expected by your application.

Assembly's dependent Assemblies are not copied

I have a scenario where i have library say for example : SomeLibrary.dll which references to System.Net.Http and System.Net.Http.Formatting just an example with Copy Local flag true, and that assembly is actually consuming some types of these two dlls.
Then i create a new Project and i add reference to SomeLibrary.dll with Copy Local flag true, when use methods of this dll which are internally using the above 2 libraries, the runtime error comes saying:
Could not load file or assembly 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
What i was expecting was it should have dependent assemblies on which SomeLibrary.dll depends should also be in the bin folder copied, which is not happening.
Am i missing something here?
UPDATE:
For your information, i am able to make it work by adding reference seperateely to those 2 dlls but wondering why i need to add seperately if i have reference to SomeLibrary.dll which is dependent on those 2 dlls.
I just had a very similar sounding problem, where I had assembly A depending on assembly B, and B depended on System.Net.Http.Formatting.dll. For some reason on my build server it wasn't copying System.Net.Http.Formatting.dll so it was missing in the final package it created (though in my case it wasn't in either projects' output folder). It worked fine locally on my development machine and I verified the assembly existing in the same place on the build server as it did on my machine (C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies).
I worked-around the problem with this answer to the related question, which was to switch to using the Microsoft.AspNet.WebApi.Client NuGet package to pull in that assembly explicitly. Unfortunately I'm still not sure what the problem was.

ImageMagick.NET Exception

I am getting a FileNotFoundException when trying to use ImageMagick.NET, taken from the "bin" folder in the source at.. http://imagemagick.codeplex.com/releases/view/30302
The exact exception I get is...
"Could not load file or assembly
'ImageMagickNET.dll' or one of its dependencies. The specified module
could not be found."
The ImageMagickNET.dll is in my output folder, so what other dependencies does it need?
Add a Reference to the 'ImageMagickNet.dll' found in the 'bin\ReleaseQ8' or 'bin\RealeaseQ16' folders, choose one of them.
After that you have to download the ImageMagick 6.5.3-10 version DLLs for Q8/Q16 because the ImageMagickNet was built to this version.
(I found all versions at this link: http://image_magick.veidrodis.com/image_magick/binaries/
For example, for Q16 download: ImageMagick-6.5.3-10-Q16-windows-dll.exe)
Then install it and copy all DLL files from 'C:\Program Files\ImageMagick-6.5.3-Q16' to your bin folder.
Now you should be able to run it properly.

Categories

Resources