System.Security.SecurityException being thrown on initializing StructureMap bootstrapper - exception

I am running a .NET 4.0 web application locally using the Visual Studio Development Server (built in web server with VS2010), and for the last couple months, my StructureMap bootstrapper file has worked perfectly.
I'm using StructureMap 2.6.1
I have not changed the Bootstrapper file or the Web.config file, and suddenly, I'm getting this strange error when trying to start up my web application.
Here is the error being thrown from the website:
it's a bit tough to read. It says:
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException. Request Failed.
here is the code in my bootstrapper file:
public class BootStrapper
{
public static void ConfigureStructureMap()
{
ObjectFactory.Initialize(x =>
{
x.AddRegistry<ProductRegistry>();
});
}
}
public class ProductRegistry : Registry
{
public ProductRegistry()
{
For<IFirmRepository>()
.Use<FirmRepository>().Ctor<string>("connectionString").Is(ConfigurationManager.ConnectionStrings["FeesAndFlows"].ConnectionString);
For<ICryptographyService>()
.Use<Rijndael>();
For<IUserRepository>()
.Use<UserRepository>().Ctor<string>("connectionString").Is(ConfigurationManager.ConnectionStrings["FeesAndFlows"].ConnectionString);
For<IAuthenticationService>()
.Use<AuthenticationService>();
For<ILogger>()
.Use<DatabaseLogger>();
}
}
The error is being thrown on this line:
x.AddRegistry<ProductRegistry>();
I've already tried adding each of these lines to my Web.config file, one at a time, and they didn't fix the problem:
<trust level="Full" />
and
<securityPolicy>
<trustLevel name="Full" policyFile="internal"/>
</securityPolicy>
Does anyone have any ideas or might have heard of a problem like this? It's pretty important, b/c without StructureMap starting up correctly, my entire application will not run.
Thanks,
Mike
UPDATE:
Ok, so it appears my problem is local. Other developers here can download the code, and runs it just fine on their local machines. Weird. They bootstrap StructurMap just fine and all instances are resolved...
Any ideas on why just my machine can't bootstrap StructureMap when running in debug mode locally for my web project?

Are you running the code from a network drive by any chance (ie is your documents folder redirected onto a network drive)? Are you in an enterprise environment running on a domain?
If the former it's likely that the code is running in the intranet security context. If the former isn't true but the later is, then its quite possible that a network administrator has changed the enterprise wide CAS policy.

Okay, so this was the problem. The StructureMap.dll was blocked by Win 7. I don't know how is become blocked or where it became blocked, but apparently, when I downloaded the StructureMap.zip file onto my system, the .zip file was blocked, which in turn, led to all the items extracted from the .zip file being blocked as well.
Every time I unblocked it, it went back to blocked when I tried to run the web app.
The way I fixed it was to go back to the original .zip file, unblock it, extract it, and then replace my StruectureMap.dll reference with one that was not blocked.
Insane.
I don't even know WHAT causes file to suddenly become blocked or what process in Windows 7 determines what file(s) should be blocked, but this strange operating system "feature" cost me a day's worth of work.

I had the exact same issue at the exact same place, ObjectFactory.Initialize:
Server Error in '/X.ServiceHost' Application.
Inheritance security rules violated while overriding member:
'StructureMap.StructureMapException.GetObjectData(System.Runtime.Serialization.SerializationInfo,
System.Runtime.Serialization.StreamingContext)'. Security
accessibility of the overriding method must match the security
accessibility of the method being overriden.
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.TypeLoadException: Inheritance security
rules violated while overriding member:
'StructureMap.StructureMapException.GetObjectData(System.Runtime.Serialization.SerializationInfo,
System.Runtime.Serialization.StreamingContext)'. Security
accessibility of the overriding method must match the security
accessibility of the method being overriden.
Getting the latest StructureMap package from NuGet (2.6.4.1) fixed the issue.
StructureMap NuGet Package

Related

0x80070005 E_ACCESSDENIED when debugging WinRT Windows.Net.Http on a Low Integrity Level process

Please see sample projects at https://github.com/jurocha-ms/LowILAccessDenied.
An E_ACCESSDENIED error is thrown when attaching a debugger (Visual Studio) to a Windows process with Low Integrity Level.
This is a snippet of the failing code:
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::Web::Http;
...
auto client = HttpClient{};
auto response = co_await client.GetAsync(
Uri{L"https://raw.githubusercontent.com/microsoft/react-native-windows/main/.yarnrc.yml"});
auto body = co_await response.Content().ReadAsStringAsync();
Follow the repo's README for building instructions.
Open with Visual Studio.
Start project SandboxLauncher.
This will launch process SandboxTest with Lower Integrity Level.
When prompted, attach the Visual Studio Debugger to SandboxTest.exe, then press ENTER.
The program will fail with the following message:
[0x80070005] A network capability is required to access this network resource
Remarks:
If SandboxLauncher is started without attaching the debugger when SandboxTest prompts for it, the program will succeed.
If the SandboxTest project is launched directly, it will have a Medium Integrity Level (or High, if running Visual Studio as an Administrator) and attaching the debugger won't cause the failure. The program will succeed.
The problem doesn't show if the HTTP call is made via plain WinInet APIs. There may be some interaction issues between Visual Studio's debugger and WinRT/COM.
This is not the issue with Universal (UWP) apps that lack the "private network client" capabilities. Normal Win32 (Desktop) apps do not have a manifest that grants such capabilities.
Is there a specific set up needed for Low IL processes and debuggers?

Service fabric upgrade failing due to change in namespace

