webpart - sharepoints - sharepoint

I've created a user control and added that user control to my webpart. But when i try to add the webpart in a page. i am facing the above stated problem.I ensured that dll was present in GAC.
I've created a user control and added that user control to my class library. I've compiled and signed the dll and have added it to the gac. But when i try to add the webpart in a page i'm getting the below mentioned error.And made necessary changes in web.config file.
I've made sure that dll is there in the gac. But i'm still getting the same error.
" An error occurred during the processing of . Could not load the assembly 'Generate , Version=1.0.0.0, Culture=neutral, PublicKeyToken=e5b42758c1bfd2df'. Make sure that it is compiled before accessing the page. "
please help me.

Make sure the user control inherits
from the solution assembly in the Control tag
Load the control in the CreateChildControls method of the Web Part
Put this user control under the CONTROLTEMPLATES folder
Are you deploying is as a Feature?
To debug locally, check the following in your config file:
* customErrors=off
* Enable Stack Traces by adding CallStack=”true” to the SafeMode tag
* Set the compilation debug attribute to "true"

Related

How to override dockbar view jsp in hook?

I have created a hook to override dockbar portlet..when I copied the view.jsp from root/html/portlet/dockbar in custom_jsps under META-INF compiler showing errors even after deploying the hook.
And when I restarted liferay portal dockbar notifications are unavailable. I am getting confused as I didn't find a clear example anywhere.
According to your comments you're referring to errors that the eclipse editor shows when you add the view.jsp in question to your hook project. Unfortunately, this is expected: The JSP contains include instructions, e.g. to ../init.jsp - and that file is not available in your hook, although it will be available once you deploy it to your appserver. For this reason, Liferay IDE (the Liferay-aware plugins for eclipse) offers to disable JSP validation in your jsp-hook. Yes, it's uncomfortable, but it's what you'll have to deal with currently. AFAIK the changes to the jsp editor would be huge to cater for this situation.
As of errors in the portal once you deploy an unchanged view.jsp: Please give the exact error messages that you see - either in your browser or in the log file.
You might want to check the appserver's directory and compare the deployed dockbar/view.jsp with the original file at dockbar/view.portal.jsp - the later file will be available once you deploy your jsp hook

SharePoint 2010: Setting up a local dev environment from production data - Could not load file or assembly due to invalid PublicKeyToken

I have tried multiple ways to get the production SharePoint content to my newly installed local development environment that is running on a VM Windows Server 2008 R2. After an export of the farm and a restore failed I came across this blog post and followed these instrucitons: http://richardstk.wordpress.com/2012/02/03/build-a-sharepoint-2010-development-test-environment/. To sum up, it's basically backing up the live SQL Content database as well as the Profile, Sync and Social databases, then restoring them on the dev machine and pointing SharePoint to use these new databases instead of the old ones. Then after that I deployed the custom webparts to the development server from within Visual Studio.
I've done this and it seemed to work pretty well. I can access Central Administrator as well as setting up a SharePoint Connection within Visual Studio and being able to see all the pages, lists, documents, etc. So it is definitely pointing to the new content database. I should mention I can also connect via SharePoint Designer and access all the correct content, Master Pages, lists, etc.
The problem I am having is that I am getting a "Could not load file or assembly" error when I go to the site in a browser and it takes me to /Pages/Home.aspx. The file is a custom webpart that I have deployed from within Visual Studio. When I look within the GAC I see the assembly listed but the PublicKeyToken is different from the one that is shown in the error message.
When I dig into it a little more I see that the custom user control is registered in my Master page, and when I look at the ascx file in the _controltemplates directory where it is located there is an Assembly that looks like this:
<%# Assembly Name="BlogRoll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=529e9730fe2a198d" %>
That PublicKeyToken is correct for the live site when I look in the GAC there but when I deployed it to my local GAC it created a new PblicKeyToken. Sorry if I'm rambling but I wasn't sure what was relevant and what wasn't.
I guess my question is how to handle this? It doesn't seem smart to change all the ascx files locally to match the new PublicKeyToken's that I have in the local GAC because then when I deploy these changes to live they won't find the appropriate assembly. What is the best way to handle this?
UPDATE
The code in question has a key.snk file that is being used to strongly sign it. My understanding is that this should make it so that it gets compiled with a specific PublicKeyToken each time and therefore install in the GAC with a specific PublicKeyToken. If that is true, then I believe the only reason it would have a different key token on my dev environment versus the production is that the key.snk file that has been provided is incorrect. Is that true?
You could use WSP Builder or WinGac to forcibly deploy the assembly with the correct PublicKeyToken to your local GAC.

Visual Web Part with referenced DLL not checking GAC

