Ninject throw an exception while loading dependencies - c#

After using my application successfully in development for a couple of weeks, I shipped it to my client. The application use Ninject to handle dependencies.
When I try to run the application on the client machine, an error occurs:
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
Stack:
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at Ninject.Infrastructure.Language.ExtensionsForAssembly.HasNinjectModules(Assembly assembly)
at Ninject.Modules.AssemblyNameRetriever.AssemblyChecker.GetAssemblyNames(IEnumerable`1 filenames, Predicate`1 filter)
at Ninject.Modules.AssemblyNameRetriever+AssemblyChecker.GetAssemblyNames(System.Collections.Generic.IEnumerable`1<System.String>, System.Predicate`1<System.Reflection.Assembly>)
at Ninject.Modules.AssemblyNameRetriever.GetAssemblyNames(System.Collections.Generic.IEnumerable`1<System.String>, System.Predicate`1<System.Reflection.Assembly>)
at Ninject.Modules.CompiledModuleLoaderPlugin.LoadModules(System.Collections.Generic.IEnumerable`1<System.String>)
at Ninject.Modules.ModuleLoader.LoadModules(System.Collections.Generic.IEnumerable`1<System.String>)
at Ninject.KernelBase..ctor(Ninject.Components.IComponentContainer, Ninject.INinjectSettings, Ninject.Modules.INinjectModule[])
at MyApplication.Main.Application_Start()
at MyApplication.Main..ctor()
at MyApplication.Program.Main()
What can cause this exception?
Framework 4.0
NInject 3.0.0.0
Thank you.

I would guess that the IoC container (Ninject) is looking for an assembly to reflect upon that cannot be found. Perhaps an assembly is not being packaged propely with your deployment? That could also explain why it works on your development machine but not on the client machine.

Related

Missing Browserlink in VS2019, Where is browserlink acquired / loaded from normally?

My local install of VS2019 (16) seems to be missing references to BrowserLink. I've tried repairing the installation, and installing multiple different SDK's to no avail.
Where is BrowserLink normally located? And what is the mechanism that causes it to be loaded in development versions? It doesn't seem to be packaged seperately from VS since version 12, unless you are using the new .net core versions.
We have checked the GAC, NuGET, and are running out of options.
It's a .net 4.5 project, if that's relevent.
Could not locate assembly Microsoft.WebTools.BrowserLink.Runtime, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a in the Assembly Stores configured. Requesting assembly:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Exception: Could not locate assembly Microsoft.WebTools.BrowserLink.Runtime, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a in the Assembly Stores configured. Requesting assembly:
The root cause is almost certainly something to do with the dumb way this project has a shared non-standard assembly cache, and doesn't fallback to normal dev locations, but the question is about what the normal location/mechanism is for BrowserLink (16) to be loaded.
If you have installed your VS2019 in default options, you can find the Browser Link library files in this path:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\Microsoft\Web Tools\Browser Link
(Replace the path of your installation location as appropriate)
You can then decide whether to copy Microsoft.WebTools.BrowserLink.*.dll to the assembly cache of your application or include this path in your application.

Call .NET Standard DLL in SQL Server

I have a requirement set upon me to run a .NET Standard project from T-SQL. I'm finding very little info about this. I've set the TRUSTWORTHY setting to ON.
Importing the test program dll I'm receiving the error below.
I try importing the netstandard.dll from the C:\Program Files\dotnet\sdk\2.2.103\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\ folder. This fails with the error below. But even after importing System.Data.Common from the same folder I keep receiving the error below.
When importing netstandard.dll from the C:\Program Files\dotnet\sdk\NuGetFallbackFolder\netstandard.library\2.0.3\build\netstandard2.0\ref folder I receive no errors. However when calling the function I receive the error below.
Msg 10313, Level 16, State 51, Line 17
An error occurred while using the .NET Framework during IL compilation. The server may be running out of resources. Try running the query again. If the problem persist, contact a support professional.
System.IO.FileLoadException: Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. Assembly in host store has a different signature than assembly in GAC. (Exception from HRESULT: 0x80131050) See Microsoft Knowledge Base article 949080 for more information.
System.IO.FileLoadException:
at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
.NET Framework assemblies work without issue. Is running .NET Standard assemblies supported on SQL Server? If it's not supported what would be the workaround? Is there any solution more simple than calling a web service through .NET Framework and letting the web service call the .NET Standard code?
SQL Server supports .NET Framework 4 assemblies, using certain libraries listed at https://learn.microsoft.com/en-us/sql/relational-databases/clr-integration/database-objects/supported-net-framework-libraries?view=sql-server-2017.
The latest "what's new" page regarding CLR in SQL Server mentions only features added in SQL Server 2012: https://learn.microsoft.com/en-us/sql/relational-databases/clr-integration/clr-integration-what-s-new?view=sql-server-2017
.NET Core and .NET Standard are newer things (introduced in 2014 and 2016, respectively).

