Issue with VSTO add-ins compiling with Reactive UI - c#

When attempting to use ReactiveUI + ReactiveUI.Winforms with VSTO addins i get the compile time error below
I have tried all the different versions of ReactiveUI as far down as v11 with no success.
Step to reproduce:
Create a new VSTO Addin via Visual studio
Add ReactiveUI and ReactiveUI.Winforms via nuget
Try to build
Microsoft.VisualStudio.Tools.Office.targets(176, 9): [MSB4018] The "FindRibbons" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'Create.ExcelAddIn, Version=10.7.0.207, Culture=neutral, PublicKeyToken=e840a71a986082bc' or one of its dependencies. The system cannot find the file specified.
File name: 'Create.ExcelAddIn, Version=10.7.0.207, Culture=neutral, PublicKeyToken=e840a71a986082bc'
Server stack trace:
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at System.UnitySerializationHolder.GetRealObject(StreamingContext context)
at System.Runtime.Serialization.ObjectManager.ResolveObjectReference(ObjectHolder holder)
at System.Runtime.Serialization.ObjectManager.DoFixups()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream stm)
at System.Runtime.Remoting.Messaging.SmuggledMethodReturnMessage.FixupForNewAppDomain()
at System.Runtime.Remoting.Channels.CrossAppDomainSink.SyncProcessMessage(IMessage reqMsg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Build.Framework.ITask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()
=== Pre-bind state information ===
LOG: DisplayName = Create.ExcelAddIn, Version=10.7.0.207, Culture=neutral, PublicKeyToken=e840a71a986082bc
(Fully-specified)
LOG: Appbase = file:///C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.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: Create.ExcelAddIn, Version=10.7.0.207, Culture=neutral, PublicKeyToken=e840a71a986082bc
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/Create.ExcelAddIn.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/Create.ExcelAddIn/Create.ExcelAddIn.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/Create.ExcelAddIn.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/Create.ExcelAddIn/Create.ExcelAddIn.EXE.

Related

C# VSTO Office add-in: “FindRibbons” task failed unexpectedly

Every time I compile the project, I get this error. My AssemblyInfo.cs file does not have the attributes ExcelLocale1033 or SecurityTransparent. There is no VisualStudio folder in C:\Program Files (x86)\MSBuild\Microsoft.
The "FindRibbons" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'ProjectName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'ProjectName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
Server stack trace:
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
Fixed. It's because of a new project that I added to the VSTO solution. This other project's output type (right click project > Properties) used to be Windows Application. I changed that to Class Library and deleted Program.cs which contained this code:
class Program
{
static void Main(string[] args)
{
}
}
The error never showed up again.

System.BadImageFormatException error

I am using Windows Server 2008 R2 Datacenter 64-bit OS. I am using Visual Studio 2013 that has a solution with 2 projects and I am encountering this error.
Exception Details: System.BadImageFormatException: Could not load file
or assembly 'EyeCantSeeEngine' or one of its dependencies. An attempt
was made to load a program with an incorrect format.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to
determine why the assembly 'EyeCantSeeEngine' could not be loaded.
=== Pre-bind state information === LOG: DisplayName = EyeCantSeeEngine (Partial) WRN: Partial binding information was supplied for an
assembly: WRN: Assembly Name: EyeCantSeeEngine | Domain ID: 2 WRN: A
partial bind occurs when only part of the assembly display name is
provided. WRN: This might result in the binder loading an incorrect
assembly. WRN: It is recommended to provide a fully specified textual
identity for the assembly, WRN: that consists of the simple name,
version, culture, and public key token. WRN: See whitepaper
http://go.microsoft.com/fwlink/?LinkId=109270 for more information and
common solutions to this issue. LOG: Appbase =
file:///C:/Users/Administrator/Documents/ISFC_Main/EyeCantSee/EyeCantSeeEngine/
LOG: Initial PrivatePath =
C:\Users\Administrator\Documents\ISFC_Main\EyeCantSee\EyeCantSeeEngine\bin
Calling assembly : (Unknown).
LOG: This bind starts in default load context. LOG: Using application
configuration file:
C:\Users\Administrator\Documents\ISFC_Main\EyeCantSee\EyeCantSeeEngine\web.config
LOG: Using host configuration file:
C:\Users\uni\Documents\IISExpress\config\aspnet.config LOG: Using
machine configuration file from
C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private,
custom, partial, or location-based assembly bind). LOG: Attempting
download of new URL
file:///C:/Users/uni/AppData/Local/Temp/1/Temporary ASP.NET
Files/root/b917a818/774df716/EyeCantSeeEngine.DLL. LOG: Attempting
download of new URL
file:///C:/Users/uni/AppData/Local/Temp/1/Temporary ASP.NET
Files/root/b917a818/774df716/EyeCantSeeEngine/EyeCantSeeEngine.DLL.
LOG: Attempting download of new URL
file:///C:/Users/Administrator/Documents/ISFC_Main/EyeCantSee/EyeCantSeeEngine/bin/EyeCantSeeEngine.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing
terminated.
Stack Trace:
[BadImageFormatException: Could not load file or assembly
'EyeCantSeeEngine' or one of its dependencies. An attempt was made to
load a program with an incorrect format.]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String
codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint,
StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean
throwOnFileNotFound, Boolean forIntrospection, Boolean
suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String
codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint,
StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean
throwOnFileNotFound, Boolean forIntrospection, Boolean
suppressSecurityChecks) +34
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName
assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly,
StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean
throwOnFileNotFound, Boolean forIntrospection, Boolean
suppressSecurityChecks) +152
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,
Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr
pPrivHostBinder, Boolean forIntrospection) +77
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,
Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean
forIntrospection) +16 System.Reflection.Assembly.Load(String
assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String
assemblyName, Boolean starDirective) +38
[ConfigurationErrorsException: Could not load file or assembly
'EyeCantSeeEngine' or one of its dependencies. An attempt was made to
load a program with an incorrect format.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String
assemblyName, Boolean starDirective) +752
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()
+218 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo
ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection
compConfig) +170
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies()
+91 System.Web.Compilation.BuildManager.CallPreStartInitMethods(String
preStartInitListPath, Boolean& isRefAssemblyLoaded) +285
System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager
appManager, IApplicationHost appHost, IConfigMapPathFactory
configMapPathFactory, HostingEnvironmentParameters hostingParameters,
PolicyLevel policyLevel, Exception appDomainCreationException) +521
[HttpException (0x80004005): Could not load file or assembly
'EyeCantSeeEngine' or one of its dependencies. An attempt was made to
load a program with an incorrect format.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9950728
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)
+101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest
wr, HttpContext context) +254
I have tried changing the target platform of the project of the error from x64 to x86 and the error that I encounter next is this.
Exception Details: System.OutOfMemoryException: Exception of type
'System.OutOfMemoryException' was thrown.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[OutOfMemoryException: Exception of type 'System.OutOfMemoryException'
was thrown.] System.Reflection.RuntimeAssembly._nLoad(AssemblyName
fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly
locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder,
Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean
suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String
codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint,
StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean
throwOnFileNotFound, Boolean forIntrospection, Boolean
suppressSecurityChecks) +34
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName
assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly,
StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean
throwOnFileNotFound, Boolean forIntrospection, Boolean
suppressSecurityChecks) +152
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,
Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr
pPrivHostBinder, Boolean forIntrospection) +77
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,
Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean
forIntrospection) +16 System.Reflection.Assembly.Load(String
assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String
assemblyName, Boolean starDirective) +38
[ConfigurationErrorsException: Exception of type
'System.OutOfMemoryException' was thrown.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String
assemblyName, Boolean starDirective) +752
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()
+218 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo
ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection
compConfig) +170
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies()
+91 System.Web.Compilation.BuildManager.CallPreStartInitMethods(String
preStartInitListPath, Boolean& isRefAssemblyLoaded) +285
System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager
appManager, IApplicationHost appHost, IConfigMapPathFactory
configMapPathFactory, HostingEnvironmentParameters hostingParameters,
PolicyLevel policyLevel, Exception appDomainCreationException) +521
[HttpException (0x80004005): Exception of type
'System.OutOfMemoryException' was thrown.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9950728
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)
+101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest
wr, HttpContext context) +254
I have also tried changing the Enable 32-bit Applications in the IIS Application Pools to True but the System.BadImageFormatException error still persist. Greatly appreciated for any suggestions to solve this error.
BadImageFormatException usually means architecture conflits.. Like trying to install a 32 bit assembly with a x64 install util for example.
Also in the pre-bind state information you can read this line:
WRN: A partial bind occurs when only part of the assembly display name
is provided.
WRN: This might result in the binder loading an incorrect assembly.
Which might indicate that you are not using a fully qualified name to load an assembly but just the type. Try specifying the fully qualified name of the assembly you are trying to load.