I have a SharePoint project with a visual web part (WebPartA inherits from OtherWebPartC) - the web part references two DLL's, (ClassLibraryB and OtherWebPartC), and they are included in the package, set to be deployed to GAC.
When I deploy the project, the DLL's are successfully deployed to GAC, and the web part successfully shows up in the gallery in SharePoint.
However, when I try to add the visual web part (WebPartA) to a page, the page breaks - I enabled error display and stack trace - it says it can't find ClassLibraryB.dll. I used fuslogvw and procmon to determine that it was trying to load the DLL from typical locations (Virtual directory/bin, temporary asp.net folders), even though the DLL was not in these locations (but as I said, it was successfully deployed to GAC).
So I manually added ClassLibraryB.dll and OtherWebPart.dll to virtual directory/bin, and it worked successfully.
How do I get SharePoint to see the ClassLibraryB.dll and OtherWebPart.dll in the GAC? Or do I have to manually deploy the DLL to the site's Virtual Directory/bin?
Try to:
Change the WebPart/assemblies deployment target to "WebApplication" (instead of the GAC);
Retract the Solution and remove corresponding assemblies from the GAC;
Re-build and re-deploy the Solution together with the assemblies to the SharePoint Bin folder (the selected "WebApplication" deployment target).
Are all the necessary assemblies copied to the Bin folder? Does the Solution work in this case?
Just a heads up to all of you digging through these ancient questions...
I stumbled upon this issue today, so i decided to leave a comment in order to claridy things.
Most of the info can be taken from this great article by Waldek Mastykarz
Using the Project you would like to package the Controls project including the SafeControls entries.
Double click on the Package project item and the Package Designer will open.
In the Package Designer you click the Advanced button. In the Advanced view you click the Add button and choose the Add Assembly from Project Output (the options are different in VS17 but they are similar)… menu option.
From the Source Project dropdown list you choose your other Project.
Then in the Safe Controls section, you click the Click here to add a new item button to add a new Safe Controls entry.
Use the $SharePoint.Project.AssemblyFullName$ token so that you can specify that you want to include the fully qualified name of your assembly.

Custom TraceProvider implementation in webpart throws security exception

I am trying to implement some logging in my webpart. I implemented a Custom trace provider implementation which writes Log messages into the 12 hive logs as has been described here:
http://msdn.microsoft.com/en-us/library/aa979522.aspx
I have wrapped the above code into a dll called logging.DLL.
I am referencing this DLL in my webpart.
I am calling the RegisterTraceProvider in the constructor using elevated privileges.
I have declared the Logging DLL as a safe control in the manifest.xml.
But When i try to add the webpart to the page, I get a security exception with message "Request failed." THis error is thrown in the constructor when it tries to call the RegisterTraceProvider method.
Am I missing something here? How can I get this logging to work?
Edit:Both my logging DLL and my webpart DLL are in the GAC.
Since the trace provider uses unmanaged code you should mark the method with:
[SecurityPermission(SecurityAction.Assert, SecurityPermissionFlag.UnmanagedCode)]
This will make sure .NET's security stops checking further in the call stack when this attribute is reached, which allow less trusted code to do unmanaged calls thorugh it. Remember that the logging dll still need permissions to run, so either give it CAS-policies in the manifest.xml or put it in the GAC. If you put it in the GAC, mark it with the following attribute which makes it callable from a non fully trusted dll:
[assembly: AllowPartiallyTrustedCallers]
Then you should be able to call it from a WebPart deployed to the bin directory.
Is your webpart deployed in the GAC or Bin folder?
If it is in the Bin folder, the webpart is not running under Full Trust, so you need to write a Code Access Security Policy for your webpart, allowing it to run call's to the API under Full Trust.
for an example check this out or just Google for Sharepoint + Code Access Security Policies.
I was Doing m RegisterTraceprovider() call inside the constructor. Looks like this was the reason it was failing. I moved my RegisterTraceProvider() call into OnInit() override, and it started working!!

WSPBuilder and Code behind for a Sharepoint Masterpage

I created a code behind file for a custom master page in visual studio. I hooked everything up manually; safe control and custom cas policy. Everything works great!
I then wanted to put this into a sharepoint solution using WSPBuilder for better deployment. I created WSP solution, added my class file and changed the output directory to the bin folder. I then built the solution and deployed it, making sure to change the page directives on the master page to reflect the new assembly name.
Now when I go to view the sharepoint site I get an error stating Security Exception error stating
‘Exception Details: System.Security.SecurityException: That assembly does not allow partially trusted callers.’
This has me stumped as it works as a visual studio class file deployed to the bin directory of the website.
However when I put this into a sharepoint solution it breaks! I tried adding
‘[assembly: System.Security.AllowPartiallyTrustedCallers]’
to the AssemblyInfo.cs but this hasn’t helped.
Anyone else experinced this or have any advice?
EDIT: I should also mention that the code behind is trying to access a sharepoint list.
Don´t you still have to include the SafeControls entry in order for it to work, like:
<SafeControl Assembly="[FullAssembly Name]"
Namespace="[YourMasterPageNamespace]"
TypeName="*"
Safe="True" />
or in WSPBuilder config:
<add key="BuildSafeControls" value="True" />
Never seen this.. but I suspect not many people have created codebehinds to the master pages in SharePoint (Microsoft doesn't too!).
I don't know what you are trying to build but I'd probably implement it using a server control that is included on the master page.
AllowPartiallyTrustedCallers has always fixed it for my server controls.
What is the trust in your web.config file set to? Try Full.
Are you calling a third party assembly?
I ran into a situation recently that I was using a third party assembly and it did not have AllowPartiallyTrustedCallers in its code. When I tried to use the assebmly, it would fail.
Are you sure that the assembly has been deployed to bin and no to GAC by accident? If there are two assemblies the one in GAC takes precedence.
You might try checking that you are using the fully qualified five part name including the correct public key token and namespace for your assemblies.

Resources