How to use SignalR as client in windows service? (File not found exception: at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpClient.Initialize)

I'm going to use SignalR in a windows service as client.
Service is running under administrator privileges.
And "Microsoft.AspNet.SignalR.Client" package added by nuget.
running code as windows application has no errors and runs correctly. but when I install it as service, service stops and in windows Events I can see this error.
this answer did not resolved my problem.
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
Exception Info: System.IO.FileNotFoundException
at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpClient.Initialize(Microsoft.AspNet.SignalR.Client.IConnection)
at Microsoft.AspNet.SignalR.Client.Transports.TransportHelper.GetNegotiationResponse(Microsoft.AspNet.SignalR.Client.Http.IHttpClient, Microsoft.AspNet.SignalR.Client.IConnection, System.String)
at Microsoft.AspNet.SignalR.Client.Transports.AutoTransport.GetNegotiateResponse(Microsoft.AspNet.SignalR.Client.IConnection, System.String)
at Microsoft.AspNet.SignalR.Client.Transports.AutoTransport.Negotiate(Microsoft.AspNet.SignalR.Client.IConnection, System.String)
at Microsoft.AspNet.SignalR.Client.Connection.Negotiate(Microsoft.AspNet.SignalR.Client.Transports.IClientTransport)
at Microsoft.AspNet.SignalR.Client.Connection.Start(Microsoft.AspNet.SignalR.Client.Transports.IClientTransport)
at Microsoft.AspNet.SignalR.Client.Connection.Start()
I don't know why, but when I catch error, the error text changes and says System.Net.Http is missing.
And I don't know why it runs perfectly as widows application, but not in service.

How to execute with a copied dll from another machine - c#

I am trying to provide a colleague with a dll that is from my build so she can execute with the changes i have made. Unfortunately she gets the following error
The system was unable to launch the requested screen. --->
Unable to display screen.
---> System.IO.FileLoadException: Could not load file or assembly 'file:///name.dll' or one of its dependencies. Operation is not
supported. (Exception from HRESULT: 0x80131515) --->
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
Now if she were trying to run it in visual studio i could set the loadFromRemoteSources switch - however this dll is replacing a dll in an install version on a vagrant box. How can i enable the dll to run in this scenario?
Thanks

The type initializer for 'CrystalDecisions.Shared.SharedUtils' threw an exception

