I am getting following error while creating EntityManager in my Data Access Layer(DAL) (Class Library project):
File name: 'Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
I am getting this error from my TestProject (Class Library project) where I have return NUnit test cases.
I have one web application which also calls DAL, but during this call it is able to create EntityManager properly.
Actually I need to add following lines to config files which avoids the above error:
<runtime>
<loadFromRemoteSources enabled="true" />
</runtime>
Now the problem is, I have obviously added these lines to my web.config, and that is I am able to create EntityManager. But how can I add this lines to my TestProject (which is a Console Library), because it will not have a config file associated with it.
PS: I am using NHibernate and NET Persistence API.
You have to copy the Iesi.Collections in the bin directory, the easiest way is to add a reference in your test project.
Related
I am making some test with XUnit on a application using CefSarp.
But the test are crashing with the exception :
System.IO.FileNotFoundException: Could not load file or assembly 'CefSharp, Version=55.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138'or one of its dependencies. The system cannot find the file specified.
at CefSharp.CefSharpApp.OnBeforeChildProcessLaunch(CefSharpApp* , CefRefPtr* commandLine)
On Xunit issue tracker (https://github.com/xunit/xunit/issues/4) the workaround is to set the shadowCopy option to false. But this does not work for me.
CefSharp have some files which need to be next the executable (https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions#Runtime_dependencies). All those files are present in the bin folder and when I check the current directory with System.IO.Directory.GetCurrentDirectory(), this is the right folder.
I tried to use the SetDllDirectory from Kernel32 to add the bin folder but it change nothing.
I also tried to load the assembly manualy with Assembly.LoadFile(). This call succeed but later when cef is initialized, the exception still happen. So the problem is probably not finding the assembly itself but the files needed by CefSharp.
Where should I put all the CefSharp file to allow XUnit to find them? I have the same problem with the Xunit test integrated in VisualStudio and with the Xunit console.
Edit :
Problem solved (see anwser). All the test are passing except test created with SpecFlow.
It throw the Could not load file or assembly but with CefSharp.Core this time.
The problem was that CefSharp does not support multiple AppDomains.
The config file of the unit test in the CefSharp repo contains the following :
<configuration>
<appSettings>
<add key="xunit.appDomain" value="denied"/>
</appSettings>
</configuration>
which prevent XUnit to use multiple AppDomains.
This config must be added in the app.config of each test library .
The CefSharp test also contains
var isDefault = AppDomain.CurrentDomain.IsDefaultAppDomain();
if (!isDefault)
{
throw new Exception(#"Add <add key=""xunit.appDomain"" value=""denied""/> to your app.config to disable appdomains");
}
to check is multiple AppDomains are used.
Background
I'm building a mobile app for an existing DNN 7 site; made by someone else who left a year ago or so. I had previously set up a WebApi module to handle authentication. Then I had the idea of setting up a class library to hold my DTO objects; since I would have to modify several existing modules to expose web methods and they'd have to interact with my app. So I created a class library threw in two classes and compiled. Added the dll reference to both my app and the web module and they have no issues building when referencing my objects. However, when I send a web request, from either my app or Postman chrome extension, to my module I get:
"Could not load file or assembly 'Elf.Web.Models, Version=1.0.6081.13955, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.",
My app doesn't seem to have issues creating and using the objects, just with the web module.
What I Tried/Checked
Properties I made sure both my class library and my web module were targeting the same framework; .NET Framework 4.5
Reference Property Copy Local is True and per Other Question
I tried manually editing my .csproj file to add the attribute Private to True under my reference. I even tried adding a binding redirect to my assembly.
Manual I also tried opening up my modules install zip tossing the class library dll into the bin folder, re-zip, and then installed to the dnn site. The problem persisted.
If anyone else has an idea of what could be an issue it'd be appreciated.
Putting the library dll in the bin folder of the installer zip file will not automatically put your library dll file into the bin folder of the DotNetNuke installation during install.
Add this to the installer .dnn file under the <components> node.
<component type="Assembly">
<assemblies>
<assembly>
<name>myLibrary.dll</name>
<path>bin</path>
</assembly>
</assemblies>
</component>
If you want the file to be added to the installer zip automatically, you have to make a reference in the ModulePackage.targets file.
<Copy SourceFiles="$(MSBuildDnnBinPath)\myLibrary.dll" DestinationFolder="$(MSBuildProjectDirectory)\Package\bin"/>
We use a 3rd party mixed mode assembly that interfaces with a printer device.
In one of our applications, the assembly functions correctly.
In another application, it was generating the following exception:
Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
After doing some research, I discovered that I could add the following to the app.config file to resolve this problem:
<startup useLegacyV2RuntimeActivationPolicy="true">
(The application that works already had this setting in its app.config)
Although this did resolve the "Mixed mode assembly" issue, now I'm seeing a somewhat different problem:
External component has thrown an exception
The strange thing is that I have one application which works correctly and another application which does not. They both call the third party assembly via the same code (which is another one of our assemblies).
I tried creating a very simple test app which calls the third party assembly using the same code path, and it also fails with the "External component has thrown an exception" error.
I've compared the app.config files for all of the applications and they are essentially the same, and I've double checked that all of the build settings are the same for each. Both projects target .NET 4.0 and X86.
There is obviously something different about the two applications but I'm at a loss to identify what it is.
Development environment is Visual Studio 2010.
Does anyone have any suggestions on what other areas I could investigate?
#tsells was right: there was a missing dependency
The third party assembly in question depended on another DLL that was present in the first applications bin folder.
I copied all of the files from the working application's bin folder to the non-working application's bin folder, and it resolved the problem.
From there it was just a matter of deducing which DLL was missing and including it in the second applications project.
When there are dependencies missing, you can use tools like CheckAsm for managed and Dependency Walker for unmanaged libraries to check for dependencies.
I'm building Web project using TFS 2010. The project contains Silverlight client and .NET/C# server side. Both of these (client and server) are referencing one 3rd party library for which we have Silverlight and .NET version, but both versions use the same name. The problem is that msbuild with outdir property specified puts all the libraries to one flat hierarchy in output directory so one library overwrites the other.
I know that one solution would be to modify build template and not specify outdir, but this brings problems with other parts of the build template (I had problem with unit tests and I read about people having problems with putting output to _PublishedWebsites).
Another workaround would be to rename that library/libraries so the names will not collide. But this will not be solution if there is a lot of such libraries.
I'd like to find some clean solution. Do you know about some elegant way how to solve this?
According to Microsoft there are (at least) three ways of referencing assemblies:
install the assembly in the GAC
specify the assembly in the application configuration
or use the AssemblyResolve Event
The GAC is no option here, as you would have the same problem (same names).
Using the AssemblyResolve Event and then use Assembly.LoadFrom would possibly a way of doing it, but easier would be imho ...
... to do it the second mentioned way: specify the assembly in the application configuration. Here you basically edit the App.config like so:
<configuration>
<runtime>
<assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
<probing privatePath=”bin;Silverlight;ParentFolder\SubFolder;”/>
</assemblyBinding>
</runtime>
</configuration>
and the application will search for the assemblies in specified directories.
So, you could create specific folders (possibly "NET" and "Silverlight" or the like), copy the respective assembly into that folder and probe for the assembly in the proper folder as described above.
Considering that when no reference is specified in the application configuration the application will be looking into either the same folder as the referencing assembly or into a folder with the name of the referencing assembly, you could also simply create 2 folders with the same name as the respective application (say "Client" and "Server" if they are called "Client.exe" and "Server.exe") and copy the proper assembly into that folder. In that case there would not even be any need to change the application configuration file.
I have a C# WinForms Project which contains some WCF service definition files which I have created in the project by adding standard classes (not using Add Item > WCF Service).
The project contains some dependencies that require me to build the project for x86 processors.
If I edit the app.config file with the WCF Service Configuration Editor and try to use the "Create New Service ..." wizard, and then browse to the project EXE file (in the debug folder) I get an error, (which I've read is because I'm targeting the x86 processor):
Could not load file or assembly 'EXE_FILE_NAME' or one of its dependencies. An attempt was made to load a program with an incorrect format.
So, upon changing the target to All CPUs, compiling the project again, and then trying to create the service in the WCF Service Configuration Editor again, I now get a different error:
Could not load file or assembly 'SOLUTION_NAME, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
(To clarify, I CAN still compile the project when targeting all CPUs, but get an error at runtime due to a dependency)
Is anybody able to help me with this problem, so I can add the services defined in app.config file using the wizards in WCF Service Configuration Editor? (I think that if I add the services to the WCF Service Configuration Editor when targeting All CPUs I can make any modifications thereafter, regardless of the target)
When debugging, look at the exception detail. From what you've described my guess is you will an assembly loading error in the fusion log because the dependencies of the WCF service can't be satisfied by looking in the default locations.
Say for example you're referencing MrCritter.MyService.dll which defines a WCF service and has a dependency on something like log4net or nHibernate. As long as nothing from those dependencies is leaking into the WCF host (eg returning an ILog) yes you'll be able to compile fine but will get ReflectionTypeLoadException thrown when trying to instantiate the service class if those dependencies aren't somewhere it can find (eg in the executing directory, in GAC etc).