Could not load file or assembly 'Telerik.Reporting' on IIS without any references in the project to it

I have a web site on IIS. There are a lot of virtual folders with separates sites on it.
I`ve updated one of them and got "Could not load file or assembly 'Telerik.Reporting, Version=6.2.13.110, Culture=neutral, PublicKeyToken=a9d7983dfcc261be' or one of its dependencies. The system cannot find the file specified."
The same errors on the other virtual folder`s sites.
Stack Trace.`[FileNotFoundException: Could not load file or assembly 'Telerik.Reporting, Version=6.2.13.110, Culture=neutral, PublicKeyToken=a9d7983dfcc261be' or one of its dependencies. The system cannot find the file specified.]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +210
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +242
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +17
System.Reflection.Assembly.Load(String assemblyString) +35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +122
[ConfigurationErrorsException: Could not load file or assembly 'Telerik.Reporting, Version=6.2.13.110, Culture=neutral, PublicKeyToken=a9d7983dfcc261be' or one of its dependencies. The system cannot find the file specified.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +12761078
System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +214
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +334
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +203
System.Web.Compilation.BuildManager.ExecutePreAppStart() +152
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151
[HttpException (0x80004005): Could not load file or assembly 'Telerik.Reporting, Version=6.2.13.110, Culture=neutral, PublicKeyToken=a9d7983dfcc261be' or one of its dependencies. The system cannot find the file specified.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722601`
But in this project I don`t use Telerik at all. I created new site on IIS, deploy this project and one work well. But in the main one I still get the error.
What should I do to remove this issue from site with virtual folders? I have to deploy this project to it. I can`t delete it and create new one.
Any suggestions? Restart doesn`t help.
There could be other Web.configs that reference the telerik assembly. You would need to check all of them

window phone 7 error

I have a project that worked fine but today i get this error... even when I creating new project i get same message... I can't understand what is the problem...
Error 1 The "CompileXaml" task failed unexpectedly.
System.IO.FileLoadException: Could not load file or assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
File name: 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' ---> System.Security.SecurityException: Strong name validation failed. (Exception from HRESULT: 0x8013141A)
The Zone of the assembly that failed was:
MyComputer
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Microsoft.Silverlight.Build.Tasks.CompileXaml.LoadSilverlightAssemblies(String[] frameworkPaths)
at Microsoft.Silverlight.Build.Tasks.CompileXaml.GenerateCode(ITaskItem item, Boolean isApplication)
at Microsoft.Silverlight.Build.Tasks.CompileXaml.Execute()
at Microsoft.Build.Framework.ITask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult)
Best Answer of Carl Saldanha (read comments)
Need re-installation...

AppDomain.CreateInstanceAndUnwrap not working in a website

I have a very simple class CompiledFunction (MarshalByRefObject) - I try to create an instance of this in a new domain like so
var appDomainSetup = new AppDomainSetup();
appDomainSetup.ApplicationBase = Path.GetDirectoryName(typeof(CompilerService).Assembly.CodeBase);
var evidence = AppDomain.CurrentDomain.Evidence;
SandboxDomain = AppDomain.CreateDomain("Sandbox", evidence, appDomainSetup);
CompiledFunction<T> result = (CompiledFunction<T>)SandboxDomain.CreateInstanceAndUnwrap(
assemblyName: typeof(CompiledFunction<T>).Assembly.GetName().Name,
typeName: typeof(CompiledFunction<T>).FullName);
This works fine in a Console application, but in an ASP .NET MVC application I get the following exception - can anyone offer any suggestion as to why this is not working in a web app? The T parameter I am passing is System.Decimal
System.IO.FileLoadException was caught
Message=The given assembly name or codebase, 'Ems.Scripting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null', was invalid.
Source=mscorlib
FileName=Ems.Scripting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
FusionLog==== Pre-bind state information ===
LOG: User = EMSLaptop\PeterMorris
LOG: DisplayName = Ems.Scripting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = /C:/Users/PeterMorris/Documents/Visual Studio 2010/Projects/MvcApplication26/MvcApplication26/bin
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Found application configuration file (C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\WebDev.WebServer40.exe.Config).
LOG: Using application configuration file: C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\WebDev.WebServer40.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: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL /C:/Users/PeterMorris/Documents/Visual Studio 2010/Projects/MvcApplication26/MvcApplication26/bin/Ems.Scripting.DLL.
StackTrace:
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName)
at System.AppDomain.CreateInstance(String assemblyName, String typeName)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
at Ems.Scripting.CompilerService.Compile[T](String[] scripts, Dictionary`2 variableDefinitions, IEnumerable`1 referencedAssemblies, ICompiledFunction`1& function, IEnumerable`1& compilerErrors) in C:\Data\EMS\Lib\Ems.Scripting\CompilerService.cs:line 43
InnerException:
The problem was that the Assembly.Code base started with file:///{rest of path here} - when using Path.GetDirectoryName on such a path it replaces file:/// with a single forward slash; so you end up with "/c:\myfolder\myfile.dll"
Getting Uri to tell me the local path was the solution
if (SandboxDomain == null)
{
var appDomainSetup = new AppDomainSetup();
string appBase = typeof(CompilerService).Assembly.CodeBase;
//Added the following line
appBase = new Uri(appBase).LocalPath;
appDomainSetup.ApplicationBase = Path.GetDirectoryName(appBase);
var evidence = AppDomain.CurrentDomain.Evidence;
SandboxDomain = AppDomain.CreateDomain("Sandbox", evidence, appDomainSetup);
}
Looks like you did not properly copy Ems.Scripting assembly for web project or set wrong ApplicationBase for your new domain (more likely).
Path.GetDirectoryName call is suspicious in computing ApplicationBase property.

Categories

Resources