I'm working on a project and have run into an issue. When I run my code I get this error message:
The type initializer for 'CrystalDecisions.Shared.SharedUtils' threw an exception
The title of the message is "TypeInitializerException was unhandled".
I receive this error at this line of code:
this.crystalReportViewer = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
I've been looking up ways to fix this issue, but I keep running into another issue. Everything I find about how to fix this says that the platform target should be changed to x86. All the comments that follow that advice are always positive because it seems to work for everyone, but it's not working for me. I also tried the platform target as x64. When I do that, I don't receive the previously stated error, but instead I receive a new error that reads:
The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
The title of this message is "InvalidOperationException was unhandled".
And the error is on this line:
db.Open();
db, of course, being set to a new OleDbConnection(connection). connection = an Access db.
Why am I receiving the first error and not the second error when platform target is x86, and vice versa if the platform target is x64?
Stacktrace:
System.TypeInitializationException was unhandled
Message=The type initializer for 'CrystalDecisions.Shared.SharedUtils' threw an exception.
Source=CrystalDecisions.Shared
TypeName=CrystalDecisions.Shared.SharedUtils
StackTrace:
at CrystalDecisions.Shared.SharedUtils.get_CurrentControl()
at CrystalDecisions.Shared.SharedUtils.GetEffectiveCulture()
at CrystalDecisions.Shared.LocaleManager..ctor()
at CrystalDecisions.Windows.Forms.CrystalReportViewer.InitReportViewer()
at CrystalDecisions.Windows.Forms.CrystalReportViewer..ctor()
at Client_Manager.ReportViewer.InitializeComponent() in C:\Users\Will\Desktop\Client_Manager\SyndicateII\ReportViewer.Designer.cs:line 31
at Client_Manager.ReportViewer..ctor() in C:\Users\Will\Desktop\Client_Manager\SyndicateII\ReportViewer.cs:line 27
at Client_Manager.Form1..ctor() in C:\Users\Will\Desktop\Client_Manager\SyndicateII\Form1.cs:line 174
at Client_Manager.Program.Main() in C:\Users\Will\Desktop\Client_Manager\SyndicateII\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.BadImageFormatException
Message=Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Source=CrystalDecisions.Shared
FileName=log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304
FusionLog==== Pre-bind state information ===
LOG: User = Will-PC\Will
LOG: DisplayName = log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304
(Fully-specified)
LOG: Appbase = file:///C:/Users/Will/Desktop/Client_Manager/SyndicateII/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Will\Desktop\Client_Manager\SyndicateII\bin\Debug\Client_Manager.vshost.exe.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304
LOG: Attempting download of new URL file:///C:/Users/Will/Desktop/Client_Manager/SyndicateII/bin/Debug/log4net.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
StackTrace:
at CrystalDecisions.Shared.SharedUtils..cctor()
InnerException:
This looks like it's the original problem:
InnerException: System.BadImageFormatException
Message=Could not load file or assembly 'log4net, Version=1.2.10.0,
Culture=neutral, PublicKeyToken=692fbea5521e1304'
or one of its dependencies. An attempt was made to load a program
with an incorrect format.
So it looks like either you're using the wrong version of log4net if it has multiple versions for different architectures, or you've just copied the assembly incorrectly. This part of the log seems relevant too:
LOG: Attempting download of new URL
file:///C:/Users/Will/Desktop/Client_Manager/SyndicateII/bin/Debug/log4net.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
That looks like it's the file you need to check for correctness.
It could be useful to someone: if you have the option to do it, go to IIS and set the Application Pool to 32 bit applications only.
That made the trick for me.
(Of course, your application could be made to run only on 64 bit. In that case, I think the installing of the 64 bit redistributable of CrystalReports should solve the issue)
You should install SAP Crystal Reports runtime for .Net 4.0
I had the same issue. 32bit app running on a 64bit server. I had installed the 64bit runtime and the above exception was thrown. After installing the 32bit version all worked as expected.
What I did for this error was to install CrystalReport Runtime. It seems missing some dlls. Check this post out for the package SAP Crystal Reports runtime for .Net 4.0 (64-bit).
Make sure you have the correct version installed for your environment it try the 64bit installer not the 32bit one as they will both install fine but then the wrong one will cause the mentioned error.
I had the exact same problem and installing the 64bit version instead fixed things for me
this problem is the driver of crystal report is not install on the client and they are in the crystal report home directory and sub folder
and named crystal.forms and crystal.shared and crystal suport and so
I solved my problem changing the application pool identity, using the local profile and the administrator login (take a look if the password expires).
Symptoms are similar.
I think that Log4net pops up because Crystal wants to log the error that has already happened.
I don't have any log4net in my project, neither the dll file.
My project is compiled with AnyCpu over a 64bit server, and I already have both CRRedist x86 x64 installed.
I also tried to run in 32bit mode without any change.
I'm having the same issue with crystal report, I just change Platform Target "Any CPU" as you can see in screenshot below too.
Depending on the version you have installed, if you only have the 32-bit version installed you must compile to x86 or if you only have the 64-bit version installed you must compile on x64, if you have both versions installed you must compile on anycpu.
If you compile on anycpu but on the pc you have the 32-bit version it will send you an error.
Cheers
As other people already figured out: This can happen due to runtime mismatch (x86 / x64).
After force building my application for x86 architecture, the error was fixed.
You should install the Crystal Reports Runtime Engine for .Net Framework and
Crystal Reports for Microsoft Visual Studio.

Categories

Resources