I have a service fabric application stuck in "Upgrading" mode.
The exception is:
Could not load type 'DB.IAddUser' from assembly 'DB' at
WebApi.Startup.ConfigureServices(IServiceCollection services)
My change was that of renaming the name space, from 'DB' to 'DB.Interfaces'.
This class is only used as a constructor dependency, and registered as such
Startup.cs
services.AddSingleton<IAddUser, AddUser>();
UserController.cs
private IAddUser addUser;
public UserController(IAddUser addUser){
this.addUser = addUser;
}
Why would this cause SF to get stuck?
Additionally, it only got stuck on the last upgrade domain, and not on the others.
I might be mistaken but if upgrade was successful on other upgrade domains then it is not code related issue.
Try to rollback the application upgrade and upgrade again:
Start-ServiceFabricApplicationRollback -ApplicationName fabric:/MyApp
documentation
It turns out that this had nothing to do with service fabric (as expected and as #SteppingRazor said).
The problem seems to be related to MSBuild/Azure devops build task, I had upgraded nuget package
Microsoft.VisualStudio.Azure.Fabric.MSBuild
from 1.6.7 to 1.6.8 and it seems that the build was still using older code (confirmed via a decompiler).
Reverting back to 1.6.7 solved the issue (albeit its just a workaround)

Brokered Component not working when deploying to client

I created a test App with brokered copmonent and it runs smooth on my machine, but when moved it to a tablet and did all the required settings (regsvr32, icacls), it throws an exception. then I went and downloaded the Microsoft Northwind sample and it act the same. works fine on my machine but not on the other tablet. Am I missing any thing here? here is the exception, it's casting exception and Access denied exception:
Unable to cast COM object of type 'NorthwindRT.DAL.FileWatcher' to interface type 'NorthwindRT.DAL.IFileWatcherClass'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{23F40340-AEB1-5774-5705-64488C9BDD3A}' failed due to the following error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
but I did on the tablet the same things I did on the developing machine!
I moved the required files to the correct directory and enabled read/execute to all applications and I registered the proxy using regsvr32. Also the user can access the directory where the implementation dll is located so Access is denied exception is weird.
I did my research about brokered comp and I am doing exactly like the available documentations!
Any Ideas? Am I missing anything here? Is there extra settings I need to do? is my system missing any required dlls?
The App does not have access to msvcr120d.dll
add "ALL APPLICATION PACKAGES" to this dll and it will solve the issue.
I am also working on brokered component, so far I did had some success in development as well as deployment.
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
You need to run icacls in the folder where you have the proxystub.dll and the winmd implementation.
icacls . /T /grant "ALL APPLICATION PACKAGES":RX
Now if you're deploying to a device that does not have a dev environment (i.e. Visual studio), you need to install Visual C++ Redistributable for Visual Studio 2015 (you can use whatever VS version you have, it just happend that i am using VS2015). You can download it here. And one more thing, since you don't have a development environment in the device, you would like to deploy Release assemblies not Debug so that the assemblies won't be referencing libraries or dll that is for debug (i.e. msvcr120.dll instead of msvcr120d.dll) because it won't be found in a clean device.
Lastly, I have a blog about brokered component. You might want to check it out.

How do I determine which assembly is missing in Mono 2.10.2?

I have a web server with MONO 2.10.2 (fast-cgi) on a CentOS 6 box. Running a plain-vanilla MVC 3 site works great. However, when I add MySql.Data, it gives me a not-so-helpful error:
System.IO.FileLoadException: The assembly name is invalid.
My DLLs are in the right place. They're referenced properly. Everything has been done correctly, but Mono still complains that it can't find an assembly without telling me which one. The problem occurs after simply adding a reference to MySql.Data and without changing any code. I've looked through the MySql.Data source solution and the references that it needs seem to exist on the web server.
I understand other people have the same problem. I am happy to debug it myself, but I'm new to Mono and I can't figure out how to get a more-detailed error messages. I've checked Mono's site for instructions to enable more detailed logging, but their docs assume a certain base knowledge about Mono that I do not have.
Is there a way to get more detailed information when Mono fails to load an assembly?
I'm not sure if these details matter, but just in case...
- Mono: 2.10.2 (served via fastcgi-mono-server4)
- MySql: Connector.Net 6.4.4.0 (from the v4 set in the .Net & Mono download)
- Webserver: NGINX 1.0.11
- OS: CentOS 6
If you can get a "test case" that compiles to an application, try:
MONO_LOG_LEVEL="debug" MONO_LOG_MASK="dll" mono my_app.exe
Or just temporarily edit your CGI script so that it sets those two variables. Check the logs - you should see what is not loaded propely.

Problem hosting wcfservice on mydoamin.com

I have an asp.net and a wcf service created. I hosted wcfservice on localhost(IIS) and the as.net web application also on IIS. Both work fine. I want to host both wcf and my asp.net web application on a registered domain. But when I right click on wcf service & click on publish and eneter details of the site I got error
""The "IsCleanMSDeployPackageNeeded" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or
assembly
'Microsoft.Web.Deployment, Version=7.1.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The system
cannot find the file specified."
Affte googleing I installed MSwebdeplot v2 on my machine &
tried again. but this tiel I get error "Web deployment
task failed. (Attempt by method
'Microsoft.Web.Publishing.Tasks.VSMSDeployDriverInCmd.LogTrace
(Microsoft.Web.Deployment.DeploymentTraceEventArgs)' to access type
'Microsoft.Web.Deployment.DeploymentSyncParameterEventArgs' failed.) "
I tried to get solution from internet but no luck. pls help me. I have attached the screen shot also.
You need this: http://www.iis.net/download/WebDeploy